From 03fc42e8fc19a0fa00840145603bbc2aae3c0010 Mon Sep 17 00:00:00 2001 From: Magdalena Banasiak Date: Fri, 25 Nov 2016 11:25:07 +0100 Subject: [PATCH] [MoneyBundle] Services initialization test --- .gitignore | 3 ++ composer.json | 15 +++++- phpunit.xml.dist | 18 ++++++++ test/app/AppKernel.php | 59 ++++++++++++++++++++++++ test/app/autoload.php | 20 ++++++++ test/app/config/config.yml | 43 +++++++++++++++++ test/app/config/parameters.yml | 6 +++ test/app/console | 24 ++++++++++ test/src/Tests/SyliusMoneyBundleTest.php | 40 ++++++++++++++++ 9 files changed, 226 insertions(+), 2 deletions(-) create mode 100644 phpunit.xml.dist create mode 100644 test/app/AppKernel.php create mode 100644 test/app/autoload.php create mode 100644 test/app/config/config.yml create mode 100644 test/app/config/parameters.yml create mode 100755 test/app/console create mode 100644 test/src/Tests/SyliusMoneyBundleTest.php diff --git a/.gitignore b/.gitignore index 46aed3371099..a24566fdcca6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ bin/ composer.phar composer.lock + +test/app/cache +test/app/logs diff --git a/composer.json b/composer.json index cd63e617141a..23421c18443c 100644 --- a/composer.json +++ b/composer.json @@ -29,10 +29,15 @@ "webmozart/assert": "^1.0" }, "require-dev": { + "doctrine/orm": "^2.5", "phpspec/phpspec": "^3.2", + "phpunit/phpunit": "^5.6", + "twig/twig": "^1.0", "sylius/currency-bundle": "^1.0", "symfony/form": "^3.2@rc", - "twig/twig": "^1.0" + "symfony/browser-kit": "^3.2@rc", + "incenteev/composer-parameter-handler": "~2.0", + "polishsymfonycommunity/symfony-mocker-container": "^1.0" }, "config": { "bin-dir": "bin" @@ -41,7 +46,10 @@ "psr-4": { "Sylius\\Bundle\\MoneyBundle\\": "" } }, "autoload-dev": { - "psr-4": { "Sylius\\Bundle\\MoneyBundle\\spec\\": "spec/" } + "psr-4": { + "Sylius\\Bundle\\MoneyBundle\\spec\\": "spec/", + "AppBundle\\": "test/src/AppBundle/" + } }, "minimum-stability": "dev", "prefer-stable": true, @@ -54,6 +62,9 @@ "extra": { "branch-alias": { "dev-master": "1.0-dev" + }, + "incenteev-parameters": { + "file": "test/app/config/parameters.yml" } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 000000000000..79efbfc82a79 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,18 @@ + + + + + + + + + + ./test/ + + + diff --git a/test/app/AppKernel.php b/test/app/AppKernel.php new file mode 100644 index 000000000000..59762aa85fa3 --- /dev/null +++ b/test/app/AppKernel.php @@ -0,0 +1,59 @@ + + */ +class AppKernel extends Kernel +{ + /** + * {@inheritdoc} + */ + public function registerBundles() + { + return [ + new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), + new winzou\Bundle\StateMachineBundle\winzouStateMachineBundle(), + new FOS\RestBundle\FOSRestBundle(), + new JMS\SerializerBundle\JMSSerializerBundle($this), + new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(), + new WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(), + new Sylius\Bundle\MoneyBundle\SyliusMoneyBundle(), + new Sylius\Bundle\ResourceBundle\SyliusResourceBundle(), + new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), + new Symfony\Bundle\TwigBundle\TwigBundle(), + ]; + } + + /** + * {@inheritdoc} + */ + public function registerContainerConfiguration(LoaderInterface $loader) + { + $loader->load(__DIR__.'/config/config.yml'); + } + + /** + * {@inheritdoc} + */ + protected function getContainerBaseClass() + { + if ('test' === $this->environment) { + return MockerContainer::class; + } + + return parent::getContainerBaseClass(); + } +} diff --git a/test/app/autoload.php b/test/app/autoload.php new file mode 100644 index 000000000000..7c2884c9da5b --- /dev/null +++ b/test/app/autoload.php @@ -0,0 +1,20 @@ +run($input); diff --git a/test/src/Tests/SyliusMoneyBundleTest.php b/test/src/Tests/SyliusMoneyBundleTest.php new file mode 100644 index 000000000000..67bbeccadc74 --- /dev/null +++ b/test/src/Tests/SyliusMoneyBundleTest.php @@ -0,0 +1,40 @@ + + */ +class SyliusMoneyBundleTest extends WebTestCase +{ + /** + * @test + */ + public function its_services_are_intitializable() + { + /** @var ContainerInterface $container */ + $container = self::createClient()->getContainer(); + + $services = $container->getServiceIds(); + + $services = array_filter($services, function ($serviceId) { + return false !== strpos($serviceId, 'sylius'); + }); + + foreach ($services as $id) { + $container->get($id); + } + } +}