Skip to content

Instantly share code, notes, and snippets.

@ikhaldeev
Created October 5, 2013 12:30
Show Gist options
  • Save ikhaldeev/6840356 to your computer and use it in GitHub Desktop.
Save ikhaldeev/6840356 to your computer and use it in GitHub Desktop.
Builder example
<?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