From 5e8668a7e0a183e48151f33cedc92f2dd5112c90 Mon Sep 17 00:00:00 2001 From: Toni Uebernickel Date: Sat, 1 Nov 2014 15:44:42 +0100 Subject: [PATCH] fix AbstractCommandTest avoiding SplFileInfo mocks --- Command/AbstractCommand.php | 4 +- Tests/Command/AbstractCommandTest.php | 43 +++++++------------ .../Resources/config/propel/schema.xml | 1 + 3 files changed, 20 insertions(+), 28 deletions(-) create mode 100644 Tests/Fixtures/src/My/ThirdBundle/Resources/config/propel/schema.xml diff --git a/Command/AbstractCommand.php b/Command/AbstractCommand.php index 17153ca..b9687db 100644 --- a/Command/AbstractCommand.php +++ b/Command/AbstractCommand.php @@ -306,7 +306,9 @@ abstract class AbstractCommand extends ContainerAwareCommand } /** - * @param \Symfony\Component\HttpKernel\Bundle\BundleInterface + * @param \Symfony\Component\HttpKernel\Bundle\BundleInterface $bundle + * + * @return array */ protected function getSchemasFromBundle(BundleInterface $bundle) { diff --git a/Tests/Command/AbstractCommandTest.php b/Tests/Command/AbstractCommandTest.php index abd9c50..71f3768 100644 --- a/Tests/Command/AbstractCommandTest.php +++ b/Tests/Command/AbstractCommandTest.php @@ -20,6 +20,9 @@ use Symfony\Component\HttpKernel\KernelInterface; */ class AbstractCommandTest extends TestCase { + /** + * @var TestableAbstractCommand + */ protected $command; public function setUp() @@ -40,6 +43,9 @@ class AbstractCommandTest extends TestCase 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()) @@ -48,47 +54,30 @@ class AbstractCommandTest extends TestCase $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)); } diff --git a/Tests/Fixtures/src/My/ThirdBundle/Resources/config/propel/schema.xml b/Tests/Fixtures/src/My/ThirdBundle/Resources/config/propel/schema.xml new file mode 100644 index 0000000..7288d9c --- /dev/null +++ b/Tests/Fixtures/src/My/ThirdBundle/Resources/config/propel/schema.xml @@ -0,0 +1 @@ +This is a schema.xml