diff --git a/.travis.yml b/.travis.yml index 517928a5..e003ff4b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,10 +18,14 @@ matrix: - php: 7.2 - php: 7.3 env: deps=low + - php: 7.4 + env: SYMFONY_PHPUNIT_VERSION=9.4 + - php: nightly + env: SYMFONY_PHPUNIT_VERSION=9.4 before_install: - phpenv config-rm xdebug.ini || true - - composer global require --no-progress --no-scripts --no-plugins symfony/flex dev-master + - composer global require --no-progress --no-scripts --no-plugins symfony/flex dev-main install: - | diff --git a/composer.json b/composer.json index f7f5d3e4..e6fab536 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ }, "minimum-stability": "dev", "require": { - "php": "^7.1.3", + "php": ">=7.1.3", "symfony/asset": "^3.4 || ^4.0 || ^5.0", "symfony/config": "^3.4 || ^4.0 || ^5.0", "symfony/dependency-injection": "^3.4 || ^4.0 || ^5.0", diff --git a/tests/Asset/TagRendererTest.php b/tests/Asset/TagRendererTest.php index 25131807..9279c4ee 100644 --- a/tests/Asset/TagRendererTest.php +++ b/tests/Asset/TagRendererTest.php @@ -13,8 +13,8 @@ use Symfony\Component\Asset\Packages; use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupCollection; use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupInterface; -use Symfony\WebpackEncoreBundle\Asset\IntegrityDataProviderInterface; use Symfony\WebpackEncoreBundle\Asset\TagRenderer; +use Symfony\WebpackEncoreBundle\Tests\TestEntrypointLookupIntegrityDataProviderInterface; class TagRendererTest extends TestCase { @@ -138,10 +138,7 @@ public function testRenderScriptTagsWithinAnEntryPointCollection() public function testRenderScriptTagsWithHashes() { - $entrypointLookup = $this->createMock([ - EntrypointLookupInterface::class, - IntegrityDataProviderInterface::class, - ]); + $entrypointLookup = $this->createMock(TestEntrypointLookupIntegrityDataProviderInterface::class); $entrypointLookup->expects($this->once()) ->method('getJavaScriptFiles') ->willReturn(['/build/file1.js', '/build/file2.js']); diff --git a/tests/EventListener/ExceptionListenerTest.php b/tests/EventListener/ExceptionListenerTest.php index 7e0df5a0..b23a2910 100644 --- a/tests/EventListener/ExceptionListenerTest.php +++ b/tests/EventListener/ExceptionListenerTest.php @@ -10,6 +10,7 @@ namespace Symfony\WebpackEncoreBundle\Tests\EventListener; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; use PHPUnit\Framework\TestCase; @@ -39,7 +40,10 @@ public function testItResetsAllEntrypointLookups() $request = new Request(); $exception = new \Exception(); - $event = new GetResponseForExceptionEvent( + $exceptionEventClass = class_exists(ExceptionEvent::class) + ? ExceptionEvent::class + : GetResponseForExceptionEvent::class; + $event = new $exceptionEventClass( $this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST, diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index 4a28959f..2cf8da5d 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -36,9 +36,9 @@ public function testTwigIntegration() { $kernel = new WebpackEncoreIntegrationTestKernel(true); $kernel->boot(); - $container = $kernel->getContainer(); + $twig = $this->getTwigEnvironmentFromBootedKernel($kernel); - $html1 = $container->get('twig')->render('@integration_test/template.twig'); + $html1 = $twig->render('@integration_test/template.twig'); $this->assertStringContainsString( '', $html1 @@ -58,7 +58,7 @@ public function testTwigIntegration() $html1 ); - $html2 = $container->get('twig')->render('@integration_test/manual_template.twig'); + $html2 = $twig->render('@integration_test/manual_template.twig'); $this->assertStringContainsString( '', $html2 @@ -73,10 +73,10 @@ public function testEntriesAreNotRepeatedWhenAlreadyOutputIntegration() { $kernel = new WebpackEncoreIntegrationTestKernel(true); $kernel->boot(); - $container = $kernel->getContainer(); + $twig = $this->getTwigEnvironmentFromBootedKernel($kernel); - $html1 = $container->get('twig')->render('@integration_test/template.twig'); - $html2 = $container->get('twig')->render('@integration_test/manual_template.twig'); + $html1 = $twig->render('@integration_test/template.twig'); + $html2 = $twig->render('@integration_test/manual_template.twig'); $this->assertStringContainsString( '', $html2 @@ -102,7 +102,7 @@ public function testCacheWarmer() { $kernel = new WebpackEncoreIntegrationTestKernel(true); $kernel->boot(); - $container = $kernel->getContainer(); + $container = $this->getContainerFromBootedKernel($kernel); $cacheWarmer = $container->get(WebpackEncoreCacheWarmerTester::class); @@ -124,8 +124,8 @@ public function testEnabledStrictMode_throwsException_ifBuildMissing() $kernel->outputPath = 'missing_build'; $kernel->builds = ['different_build' => 'missing_build']; $kernel->boot(); - $container = $kernel->getContainer(); - $container->get('twig')->render('@integration_test/template.twig'); + $twig = $this->getTwigEnvironmentFromBootedKernel($kernel); + $twig->render('@integration_test/template.twig'); } public function testDisabledStrictMode_ignoresMissingBuild() @@ -135,8 +135,8 @@ public function testDisabledStrictMode_ignoresMissingBuild() $kernel->strictMode = false; $kernel->builds = ['different_build' => 'missing_build']; $kernel->boot(); - $container = $kernel->getContainer(); - $html = $container->get('twig')->render('@integration_test/template.twig'); + $twig = $this->getTwigEnvironmentFromBootedKernel($kernel); + $html = $twig->render('@integration_test/template.twig'); self::assertSame('', trim($html)); } @@ -144,7 +144,7 @@ public function testAutowireableInterfaces() { $kernel = new WebpackEncoreIntegrationTestKernel(true); $kernel->boot(); - $container = $kernel->getContainer(); + $container = $this->getContainerFromBootedKernel($kernel); $this->assertInstanceOf(WebpackEncoreAutowireTestService::class, $container->get(WebpackEncoreAutowireTestService::class)); } @@ -152,7 +152,7 @@ public function testPreload() { $kernel = new WebpackEncoreIntegrationTestKernel(true); $kernel->boot(); - $container = $kernel->getContainer(); + $container = $this->getContainerFromBootedKernel($kernel); /** @var TagRenderer $tagRenderer */ $tagRenderer = $container->get('public.webpack_encore.tag_renderer'); @@ -168,7 +168,7 @@ public function testAutowireDefaultBuildArgument() { $kernel = new WebpackEncoreIntegrationTestKernel(true); $kernel->boot(); - $container = $kernel->getContainer(); + $container = $this->getContainerFromBootedKernel($kernel); $container->get('public.webpack_encore.entrypoint_lookup_collection') ->getEntrypointLookup(); @@ -176,6 +176,26 @@ public function testAutowireDefaultBuildArgument() // Testing that it doesn't throw an exception is enough $this->assertTrue(true); } + + private function getContainerFromBootedKernel(WebpackEncoreIntegrationTestKernel $kernel) + { + if ($kernel::VERSION_ID >= 40100) { + return $kernel->getContainer()->get('test.service_container'); + } + + return $kernel->getContainer(); + } + + private function getTwigEnvironmentFromBootedKernel(WebpackEncoreIntegrationTestKernel $kernel) + { + $container = $this->getContainerFromBootedKernel($kernel); + + if ($container->has(\Twig\Environment::class)) { + return $container->get(\Twig\Environment::class); + } + + return $container->get('twig'); + } } abstract class AbstractWebpackEncoreIntegrationTestKernel extends Kernel @@ -206,12 +226,19 @@ public function registerBundles() protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader) { - $container->loadFromExtension('framework', [ + $frameworkConfig = [ 'secret' => 'foo', 'assets' => [ 'enabled' => $this->enableAssets, ], - ]); + 'test' => true, + ]; + if (AbstractWebpackEncoreIntegrationTestKernel::VERSION_ID >= 50100) { + $frameworkConfig['router'] = [ + 'utf8' => true, + ]; + } + $container->loadFromExtension('framework', $frameworkConfig); $container->loadFromExtension('twig', [ 'paths' => [ @@ -238,10 +265,10 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa ->setPublic(true); $container->setAlias(new Alias('public.webpack_encore.tag_renderer', true), 'webpack_encore.tag_renderer'); - $container->getAlias('public.webpack_encore.tag_renderer')->setPrivate(false); + $container->getAlias('public.webpack_encore.tag_renderer')->setPublic(true); $container->setAlias(new Alias('public.webpack_encore.entrypoint_lookup_collection', true), 'webpack_encore.entrypoint_lookup_collection'); - $container->getAlias('public.webpack_encore.entrypoint_lookup_collection')->setPrivate(false); + $container->getAlias('public.webpack_encore.entrypoint_lookup_collection')->setPublic(true); // avoid logging request logs $container->register('logger', Logger::class) @@ -264,11 +291,11 @@ public function renderFoo() } } -if (method_exists(AbstractWebpackEncoreIntegrationTestKernel::class, 'configureRouting')) { +if (AbstractWebpackEncoreIntegrationTestKernel::VERSION_ID >= 50100) { class WebpackEncoreIntegrationTestKernel extends AbstractWebpackEncoreIntegrationTestKernel { protected function configureRouting(RoutingConfigurator $routes): void { - $routes->add('/foo', 'kernel:'.(parent::VERSION_ID >= 40100 ? ':' : '').'renderFoo'); + $routes->add('/foo', 'kernel::renderFoo'); } } } else { diff --git a/tests/TestEntrypointLookupIntegrityDataProviderInterface.php b/tests/TestEntrypointLookupIntegrityDataProviderInterface.php new file mode 100644 index 00000000..2152b552 --- /dev/null +++ b/tests/TestEntrypointLookupIntegrityDataProviderInterface.php @@ -0,0 +1,17 @@ + + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\WebpackEncoreBundle\Tests; + +use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupInterface; +use Symfony\WebpackEncoreBundle\Asset\IntegrityDataProviderInterface; + +interface TestEntrypointLookupIntegrityDataProviderInterface extends EntrypointLookupInterface, IntegrityDataProviderInterface +{ +}