-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from infinit89/feature/exclusionstrategy
Exclusion Strategy
- Loading branch information
Showing
6 changed files
with
225 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
29 changes: 29 additions & 0 deletions
29
src/Sp/FixtureDumper/ExclusionStrategy/ArrayExclusionStrategy.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Sp\FixtureDumper\ExclusionStrategy; | ||
|
||
use Doctrine\Common\Persistence\Mapping\ClassMetadata; | ||
use Sp\FixtureDumper\Util\ClassUtils; | ||
|
||
/** | ||
* @author Miguel González <infinit89@gmail.com> | ||
*/ | ||
class ArrayExclusionStrategy implements ExclusionStrategyInterface | ||
{ | ||
/** @var array */ | ||
private $skipClassesNames; | ||
|
||
public function __construct(array $skipClassesNames) | ||
{ | ||
$this->skipClassesNames = $skipClassesNames; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function shouldSkipClass(ClassMetadata $metadata) | ||
{ | ||
return in_array(ClassUtils::getClassName($metadata->getName()), $this->skipClassesNames) || | ||
in_array($metadata->getName(), $this->skipClassesNames); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/Sp/FixtureDumper/ExclusionStrategy/ExclusionStrategyInterface.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Sp\FixtureDumper\ExclusionStrategy; | ||
|
||
use Doctrine\Common\Persistence\Mapping\ClassMetadata; | ||
|
||
/** | ||
* Interface ExclusionStrategyInterface | ||
* | ||
* @package Sp\FixtureDumper\ExclusionStrategy | ||
* @author Miguel González <infinit89@gmail.com> | ||
*/ | ||
interface ExclusionStrategyInterface | ||
{ | ||
|
||
/** | ||
* Indicates if this class should be skipped and do not generate fixtures for this class | ||
* | ||
* @param ClassMetadata $metadata | ||
* | ||
* @return boolean true if this class should be skipped | ||
*/ | ||
public function shouldSkipClass(ClassMetadata $metadata); | ||
} |
34 changes: 34 additions & 0 deletions
34
tests/Sp/FixtureDumper/Tests/ExclusionStrategy/ArrayExclusionStrategyTest.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Sp\FixtureDumper\Tests\ExclusionStrategy; | ||
|
||
use Sp\FixtureDumper\ExclusionStrategy\ArrayExclusionStrategy; | ||
|
||
/** | ||
* @author Miguel González <infinit89@gmail.com> | ||
*/ | ||
class ArrayExclusionStrategyTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @dataProvider dataProviderArrayExclusionStrategy | ||
*/ | ||
public function testShouldSkipClassName($excludedClasses, $classMetadata, $shouldSkip) | ||
{ | ||
$exclusionStrategy = new ArrayExclusionStrategy($excludedClasses); | ||
|
||
$this->assertEquals($exclusionStrategy->shouldSkipClass($classMetadata), $shouldSkip); | ||
} | ||
|
||
public function dataProviderArrayExclusionStrategy() | ||
{ | ||
$postClass = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata'); | ||
$postClass->expects($this->any())->method('getName')->will($this->returnValue('Acme\Demo\Entity\Post')); | ||
|
||
return array( | ||
array(array('Post'), $postClass, true), | ||
array(array('Acme\Demo\Entity\Post'), $postClass, true), | ||
array(array('Acme\Demo\Entity\PostBlog'), $postClass, false), | ||
array(array('', 'aPost', 'Posti'), $postClass, false), | ||
); | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
tests/Sp/FixtureDumper/Tests/ExclusionStrategy/ExclusionStrategyTest.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
namespace Sp\FixtureDumper\Tests\ExclusionStrategy; | ||
|
||
use PhpCollection\Map; | ||
|
||
/** | ||
* @author Miguel González <infinit89@gmail.com> | ||
*/ | ||
class ExclusionStrategyTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $handlerRegistry; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $manager; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $generator; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $metadata; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $dumper; | ||
|
||
protected function setUp() | ||
{ | ||
$this->metadata = array( | ||
$this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata'), | ||
$this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata'), | ||
); | ||
$this->manager = $this->getMock('Doctrine\Common\Persistence\ObjectManager'); | ||
$this->generator = $this | ||
->getMockBuilder('Sp\FixtureDumper\Generator\AbstractGenerator') | ||
->disableOriginalConstructor() | ||
->setMethods(array('generate', 'setNavigator')) | ||
->getMockForAbstractClass(); | ||
$this->handlerRegistry = $this->getMock('Sp\FixtureDumper\Converter\Handler\HandlerRegistryInterface'); | ||
$this->dumper = $this | ||
->getMockForAbstractClass( | ||
'Sp\FixtureDumper\AbstractDumper', | ||
array( | ||
$this->manager, | ||
$this->handlerRegistry, | ||
new Map(array('php' => $this->generator)), | ||
), | ||
'', | ||
true, | ||
true, | ||
true, | ||
array('writeFixture', 'getAllMetadata', 'getDumpOrder', 'getExclusionStrategy') | ||
); | ||
|
||
$this->dumper->expects($this->once())->method('getAllMetadata')->will($this->returnValue($this->metadata)); | ||
$this->dumper->expects($this->once())->method('getDumpOrder')->will($this->returnValue($this->metadata)); | ||
} | ||
|
||
public function testCollaborationExclusionStrategy() | ||
{ | ||
$this->exclusionStrategy = $this | ||
->getMock('Sp\FixtureDumper\ExclusionStrategy\ExclusionStrategyInterface'); | ||
|
||
$this->dumper->setExclusionStrategy($this->exclusionStrategy); | ||
|
||
$this->dumper | ||
->expects($this->once()) | ||
->method('getExclusionStrategy') | ||
->will($this->returnValue($this->exclusionStrategy)); | ||
|
||
$this->exclusionStrategy | ||
->expects($this->exactly(2)) | ||
->method('shouldSkipClass'); | ||
|
||
$this->dumper->dump('/foo', 'php'); | ||
} | ||
} |