From b4f36c89ceabc514cf526f93862bbc2c15a80901 Mon Sep 17 00:00:00 2001 From: Kamil Kokot Date: Tue, 19 Feb 2019 15:58:50 +0100 Subject: [PATCH] Clean up PHPUnit tests a bit --- .gitignore | 2 - composer.json | 13 +--- phpunit.xml.dist | 3 +- test/app/AppKernel.php | 60 ------------------- test/app/config/config.yml | 32 ---------- test/app/config/parameters.yml | 6 -- test/app/console | 24 -------- tests/Application/.gitignore | 3 + tests/Application/Kernel.php | 40 +++++++++++++ {test => tests/Application}/composer.json | 0 tests/Application/config/config.yml | 13 ++++ tests/Application/var/.gitignore | 0 .../SyliusFixturesExtensionTest.php | 7 ++- .../Smoke}/SyliusFixturesBundleTest.php | 9 +-- 14 files changed, 69 insertions(+), 143 deletions(-) delete mode 100644 test/app/AppKernel.php delete mode 100644 test/app/config/config.yml delete mode 100644 test/app/config/parameters.yml delete mode 100755 test/app/console create mode 100644 tests/Application/.gitignore create mode 100644 tests/Application/Kernel.php rename {test => tests/Application}/composer.json (100%) create mode 100644 tests/Application/config/config.yml create mode 100644 tests/Application/var/.gitignore rename {test/src/Tests => tests/Smoke}/SyliusFixturesBundleTest.php (71%) diff --git a/.gitignore b/.gitignore index 7b3b775..3e1a2c1 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,5 @@ /composer.phar /composer.lock -/test/var - /phpspec.yml /phpunit.xml diff --git a/composer.json b/composer.json index ced5cec..7c7ef97 100644 --- a/composer.json +++ b/composer.json @@ -35,15 +35,7 @@ "matthiasnoback/symfony-config-test": "^4.0", "matthiasnoback/symfony-dependency-injection-test": "^3.0", "phpspec/phpspec": "^5.0", - "phpunit/phpunit": "^7.0", - "twig/twig": "^2.0", - "symfony/browser-kit": "^3.4|^4.1.1", - "symfony/dependency-injection": "^3.4|^4.1.1", - "symfony/templating": "^3.4|^4.1.1", - "symfony/translation": "^3.4|^4.1.1", - "symfony/twig-bundle": "^3.4|^4.1.1", - "symfony/security-csrf": "^3.4|^4.1.1", - "polishsymfonycommunity/symfony-mocker-container": "^1.0" + "phpunit/phpunit": "^7.0" }, "autoload": { "psr-4": { "Sylius\\Bundle\\FixturesBundle\\": "src/" } @@ -52,8 +44,7 @@ "psr-4": { "Sylius\\Bundle\\FixturesBundle\\spec\\": "spec/", "Sylius\\Bundle\\FixturesBundle\\Tests\\": "tests/" - }, - "classmap": ["test/app/AppKernel.php"] + } }, "extra": { "branch-alias": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 80f735f..f4bce2d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -5,12 +5,11 @@ colors="true" > - + - ./test/ ./Tests/ diff --git a/test/app/AppKernel.php b/test/app/AppKernel.php deleted file mode 100644 index 991739d..0000000 --- a/test/app/AppKernel.php +++ /dev/null @@ -1,60 +0,0 @@ -load(__DIR__ . '/config/config.yml'); - } - - /** - * {@inheritdoc} - */ - protected function getContainerBaseClass() - { - if (0 === strpos($this->environment, 'test')) { - return MockerContainer::class; - } - - return parent::getContainerBaseClass(); - } -} diff --git a/test/app/config/config.yml b/test/app/config/config.yml deleted file mode 100644 index 9f2831b..0000000 --- a/test/app/config/config.yml +++ /dev/null @@ -1,32 +0,0 @@ -imports: - - { resource: "parameters.yml" } - -framework: - assets: false - translator: { fallbacks: ["%locale%"] } - secret: "%secret%" - router: - resource: "%kernel.project_dir%/app/config/routing.yml" - csrf_protection: true - templating: - engines: ['twig'] - default_locale: "%locale%" - session: - handler_id: ~ - storage_id: session.storage.mock_file - http_method_override: true - test: ~ - -twig: - debug: "%kernel.debug%" - strict_variables: "%kernel.debug%" - -doctrine: - dbal: - driver: "%database_driver%" - path: "%database_path%" - charset: UTF8 - orm: - entity_managers: - default: - auto_mapping: true diff --git a/test/app/config/parameters.yml b/test/app/config/parameters.yml deleted file mode 100644 index 5532124..0000000 --- a/test/app/config/parameters.yml +++ /dev/null @@ -1,6 +0,0 @@ -parameters: - database_driver: pdo_sqlite - database_path: "%kernel.project_dir%/app/db.sql" - - locale: en_US - secret: "Three can keep a secret, if two of them are dead." diff --git a/test/app/console b/test/app/console deleted file mode 100755 index 296012b..0000000 --- a/test/app/console +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env php -run($input); diff --git a/tests/Application/.gitignore b/tests/Application/.gitignore new file mode 100644 index 0000000..8f4ed86 --- /dev/null +++ b/tests/Application/.gitignore @@ -0,0 +1,3 @@ +/var/cache +/var/log +/var/db.sql diff --git a/tests/Application/Kernel.php b/tests/Application/Kernel.php new file mode 100644 index 0000000..b40fdd3 --- /dev/null +++ b/tests/Application/Kernel.php @@ -0,0 +1,40 @@ +load(__DIR__ . '/config/config.yml'); + } +} diff --git a/test/composer.json b/tests/Application/composer.json similarity index 100% rename from test/composer.json rename to tests/Application/composer.json diff --git a/tests/Application/config/config.yml b/tests/Application/config/config.yml new file mode 100644 index 0000000..cfdd801 --- /dev/null +++ b/tests/Application/config/config.yml @@ -0,0 +1,13 @@ +framework: + secret: "Three can keep a secret, if two of them are dead." + test: ~ + +doctrine: + dbal: + driver: "pdo_sqlite" + path: "%kernel.project_dir%/var/db.sql" + charset: UTF8 + orm: + entity_managers: + default: + auto_mapping: true diff --git a/tests/Application/var/.gitignore b/tests/Application/var/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/tests/DependencyInjection/SyliusFixturesExtensionTest.php b/tests/DependencyInjection/SyliusFixturesExtensionTest.php index 0e18d8d..c5f33c3 100644 --- a/tests/DependencyInjection/SyliusFixturesExtensionTest.php +++ b/tests/DependencyInjection/SyliusFixturesExtensionTest.php @@ -14,6 +14,7 @@ namespace Sylius\Bundle\FixturesBundle\Tests\DependencyInjection; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; +use PHPUnit\Framework\Assert; use Sylius\Bundle\FixturesBundle\DependencyInjection\SyliusFixturesExtension; final class SyliusFixturesExtensionTest extends AbstractExtensionTestCase @@ -23,6 +24,8 @@ final class SyliusFixturesExtensionTest extends AbstractExtensionTestCase */ public function it_does_not_crash_if_no_suite_is_configured(): void { + $this->expectNotToPerformAssertions(); + $this->load(); } @@ -38,8 +41,8 @@ public function it_registers_configured_suites(): void $suiteRegistryDefinition = $this->container->findDefinition('sylius_fixtures.suite_registry'); $suiteMethodCall = $suiteRegistryDefinition->getMethodCalls()[0]; - static::assertSame('addSuite', $suiteMethodCall[0]); - static::assertSame('suite_name', $suiteMethodCall[1][0]); + Assert::assertSame('addSuite', $suiteMethodCall[0]); + Assert::assertSame('suite_name', $suiteMethodCall[1][0]); } /** diff --git a/test/src/Tests/SyliusFixturesBundleTest.php b/tests/Smoke/SyliusFixturesBundleTest.php similarity index 71% rename from test/src/Tests/SyliusFixturesBundleTest.php rename to tests/Smoke/SyliusFixturesBundleTest.php index 9a68fdc..6168f59 100644 --- a/test/src/Tests/SyliusFixturesBundleTest.php +++ b/tests/Smoke/SyliusFixturesBundleTest.php @@ -11,14 +11,15 @@ declare(strict_types=1); -namespace Sylius\Bundle\FixturesBundle\Tests; +namespace Sylius\Bundle\FixturesBundle\Tests\Smoke; use PHPUnit\Framework\Assert; +use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; -final class SyliusFixturesBundleTest extends WebTestCase +final class SyliusFixturesBundleTest extends KernelTestCase { /** * @test @@ -26,12 +27,12 @@ final class SyliusFixturesBundleTest extends WebTestCase public function its_services_are_initializable(): void { /** @var ContainerBuilder $container */ - $container = self::createClient()->getContainer(); + $container = self::bootKernel()->getContainer(); $services = $container->getServiceIds(); $services = array_filter($services, function (string $serviceId): bool { - return 0 === strpos($serviceId, 'sylius.'); + return 0 === strpos($serviceId, 'sylius_fixtures.') || 0 === strpos($serviceId, 'Sylius\\Bundle\\FixturesBundle\\'); }); foreach ($services as $id) {