Skip to content

Commit

Permalink
Fix tests and CS
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Jul 2, 2020
1 parent 114ad3b commit 8cbb1d9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Bundle/Config/ModuleConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(string $name)
*/
public function getBundleInstance(KernelInterface $kernel)
{
$dir = \method_exists($kernel, 'getRootDir') ? $kernel->getRootDir() : $kernel->getProjectDir();
$dir = method_exists($kernel, 'getRootDir') ? $kernel->getRootDir() : $kernel->getProjectDir();

return new ContaoModuleBundle($this->name, $dir);
}
Expand Down
25 changes: 14 additions & 11 deletions tests/Bundle/Config/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Contao\ManagerPlugin\Bundle\Config\BundleConfig;
use Contao\ManagerPlugin\Bundle\Config\ConfigInterface;
use Contao\ManagerPlugin\Bundle\Config\ModuleConfig;
use PHPUnit\Framework\MockObject\Generator;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpKernel\KernelInterface;
Expand Down Expand Up @@ -103,7 +102,7 @@ public function testReturnsTheBundleInstances(): void
$this->assertInstanceOf(ContaoCoreBundle::class, $bundle);
}

public function testReturnsTheBundlePath(): void
public function testReturnsTheBundlePathWithProjectDir(): void
{
$kernel = $this->mockKernel(__DIR__.'/../../Fixtures/Bundle/Config');

Expand All @@ -114,6 +113,17 @@ public function testReturnsTheBundlePath(): void
$this->assertSame(__DIR__.'/../../Fixtures/Bundle/Config/system/modules/foobar', $bundle->getPath());
}

public function testReturnsTheBundlePathWithRootDir(): void
{
$kernel = $this->mockKernel(__DIR__.'/../../Fixtures/Bundle/Config/app');

$config = ModuleConfig::create('foobar');
$bundle = $config->getBundleInstance($kernel);

$this->assertInstanceOf(ContaoModuleBundle::class, $bundle);
$this->assertSame(__DIR__.'/../../Fixtures/Bundle/Config/system/modules/foobar', $bundle->getPath());
}

public function testFailsToReturnTheBundleInstanceIfTheNameIsInvalid(): void
{
$kernel = $this->mockKernel(__DIR__.'/../../Fixtures/Bundle/Config');
Expand Down Expand Up @@ -149,17 +159,10 @@ public function testLoadsTheModuleConfigurationAfterTheLegacyModules(): void
*/
private function mockKernel(string $projectDir): KernelInterface
{
$generator = new Generator();
$methods = $generator->getClassMethods(KernelInterface::class);
$methods[] = 'getProjectDir';

$kernel = $this->getMockBuilder(KernelInterface::class)
->setMethods($methods)
->getMock()
;
$kernel = $this->createMock(KernelInterface::class);

$kernel
->method('getProjectDir')
->method(method_exists($kernel, 'getRootDir') ? 'getRootDir' : 'getProjectDir')
->willReturn($projectDir)
;

Expand Down

0 comments on commit 8cbb1d9

Please sign in to comment.