-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #265 Toggle doctrine migration (arti0090)
This PR was merged into the 1.0-dev branch. Discussion ---------- Commits ------- 27fdd51 Toggle doctrine migration 9e24170 add missed bundle namespace 2410b48 Delete .phpunit.result.cache
- Loading branch information
Showing
4 changed files
with
145 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
tests/DependencyInjection/SyliusRefundExtensionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Sylius\RefundPlugin\DependencyInjection; | ||
|
||
use Doctrine\Bundle\MigrationsBundle\DependencyInjection\DoctrineMigrationsExtension; | ||
use FOS\OAuthServerBundle\DependencyInjection\FOSOAuthServerExtension; | ||
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; | ||
use Sylius\RefundPlugin\DependencyInjection\SyliusRefundExtension; | ||
use SyliusLabs\DoctrineMigrationsExtraBundle\DependencyInjection\SyliusLabsDoctrineMigrationsExtraExtension; | ||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; | ||
|
||
final class SyliusRefundExtensionTest extends AbstractExtensionTestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function it_autoconfigures_prepending_doctrine_migration_with_proper_migrations_paths(): void | ||
{ | ||
$this->configureContainer(); | ||
|
||
$this->customLoad(); | ||
|
||
$doctrineMigrationsExtensionConfig = $this->container->getExtensionConfig('doctrine_migrations'); | ||
|
||
self::assertTrue(isset( | ||
$doctrineMigrationsExtensionConfig[0]['migrations_paths']['Sylius\RefundPlugin\Migrations'] | ||
)); | ||
self::assertSame( | ||
'@SyliusRefundPlugin/Migrations', | ||
$doctrineMigrationsExtensionConfig[0]['migrations_paths']['Sylius\RefundPlugin\Migrations'] | ||
); | ||
|
||
$syliusLabsDoctrineMigrationsExtraExtensionConfig = $this | ||
->container | ||
->getExtensionConfig('sylius_labs_doctrine_migrations_extra') | ||
; | ||
|
||
self::assertTrue(isset( | ||
$syliusLabsDoctrineMigrationsExtraExtensionConfig[0]['migrations']['Sylius\RefundPlugin\Migrations'] | ||
)); | ||
self::assertSame( | ||
'Sylius\Bundle\CoreBundle\Migrations', | ||
$syliusLabsDoctrineMigrationsExtraExtensionConfig[0]['migrations']['Sylius\RefundPlugin\Migrations'][0] | ||
); | ||
self::assertSame( | ||
'Sylius\Bundle\AdminApiBundle\Migrations', | ||
$syliusLabsDoctrineMigrationsExtraExtensionConfig[0]['migrations']['Sylius\RefundPlugin\Migrations'][1] | ||
); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_does_not_autoconfigure_prepending_doctrine_migrations_if_it_is_disabled(): void | ||
{ | ||
$this->configureContainer(); | ||
|
||
$this->container->setParameter('sylius_core.prepend_doctrine_migrations', false); | ||
|
||
$this->customLoad(); | ||
|
||
$doctrineMigrationsExtensionConfig = $this->container->getExtensionConfig('doctrine_migrations'); | ||
|
||
self::assertEmpty($doctrineMigrationsExtensionConfig); | ||
|
||
$syliusLabsDoctrineMigrationsExtraExtensionConfig = $this | ||
->container | ||
->getExtensionConfig('sylius_labs_doctrine_migrations_extra') | ||
; | ||
|
||
self::assertEmpty($syliusLabsDoctrineMigrationsExtraExtensionConfig); | ||
} | ||
|
||
protected function getContainerExtensions(): array | ||
{ | ||
return [new SyliusRefundExtension()]; | ||
} | ||
|
||
private function configureContainer(): void | ||
{ | ||
$this->container->setParameter('kernel.environment', 'test'); | ||
$this->container->setParameter('kernel.debug', true); | ||
|
||
$this->container->registerExtension(new DoctrineMigrationsExtension()); | ||
$this->container->registerExtension(new SyliusLabsDoctrineMigrationsExtraExtension()); | ||
$this->container->registerExtension(new FOSOAuthServerExtension()); | ||
} | ||
|
||
private function customLoad(): void | ||
{ | ||
$configurationValues = ['sylius_refund' => []]; | ||
|
||
$configs = [$this->getMinimalConfiguration(), $configurationValues]; | ||
|
||
foreach ($this->container->getExtensions() as $extension) { | ||
if ($extension instanceof PrependExtensionInterface) { | ||
$extension->prepend($this->container); | ||
} | ||
} | ||
|
||
foreach ($this->container->getExtensions() as $extension) { | ||
$extensionAlias = $extension->getAlias(); | ||
if (isset($configs[$extensionAlias])) { | ||
$extension->load($configs[$extensionAlias], $this->container); | ||
} | ||
} | ||
} | ||
} |