From 8cbb1d9e9daaee01b3b2d97a6efa8bf1bea16172 Mon Sep 17 00:00:00 2001 From: Andreas Schempp Date: Thu, 2 Jul 2020 17:22:10 +0200 Subject: [PATCH] Fix tests and CS --- src/Bundle/Config/ModuleConfig.php | 2 +- tests/Bundle/Config/ConfigTest.php | 25 ++++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/Bundle/Config/ModuleConfig.php b/src/Bundle/Config/ModuleConfig.php index b8ed0fd..a2784fc 100644 --- a/src/Bundle/Config/ModuleConfig.php +++ b/src/Bundle/Config/ModuleConfig.php @@ -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); } diff --git a/tests/Bundle/Config/ConfigTest.php b/tests/Bundle/Config/ConfigTest.php index aaf4196..68664c0 100644 --- a/tests/Bundle/Config/ConfigTest.php +++ b/tests/Bundle/Config/ConfigTest.php @@ -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; @@ -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'); @@ -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'); @@ -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) ;