Skip to content

Commit

Permalink
feature #80 Allow Symfony 5 (nicolas-grekas)
Browse files Browse the repository at this point in the history
This PR was merged into the master branch.

Discussion
----------

Allow Symfony 5

Commits
-------

6970a17 Allow Symfony 5
  • Loading branch information
weaverryan committed Oct 22, 2019
2 parents 8666b66 + 6970a17 commit 10acbc0
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 114 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ composer.lock
phpunit.xml
vendor/
.php_cs.cache
.phpunit.result.cache
1 change: 1 addition & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ return PhpCsFixer\Config::create()
->setRules(array(
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHPUnit75Migration:risky' => true,
'array_syntax' => ['syntax' => 'short'],
'protected_to_private' => false,
'semicolon_after_instruction' => false,
Expand Down
26 changes: 10 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,28 @@ env:
global:
- PHPUNIT_FLAGS="-v"
- SYMFONY_PHPUNIT_DIR="$HOME/symfony-bridge/.phpunit"
- SYMFONY_REQUIRE='>=2.8'

matrix:
fast_finish: true
include:
- php: 7.1
env: SYMFONY_PHPUNIT_VERSION=7.4
- php: 7.1
env: deps=high SYMFONY_PHPUNIT_VERSION=7.4
- php: 7.2
env: deps=low
- php: 7.3

allow_failures:
# Dev-master is allowed to fail.
- env: STABILITY="dev"
env: deps=low

before_install:
- if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi
- if ! [ -z "$STABILITY" ]; then composer config minimum-stability ${STABILITY}; fi;
- phpenv config-rm xdebug.ini || true
- composer global require --no-progress --no-scripts --no-plugins symfony/flex dev-master

install:
- |
# Install symfony/flex
if [[ $deps = low ]]; then
export SYMFONY_REQUIRE='>=2.3'
export SYMFONY_DEPRECATIONS_HELPER=weak
composer update --prefer-dist --prefer-lowest --prefer-stable
else
composer update --prefer-dist
fi
composer global require --no-progress --no-scripts --no-plugins symfony/flex dev-master
install:
- composer install
- ./vendor/bin/simple-phpunit install

script:
Expand Down
19 changes: 9 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,20 @@
"Symfony\\WebpackEncoreBundle\\Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"require": {
"php": "^7.1.3",
"symfony/asset": "^3.4 || ^4.0",
"symfony/config": "^3.4 || ^4.0",
"symfony/dependency-injection": "^3.4 || ^4.0",
"symfony/http-kernel": "^3.4 || ^4.0",
"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",
"symfony/http-kernel": "^3.4 || ^4.0 || ^5.0",
"symfony/service-contracts": "^1.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.14",
"symfony/framework-bundle": "^3.4 || ^4.0",
"symfony/phpunit-bridge": "^3.4 || ^4.1",
"symfony/twig-bundle": "^3.4 || ^4.0",
"twig/twig": "^1.35 || ^2.0",
"symfony/web-link": "^3.4 || ^4.0",
"symfony/framework-bundle": "^3.4 || ^4.0 || ^5.0",
"symfony/phpunit-bridge": "^4.3.5 || ^5.0",
"symfony/twig-bundle": "^3.4 || ^4.0 || ^5.0",
"symfony/web-link": "^3.4 || ^4.0 || ^5.0",
"fig/link-util": "^1.0"
},
"extra": {
Expand Down
6 changes: 6 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
backupGlobals="false"
bootstrap="vendor/autoload.php"
colors="true"
failOnRisky="true"
failOnWarning="true"
>
<php>
<server name="SYMFONY_PHPUNIT_VERSION" value="7.5" />
</php>

<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
Expand Down
2 changes: 1 addition & 1 deletion src/Asset/EntrypointLookupCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

namespace Symfony\WebpackEncoreBundle\Asset;

use Symfony\WebpackEncoreBundle\Exception\UndefinedBuildException;
use Psr\Container\ContainerInterface;
use Symfony\WebpackEncoreBundle\Exception\UndefinedBuildException;

/**
* Aggregate the different entry points configured in the container.
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/WebpackEncoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private function entrypointFactory(ContainerBuilder $container, string $name, st
$strictMode,
];
$definition = new Definition(EntrypointLookup::class, $arguments);
$definition->addTag('kernel.reset', ['method'=>'reset']);
$definition->addTag('kernel.reset', ['method' => 'reset']);
$container->setDefinition($id, $definition);

return new Reference($id);
Expand Down
7 changes: 5 additions & 2 deletions src/EventListener/PreLoadAssetsEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Fig\Link\GenericLinkProvider;
use Fig\Link\Link;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\WebpackEncoreBundle\Asset\TagRenderer;

/**
Expand All @@ -27,7 +27,10 @@ public function __construct(TagRenderer $tagRenderer)
$this->tagRenderer = $tagRenderer;
}

public function onKernelResponse(FilterResponseEvent $event)
/**
* @param ResponseEvent $event
*/
public function onKernelResponse($event)
{
if (!$event->isMasterRequest()) {
return;
Expand Down
16 changes: 7 additions & 9 deletions tests/Asset/EntrypointLookupCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,27 @@

namespace Symfony\WebpackEncoreBundle\Tests\Asset;

use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupCollection;
use PHPUnit\Framework\TestCase;
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupInterface;

class EntrypointLookupCollectionTest extends TestCase
{
/**
* @expectedException \Symfony\WebpackEncoreBundle\Exception\UndefinedBuildException
* @expectedExceptionMessage The build "something" is not configured
*/
public function testExceptionOnMissingEntry()
{
$this->expectException(\Symfony\WebpackEncoreBundle\Exception\UndefinedBuildException::class);
$this->expectExceptionMessage('The build "something" is not configured');

$collection = new EntrypointLookupCollection(new ServiceLocator([]));
$collection->getEntrypointLookup('something');
}

/**
* @expectedException \Symfony\WebpackEncoreBundle\Exception\UndefinedBuildException
* @expectedExceptionMessage There is no default build configured: please pass an argument to getEntrypointLookup().
*/
public function testExceptionOnMissingDefaultBuildEntry()
{
$this->expectException(\Symfony\WebpackEncoreBundle\Exception\UndefinedBuildException::class);
$this->expectExceptionMessage('There is no default build configured: please pass an argument to getEntrypointLookup().');

$collection = new EntrypointLookupCollection(new ServiceLocator([]));
$collection->getEntrypointLookup();
}
Expand Down
39 changes: 17 additions & 22 deletions tests/Asset/EntrypointLookupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

namespace Symfony\WebpackEncoreBundle\Tests\Asset;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookup;
use PHPUnit\Framework\TestCase;

class EntrypointLookupTest extends TestCase
{
Expand Down Expand Up @@ -45,7 +45,7 @@ class EntrypointLookupTest extends TestCase
}
EOF;

public function setUp()
protected function setUp(): void
{
$filename = tempnam(sys_get_temp_dir(), 'WebpackEncoreBundle');
file_put_contents($filename, self::$testJson);
Expand Down Expand Up @@ -119,57 +119,52 @@ public function testMissingIntegrityData()
$this->assertEquals([], $this->entrypointLookup->getIntegrityData());
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessageContains There was a problem JSON decoding the
*/
public function testExceptionOnInvalidJson()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('There was a problem JSON decoding the');

$filename = tempnam(sys_get_temp_dir(), 'WebpackEncoreBundle');
file_put_contents($filename, 'abcd');

$this->entrypointLookup = new EntrypointLookup($filename);
$this->entrypointLookup->getJavaScriptFiles('an_entry');
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessageContains Could not find an "entrypoints" key in the
*/
public function testExceptionOnMissingEntrypointsKeyInJson()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Could not find an "entrypoints" key in the');

$filename = tempnam(sys_get_temp_dir(), 'WebpackEncoreBundle');
file_put_contents($filename, '{}');

$this->entrypointLookup = new EntrypointLookup($filename);
$this->entrypointLookup->getJavaScriptFiles('an_entry');
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Could not find the entrypoints file
*/
public function testExceptionOnBadFilename()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Could not find the entrypoints file');

$entrypointLookup = new EntrypointLookup('fake_file');
$entrypointLookup->getCssFiles('anything');
}

/**
* @expectedException \Symfony\WebpackEncoreBundle\Exception\EntrypointNotFoundException
* @expectedExceptionMessage Could not find the entry
*/
public function testExceptionOnMissingEntry()
{
$this->expectException(\Symfony\WebpackEncoreBundle\Exception\EntrypointNotFoundException::class);
$this->expectExceptionMessage('Could not find the entry');

$this->entrypointLookup->getCssFiles('fake_entry');
}

/**
* @expectedException \Symfony\WebpackEncoreBundle\Exception\EntrypointNotFoundException
* @expectedExceptionMessage Try "my_entry" instead
*/
public function testExceptionOnEntryWithExtension()
{
$this->expectException(\Symfony\WebpackEncoreBundle\Exception\EntrypointNotFoundException::class);
$this->expectExceptionMessage('Try "my_entry" instead');

$this->entrypointLookup->getJavaScriptFiles('my_entry.js');
}

Expand Down
18 changes: 9 additions & 9 deletions tests/Asset/TagRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Asset\Packages;
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupInterface;
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupCollection;
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupInterface;
use Symfony\WebpackEncoreBundle\Asset\IntegrityDataProviderInterface;
use Symfony\WebpackEncoreBundle\Asset\TagRenderer;

Expand Down Expand Up @@ -43,11 +43,11 @@ public function testRenderScriptTagsWithDefaultAttributes()
$renderer = new TagRenderer($entrypointCollection, $packages, []);

$output = $renderer->renderWebpackScriptTags('my_entry', 'custom_package');
$this->assertContains(
$this->assertStringContainsString(
'<script src="http://localhost:8080/build/file1.js"></script>',
$output
);
$this->assertContains(
$this->assertStringContainsString(
'<script src="http://localhost:8080/build/file2.js"></script>',
$output
);
Expand All @@ -74,7 +74,7 @@ public function testRenderScriptTagsWithBadFilename()
$renderer = new TagRenderer($entrypointCollection, $packages, ['crossorigin' => 'anonymous']);

$output = $renderer->renderWebpackScriptTags('my_entry', 'custom_package');
$this->assertContains(
$this->assertStringContainsString(
'<script crossorigin="anonymous" src="http://localhost:8080/build/file&lt;&quot;bad_chars.js"></script>',
$output
);
Expand Down Expand Up @@ -120,17 +120,17 @@ public function testRenderScriptTagsWithinAnEntryPointCollection()
$renderer = new TagRenderer($entrypointCollection, $packages, ['crossorigin' => 'anonymous']);

$output = $renderer->renderWebpackScriptTags('my_entry', 'custom_package');
$this->assertContains(
$this->assertStringContainsString(
'<script crossorigin="anonymous" src="http://localhost:8080/build/file1.js"></script>',
$output
);
$output = $renderer->renderWebpackScriptTags('my_entry', null, 'second');
$this->assertContains(
$this->assertStringContainsString(
'<script crossorigin="anonymous" src="http://localhost:8080/build/file2.js"></script>',
$output
);
$output = $renderer->renderWebpackScriptTags('my_entry', 'specific_package', 'third');
$this->assertContains(
$this->assertStringContainsString(
'<script crossorigin="anonymous" src="http://localhost:8080/build/file3.js"></script>',
$output
);
Expand Down Expand Up @@ -170,11 +170,11 @@ public function testRenderScriptTagsWithHashes()
$renderer = new TagRenderer($entrypointCollection, $packages, ['crossorigin' => 'anonymous']);

$output = $renderer->renderWebpackScriptTags('my_entry', 'custom_package');
$this->assertContains(
$this->assertStringContainsString(
'<script crossorigin="anonymous" src="http://localhost:8080/build/file1.js" integrity="sha384-Q86c+opr0lBUPWN28BLJFqmLhho+9ZcJpXHorQvX6mYDWJ24RQcdDarXFQYN8HLc"></script>',
$output
);
$this->assertContains(
$this->assertStringContainsString(
'<script crossorigin="anonymous" src="http://localhost:8080/build/file2.js" integrity="sha384-ymG7OyjISWrOpH9jsGvajKMDEOP/mKJq8bHC0XdjQA6P8sg2nu+2RLQxcNNwE/3J"></script>',
$output
);
Expand Down
Loading

0 comments on commit 10acbc0

Please sign in to comment.