Skip to content

Commit 5af07d3

Browse files
committed
Merge pull request #298 from havvg/1.4
fix AbstractCommandTest avoiding SplFileInfo mocks
2 parents 68793ac + 5e8668a commit 5af07d3

File tree

3 files changed

+20
-28
lines changed

3 files changed

+20
-28
lines changed

Command/AbstractCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,9 @@ protected function getFinalSchemas(KernelInterface $kernel, BundleInterface $bun
306306
}
307307

308308
/**
309-
* @param \Symfony\Component\HttpKernel\Bundle\BundleInterface
309+
* @param \Symfony\Component\HttpKernel\Bundle\BundleInterface $bundle
310+
*
311+
* @return array
310312
*/
311313
protected function getSchemasFromBundle(BundleInterface $bundle)
312314
{

Tests/Command/AbstractCommandTest.php

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
*/
2121
class AbstractCommandTest extends TestCase
2222
{
23+
/**
24+
* @var TestableAbstractCommand
25+
*/
2326
protected $command;
2427

2528
public function setUp()
@@ -40,6 +43,9 @@ public function testParseDbNameWithoutDbName()
4043

4144
public function testTransformToLogicalName()
4245
{
46+
$bundleDir = realpath(__DIR__ . '/../Fixtures/src/My/SuperBundle');
47+
$filename = 'Resources' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'a-schema.xml';
48+
4349
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface');
4450
$bundle
4551
->expects($this->once())
@@ -48,47 +54,30 @@ public function testTransformToLogicalName()
4854
$bundle
4955
->expects($this->once())
5056
->method('getPath')
51-
->will($this->returnValue('/Users/foo/project/src/My/SuperBundle'));
52-
53-
$schema = $this
54-
->getMockBuilder('\SplFileInfo')
55-
->disableOriginalConstructor()
56-
->getMock();
57-
$schema
58-
->expects($this->once())
59-
->method('getRealPath')
60-
->will($this->returnValue('/Users/foo/project/src/My/SuperBundle'
61-
. DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'my-schema.xml'));
62-
63-
$expected = '@MySuperBundle/Resources/config/my-schema.xml';
57+
->will($this->returnValue($bundleDir));
6458

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

6864
public function testTransformToLogicalNameWithSubDir()
6965
{
66+
$bundleDir = realpath(__DIR__ . '/../Fixtures/src/My/ThirdBundle');
67+
$filename = 'Resources' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'propel' . DIRECTORY_SEPARATOR . 'schema.xml';
68+
7069
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface');
7170
$bundle
7271
->expects($this->once())
7372
->method('getName')
74-
->will($this->returnValue('MySuperBundle'));
73+
->will($this->returnValue('MyThirdBundle'));
7574
$bundle
7675
->expects($this->once())
7776
->method('getPath')
78-
->will($this->returnValue('/Users/foo/project/src/My/SuperBundle'));
79-
80-
$schema = $this
81-
->getMockBuilder('\SplFileInfo')
82-
->disableOriginalConstructor()
83-
->getMock();
84-
$schema
85-
->expects($this->once())
86-
->method('getRealPath')
87-
->will($this->returnValue('/Users/foo/project/src/My/SuperBundle'
88-
. DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'propel/my-schema.xml'));
89-
90-
$expected = '@MySuperBundle/Resources/config/propel/my-schema.xml';
77+
->will($this->returnValue($bundleDir));
9178

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a schema.xml

0 commit comments

Comments
 (0)