Skip to content

dirkwinkhaus/widi-filter-specification

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Widi\Filter\Specification

Code Sample From Test

    $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);

About

Specification pattern for filtering objects in php.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages