Skip to content

Commit c879bc5

Browse files
committed
feature #98 PHP 8.0 compatibility (jmsche)
This PR was squashed before being merged into the master branch. Discussion ---------- PHP 8.0 compatibility Tests are also run against PHP7.4. Commits ------- 0c797de PHP 8.0 compatibility
2 parents 5c0f659 + 0c797de commit c879bc5

File tree

6 files changed

+77
-28
lines changed

6 files changed

+77
-28
lines changed

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ matrix:
1818
- php: 7.2
1919
- php: 7.3
2020
env: deps=low
21+
- php: 7.4
22+
env: SYMFONY_PHPUNIT_VERSION=9.4
23+
- php: nightly
24+
env: SYMFONY_PHPUNIT_VERSION=9.4
2125

2226
before_install:
2327
- phpenv config-rm xdebug.ini || true
24-
- composer global require --no-progress --no-scripts --no-plugins symfony/flex dev-master
28+
- composer global require --no-progress --no-scripts --no-plugins symfony/flex dev-main
2529

2630
install:
2731
- |

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
},
2222
"minimum-stability": "dev",
2323
"require": {
24-
"php": "^7.1.3",
24+
"php": ">=7.1.3",
2525
"symfony/asset": "^3.4 || ^4.0 || ^5.0",
2626
"symfony/config": "^3.4 || ^4.0 || ^5.0",
2727
"symfony/dependency-injection": "^3.4 || ^4.0 || ^5.0",

tests/Asset/TagRendererTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
use Symfony\Component\Asset\Packages;
1414
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupCollection;
1515
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupInterface;
16-
use Symfony\WebpackEncoreBundle\Asset\IntegrityDataProviderInterface;
1716
use Symfony\WebpackEncoreBundle\Asset\TagRenderer;
17+
use Symfony\WebpackEncoreBundle\Tests\TestEntrypointLookupIntegrityDataProviderInterface;
1818

1919
class TagRendererTest extends TestCase
2020
{
@@ -138,10 +138,7 @@ public function testRenderScriptTagsWithinAnEntryPointCollection()
138138

139139
public function testRenderScriptTagsWithHashes()
140140
{
141-
$entrypointLookup = $this->createMock([
142-
EntrypointLookupInterface::class,
143-
IntegrityDataProviderInterface::class,
144-
]);
141+
$entrypointLookup = $this->createMock(TestEntrypointLookupIntegrityDataProviderInterface::class);
145142
$entrypointLookup->expects($this->once())
146143
->method('getJavaScriptFiles')
147144
->willReturn(['/build/file1.js', '/build/file2.js']);

tests/EventListener/ExceptionListenerTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Symfony\WebpackEncoreBundle\Tests\EventListener;
1111

1212
use Symfony\Component\HttpFoundation\Request;
13+
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
1314
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
1415
use Symfony\Component\HttpKernel\HttpKernelInterface;
1516
use PHPUnit\Framework\TestCase;
@@ -39,7 +40,10 @@ public function testItResetsAllEntrypointLookups()
3940

4041
$request = new Request();
4142
$exception = new \Exception();
42-
$event = new GetResponseForExceptionEvent(
43+
$exceptionEventClass = class_exists(ExceptionEvent::class)
44+
? ExceptionEvent::class
45+
: GetResponseForExceptionEvent::class;
46+
$event = new $exceptionEventClass(
4347
$this->createMock(HttpKernelInterface::class),
4448
$request,
4549
HttpKernelInterface::MASTER_REQUEST,

tests/IntegrationTest.php

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public function testTwigIntegration()
3636
{
3737
$kernel = new WebpackEncoreIntegrationTestKernel(true);
3838
$kernel->boot();
39-
$container = $kernel->getContainer();
39+
$twig = $this->getTwigEnvironmentFromBootedKernel($kernel);
4040

41-
$html1 = $container->get('twig')->render('@integration_test/template.twig');
41+
$html1 = $twig->render('@integration_test/template.twig');
4242
$this->assertStringContainsString(
4343
'<script src="/build/file1.js" integrity="sha384-Q86c+opr0lBUPWN28BLJFqmLhho+9ZcJpXHorQvX6mYDWJ24RQcdDarXFQYN8HLc"></script>',
4444
$html1
@@ -58,7 +58,7 @@ public function testTwigIntegration()
5858
$html1
5959
);
6060

61-
$html2 = $container->get('twig')->render('@integration_test/manual_template.twig');
61+
$html2 = $twig->render('@integration_test/manual_template.twig');
6262
$this->assertStringContainsString(
6363
'<script src="/build/file3.js"></script>',
6464
$html2
@@ -73,10 +73,10 @@ public function testEntriesAreNotRepeatedWhenAlreadyOutputIntegration()
7373
{
7474
$kernel = new WebpackEncoreIntegrationTestKernel(true);
7575
$kernel->boot();
76-
$container = $kernel->getContainer();
76+
$twig = $this->getTwigEnvironmentFromBootedKernel($kernel);
7777

78-
$html1 = $container->get('twig')->render('@integration_test/template.twig');
79-
$html2 = $container->get('twig')->render('@integration_test/manual_template.twig');
78+
$html1 = $twig->render('@integration_test/template.twig');
79+
$html2 = $twig->render('@integration_test/manual_template.twig');
8080
$this->assertStringContainsString(
8181
'<script src="/build/file3.js"></script>',
8282
$html2
@@ -102,7 +102,7 @@ public function testCacheWarmer()
102102
{
103103
$kernel = new WebpackEncoreIntegrationTestKernel(true);
104104
$kernel->boot();
105-
$container = $kernel->getContainer();
105+
$container = $this->getContainerFromBootedKernel($kernel);
106106

107107
$cacheWarmer = $container->get(WebpackEncoreCacheWarmerTester::class);
108108

@@ -124,8 +124,8 @@ public function testEnabledStrictMode_throwsException_ifBuildMissing()
124124
$kernel->outputPath = 'missing_build';
125125
$kernel->builds = ['different_build' => 'missing_build'];
126126
$kernel->boot();
127-
$container = $kernel->getContainer();
128-
$container->get('twig')->render('@integration_test/template.twig');
127+
$twig = $this->getTwigEnvironmentFromBootedKernel($kernel);
128+
$twig->render('@integration_test/template.twig');
129129
}
130130

131131
public function testDisabledStrictMode_ignoresMissingBuild()
@@ -135,24 +135,24 @@ public function testDisabledStrictMode_ignoresMissingBuild()
135135
$kernel->strictMode = false;
136136
$kernel->builds = ['different_build' => 'missing_build'];
137137
$kernel->boot();
138-
$container = $kernel->getContainer();
139-
$html = $container->get('twig')->render('@integration_test/template.twig');
138+
$twig = $this->getTwigEnvironmentFromBootedKernel($kernel);
139+
$html = $twig->render('@integration_test/template.twig');
140140
self::assertSame('', trim($html));
141141
}
142142

143143
public function testAutowireableInterfaces()
144144
{
145145
$kernel = new WebpackEncoreIntegrationTestKernel(true);
146146
$kernel->boot();
147-
$container = $kernel->getContainer();
147+
$container = $this->getContainerFromBootedKernel($kernel);
148148
$this->assertInstanceOf(WebpackEncoreAutowireTestService::class, $container->get(WebpackEncoreAutowireTestService::class));
149149
}
150150

151151
public function testPreload()
152152
{
153153
$kernel = new WebpackEncoreIntegrationTestKernel(true);
154154
$kernel->boot();
155-
$container = $kernel->getContainer();
155+
$container = $this->getContainerFromBootedKernel($kernel);
156156

157157
/** @var TagRenderer $tagRenderer */
158158
$tagRenderer = $container->get('public.webpack_encore.tag_renderer');
@@ -168,14 +168,34 @@ public function testAutowireDefaultBuildArgument()
168168
{
169169
$kernel = new WebpackEncoreIntegrationTestKernel(true);
170170
$kernel->boot();
171-
$container = $kernel->getContainer();
171+
$container = $this->getContainerFromBootedKernel($kernel);
172172

173173
$container->get('public.webpack_encore.entrypoint_lookup_collection')
174174
->getEntrypointLookup();
175175

176176
// Testing that it doesn't throw an exception is enough
177177
$this->assertTrue(true);
178178
}
179+
180+
private function getContainerFromBootedKernel(WebpackEncoreIntegrationTestKernel $kernel)
181+
{
182+
if ($kernel::VERSION_ID >= 40100) {
183+
return $kernel->getContainer()->get('test.service_container');
184+
}
185+
186+
return $kernel->getContainer();
187+
}
188+
189+
private function getTwigEnvironmentFromBootedKernel(WebpackEncoreIntegrationTestKernel $kernel)
190+
{
191+
$container = $this->getContainerFromBootedKernel($kernel);
192+
193+
if ($container->has(\Twig\Environment::class)) {
194+
return $container->get(\Twig\Environment::class);
195+
}
196+
197+
return $container->get('twig');
198+
}
179199
}
180200

181201
abstract class AbstractWebpackEncoreIntegrationTestKernel extends Kernel
@@ -206,12 +226,19 @@ public function registerBundles()
206226

207227
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
208228
{
209-
$container->loadFromExtension('framework', [
229+
$frameworkConfig = [
210230
'secret' => 'foo',
211231
'assets' => [
212232
'enabled' => $this->enableAssets,
213233
],
214-
]);
234+
'test' => true,
235+
];
236+
if (AbstractWebpackEncoreIntegrationTestKernel::VERSION_ID >= 50100) {
237+
$frameworkConfig['router'] = [
238+
'utf8' => true,
239+
];
240+
}
241+
$container->loadFromExtension('framework', $frameworkConfig);
215242

216243
$container->loadFromExtension('twig', [
217244
'paths' => [
@@ -238,10 +265,10 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa
238265
->setPublic(true);
239266

240267
$container->setAlias(new Alias('public.webpack_encore.tag_renderer', true), 'webpack_encore.tag_renderer');
241-
$container->getAlias('public.webpack_encore.tag_renderer')->setPrivate(false);
268+
$container->getAlias('public.webpack_encore.tag_renderer')->setPublic(true);
242269

243270
$container->setAlias(new Alias('public.webpack_encore.entrypoint_lookup_collection', true), 'webpack_encore.entrypoint_lookup_collection');
244-
$container->getAlias('public.webpack_encore.entrypoint_lookup_collection')->setPrivate(false);
271+
$container->getAlias('public.webpack_encore.entrypoint_lookup_collection')->setPublic(true);
245272

246273
// avoid logging request logs
247274
$container->register('logger', Logger::class)
@@ -264,11 +291,11 @@ public function renderFoo()
264291
}
265292
}
266293

267-
if (method_exists(AbstractWebpackEncoreIntegrationTestKernel::class, 'configureRouting')) {
294+
if (AbstractWebpackEncoreIntegrationTestKernel::VERSION_ID >= 50100) {
268295
class WebpackEncoreIntegrationTestKernel extends AbstractWebpackEncoreIntegrationTestKernel {
269296
protected function configureRouting(RoutingConfigurator $routes): void
270297
{
271-
$routes->add('/foo', 'kernel:'.(parent::VERSION_ID >= 40100 ? ':' : '').'renderFoo');
298+
$routes->add('/foo', 'kernel::renderFoo');
272299
}
273300
}
274301
} else {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony WebpackEncoreBundle package.
5+
* (c) Fabien Potencier <[email protected]>
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
namespace Symfony\WebpackEncoreBundle\Tests;
11+
12+
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupInterface;
13+
use Symfony\WebpackEncoreBundle\Asset\IntegrityDataProviderInterface;
14+
15+
interface TestEntrypointLookupIntegrityDataProviderInterface extends EntrypointLookupInterface, IntegrityDataProviderInterface
16+
{
17+
}

0 commit comments

Comments
 (0)