Skip to content

Commit

Permalink
Merge pull request #298 from havvg/1.4
Browse files Browse the repository at this point in the history
fix AbstractCommandTest avoiding SplFileInfo mocks
  • Loading branch information
havvg committed Nov 1, 2014
2 parents 68793ac + 5e8668a commit 5af07d3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
4 changes: 3 additions & 1 deletion Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ protected function getFinalSchemas(KernelInterface $kernel, BundleInterface $bun
}

/**
* @param \Symfony\Component\HttpKernel\Bundle\BundleInterface
* @param \Symfony\Component\HttpKernel\Bundle\BundleInterface $bundle
*
* @return array
*/
protected function getSchemasFromBundle(BundleInterface $bundle)
{
Expand Down
43 changes: 16 additions & 27 deletions Tests/Command/AbstractCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
*/
class AbstractCommandTest extends TestCase
{
/**
* @var TestableAbstractCommand
*/
protected $command;

public function setUp()
Expand All @@ -40,6 +43,9 @@ public function testParseDbNameWithoutDbName()

public function testTransformToLogicalName()
{
$bundleDir = realpath(__DIR__ . '/../Fixtures/src/My/SuperBundle');
$filename = 'Resources' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'a-schema.xml';

$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface');
$bundle
->expects($this->once())
Expand All @@ -48,47 +54,30 @@ public function testTransformToLogicalName()
$bundle
->expects($this->once())
->method('getPath')
->will($this->returnValue('/Users/foo/project/src/My/SuperBundle'));

$schema = $this
->getMockBuilder('\SplFileInfo')
->disableOriginalConstructor()
->getMock();
$schema
->expects($this->once())
->method('getRealPath')
->will($this->returnValue('/Users/foo/project/src/My/SuperBundle'
. DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'my-schema.xml'));

$expected = '@MySuperBundle/Resources/config/my-schema.xml';
->will($this->returnValue($bundleDir));

$schema = new \SplFileInfo($bundleDir . DIRECTORY_SEPARATOR . $filename);
$expected = '@MySuperBundle/Resources/config/a-schema.xml';
$this->assertEquals($expected, $this->command->transformToLogicalName($schema, $bundle));
}

public function testTransformToLogicalNameWithSubDir()
{
$bundleDir = realpath(__DIR__ . '/../Fixtures/src/My/ThirdBundle');
$filename = 'Resources' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'propel' . DIRECTORY_SEPARATOR . 'schema.xml';

$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface');
$bundle
->expects($this->once())
->method('getName')
->will($this->returnValue('MySuperBundle'));
->will($this->returnValue('MyThirdBundle'));
$bundle
->expects($this->once())
->method('getPath')
->will($this->returnValue('/Users/foo/project/src/My/SuperBundle'));

$schema = $this
->getMockBuilder('\SplFileInfo')
->disableOriginalConstructor()
->getMock();
$schema
->expects($this->once())
->method('getRealPath')
->will($this->returnValue('/Users/foo/project/src/My/SuperBundle'
. DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'propel/my-schema.xml'));

$expected = '@MySuperBundle/Resources/config/propel/my-schema.xml';
->will($this->returnValue($bundleDir));

$schema = new \SplFileInfo($bundleDir . DIRECTORY_SEPARATOR . $filename);
$expected = '@MyThirdBundle/Resources/config/propel/schema.xml';
$this->assertEquals($expected, $this->command->transformToLogicalName($schema, $bundle));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a schema.xml

0 comments on commit 5af07d3

Please sign in to comment.