widi / filter-specification
用于在PHP中过滤对象的规范模式。
4.0.1
2022-05-02 08:30 UTC
Requires
- php: >=7.4 <=8.2
- phpunit/phpunit: ^9.5
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);