widi/filter-specification

用于在PHP中过滤对象的规范模式。

4.0.1 2022-05-02 08:30 UTC

This package is auto-updated.

Last update: 2024-09-27 15:43:35 UTC


README文件

测试用例中的代码示例

    $candidate = $this->prophesize(MyCandidateInterface::class);
    $candidate->getValue()->willReturn($value);

    $builderFactory = new BuilderFactory();

    $specificationBuilder = $builderFactory->create();
    $firstSpecification   =
        $specificationBuilder
            ->and(new CandidateIsHigherThanFiveCompositeSpecification())
            ->and(new CandidateIsLowerThanTwentyCompositeSpecification())
            ->or(new CandidateIsDivisableByFive())
            ->build();

    $secondSpecification =
        $specificationBuilder
            ->and(new CandidateIsHigherThanOneHundredCompositeSpecification())
            ->and(new CandidateIsLowerThanTwoHundredCompositeSpecification())
            ->build();

    $compositeSpecification =
        $specificationBuilder
            ->or($firstSpecification)
            ->or($secondSpecification)
            ->build();

    $result = $compositeSpecification->meetsSpecification($candidate->reveal());

    $this->assertEquals($expectedResult, $result, 'Value failed: ' . $value);