Created
October 5, 2013 12:30
-
-
Save ikhaldeev/6840356 to your computer and use it in GitHub Desktop.
Builder example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @test | |
* @dataProvider findBySearchMappingProvider | |
* | |
* @param SearchMapping $searchMapping | |
* @param array $expectedReferences | |
*/ | |
public function findBySearchMapping(SearchMapping $searchMapping, array $expectedReferences) | |
{ | |
$expectedResults = $this->getSomethingByReferences($expectedReferences); | |
$results = $this->uut->findBySearchMapping($searchMapping); | |
$this->assertCount(count($expectedResults), $results); | |
$this->assertContainsOnlyInstancesOf('SomeInterface', $results); | |
$this->assertEquals($expectedResults, $results); | |
} | |
/** | |
* @return array | |
*/ | |
public function findBySearchMappingProvider() | |
{ | |
return array( | |
// find all models | |
array( | |
(new SearchMappingBuilder())->build(), | |
array('model_1', 'model_2', 'model_3', 'model_4', 'model_5', 'model_6') | |
), | |
array( | |
(new SearchMappingBuilder())->withColor('black')->build(), | |
array('model_1') | |
), | |
//code | |
array( | |
(new SearchMappingBuilder())->withColod('black')->withSize('XL')->withWidth(1)->withHeight(23)->build(), | |
array() | |
), | |
array( | |
(new SearchMappingBuilder())->withEnabled(true)->build(), | |
array('model_1', 'model_3', 'model_4', 'model_5', 'model_6') | |
), | |
//code | |
); | |
} | |
/** | |
* @param array $references | |
* @return SomeInterface[] | |
*/ | |
private function getSomethingByReferences(array $references) | |
{ | |
$models = array(); | |
foreach ($references as $referenceName) { | |
$models[] = $this->referenceRepository->getReference($referenceName); | |
} | |
return $models; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment