Skip to content
This repository has been archived by the owner on Nov 20, 2020. It is now read-only.

Commit

Permalink
Ensure our bundle works with SF 4.2 (#82)
Browse files Browse the repository at this point in the history
* Ensure our bundle works with SF 4.2

* Travis should also check on 7.2

* The templates should stay in Resources/views

* Ignore deprecation from PHPUnit

We still support SF3.3 and would need to do a major to change the current logic

* FIX: Issue with phpdocumentor/type-resolver

* FIX: composer.json incorrectl formatted
  • Loading branch information
ping-localhost authored and haroldiedema committed Dec 14, 2018
1 parent f702295 commit e12840f
Show file tree
Hide file tree
Showing 21 changed files with 157 additions and 65 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ env:

php:
- '7.1'
- '7.2'
- nightly

matrix:
Expand All @@ -19,6 +20,10 @@ matrix:
env: COMPOSER_FLAGS="--prefer-lowest"
- php: 7.1
env: COMPOSER_FLAGS=""
- php: 7.2
env: COMPOSER_FLAGS="--prefer-lowest"
- php: 7.2
env: COMPOSER_FLAGS=""
allow_failures:
- php: nightly

Expand Down
14 changes: 8 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
"description": "Integrates Webpack with Symfony",
"license": "MIT",
"require": {
"php": "^7.1.0",
"ext-json": "*",
"symfony/monolog-bundle": "^4.0.0||^3.1.0",
"symfony/symfony": "^4.0.0||^3.3.0",
"twig/twig": "^2.4.0"
"php": "^7.1.0",
"ext-json": "*",
"phpdocumentor/type-resolver": "^0.2.1",
"symfony/monolog-bundle": "^4.0.0||^3.1.0",
"symfony/symfony": "^4.0.0||^3.3.0",
"twig/twig": "^2.4.0"
},
"require-dev": {
"hostnet/phpcs-tool": "^8.3.2",
Expand All @@ -25,7 +26,8 @@
"psr-4": {
"Hostnet\\Fixture\\WebpackBundle\\": "test/Fixture",
"Hostnet\\Bundle\\WebpackBundle\\": "test/Bundle",
"Hostnet\\Component\\Webpack\\": "test/Component"
"Hostnet\\Component\\Webpack\\": "test/Component",
"Hostnet\\Tests\\": "test"
}
},
"archive": {
Expand Down
9 changes: 5 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation = "http://schema.phpunit.de/4.7/phpunit.xsd"
colors = "true"
xsi:noNamespaceSchemaLocation = "http://schema.phpunit.de/7.2/phpunit.xsd"
bootstrap = "vendor/autoload.php"
>
colors = "true"
>
<php>
<server name="KERNEL_DIR" value="test/Fixture"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak_vendors"/>
</php>
<testsuites>
<testsuite name="webpack-bundle">
<testsuite name="WebpackBundle - Test Suite">
<directory>./test</directory>
</testsuite>
</testsuites>
Expand Down
32 changes: 30 additions & 2 deletions src/Bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
use Hostnet\Component\Webpack\Configuration\Loader\LoaderInterface;
use Hostnet\Component\Webpack\Configuration\Plugin\PluginInterface;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\HttpKernel\Kernel;

class Configuration implements ConfigurationInterface
{
Expand All @@ -33,8 +35,8 @@ public function __construct(array $bundles = [], array $plugins = [])
*/
public function getConfigTreeBuilder()
{
$tree_builder = new TreeBuilder();
$root_node = $tree_builder->root(self::CONFIG_ROOT);
$tree_builder = $this->createTreeBuilder();
$root_node = $this->retrieveRootNode($tree_builder);
$children = $root_node->children();

$root_node->fixXmlConfig('bundle');
Expand Down Expand Up @@ -169,4 +171,30 @@ private function applyConfigurationFromClass($interface, NodeBuilder $node_build
$class_name::applyConfiguration($node_builder);
}
}

private function createTreeBuilder(): TreeBuilder
{
if (Kernel::VERSION_ID >= 40200) {
return new TreeBuilder(self::CONFIG_ROOT);
}

if (Kernel::VERSION_ID >= 30300 && Kernel::VERSION_ID < 40200) {
return new TreeBuilder();
}

throw new \RuntimeException('This bundle can only be used by Symfony 3.3 and up.');
}

private function retrieveRootNode(TreeBuilder $tree_builder): NodeDefinition
{
if (Kernel::VERSION_ID >= 40200) {
return $tree_builder->getRootNode();
}

if (Kernel::VERSION_ID >= 30300 && Kernel::VERSION_ID < 40200) {
return $tree_builder->root(self::CONFIG_ROOT);
}

throw new \RuntimeException('This bundle can only be used by Symfony 3.3 and up.');
}
}
2 changes: 1 addition & 1 deletion src/Bundle/DependencyInjection/WebpackCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function process(ContainerBuilder $container)

$process_definition = $container
->getDefinition(Process::class)
->replaceArgument(0, $config['node']['binary'] . ' ' . $webpack)
->replaceArgument(0, [$config['node']['binary'] . ' ' . $webpack])
->replaceArgument(1, $container->getParameter('kernel.cache_dir'))
->addMethodCall('setTimeout', [$config['compile_timeout']]);

Expand Down
6 changes: 3 additions & 3 deletions src/Bundle/Resources/views/profiler.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@
</ul>
<div style="clear: both;"></div>

{{ include("WebpackBundle:sections:output.html.twig") }}
{{ include("WebpackBundle:sections:assets.html.twig") }}
{{ include("WebpackBundle:sections:config.html.twig") }}
{{ include("WebpackBundle::sections:output.html.twig") }}
{{ include("WebpackBundle::sections:assets.html.twig") }}
{{ include("WebpackBundle::sections:config.html.twig") }}

<script>sfWebpackSwitchTab('output');</script>
{% endif %}
Expand Down
41 changes: 41 additions & 0 deletions test/AbstractTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* @copyright 2017-present Hostnet B.V.
*/
declare(strict_types=1);

namespace Hostnet\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\HttpKernel\Kernel;

class AbstractTestCase extends TestCase
{
protected function createTreeBuilder(string $config_root): TreeBuilder
{
if (Kernel::VERSION_ID >= 40200) {
return new TreeBuilder($config_root);
}

if (Kernel::VERSION_ID >= 30300 && Kernel::VERSION_ID < 40200) {
return new TreeBuilder();
}

throw new \RuntimeException('This bundle can only be used by Symfony 3.3 and up.');
}

protected function retrieveRootNode(TreeBuilder $tree_builder, string $config_root): NodeDefinition
{
if (Kernel::VERSION_ID >= 40200) {
return $tree_builder->getRootNode();
}

if (Kernel::VERSION_ID >= 30300 && Kernel::VERSION_ID < 40200) {
return $tree_builder->root($config_root);
}

throw new \RuntimeException('This bundle can only be used by Symfony 3.3 and up.');
}
}
7 changes: 4 additions & 3 deletions test/Component/Configuration/Config/OutputConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
namespace Hostnet\Component\Webpack\Configuration\Config;

use Hostnet\Component\Webpack\Configuration\CodeBlock;
use Hostnet\Tests\AbstractTestCase;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;

/**
* @covers \Hostnet\Component\Webpack\Configuration\Config\OutputConfig
*/
class OutputConfigTest extends TestCase
class OutputConfigTest extends AbstractTestCase
{
public function testConfigTreeBuilder()
{
$tree = new TreeBuilder();
$node = $tree->root('webpack')->children();
$tree = $this->createTreeBuilder('webpack');
$node = $this->retrieveRootNode($tree, 'webpack')->children();

OutputConfig::applyConfiguration($node);
$node->end();
Expand Down
7 changes: 4 additions & 3 deletions test/Component/Configuration/Config/ResolveConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
namespace Hostnet\Component\Webpack\Configuration\Config;

use Hostnet\Component\Webpack\Configuration\CodeBlock;
use Hostnet\Tests\AbstractTestCase;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;

/**
* @covers \Hostnet\Component\Webpack\Configuration\Config\ResolveConfig
*/
class ResolveConfigTest extends TestCase
class ResolveConfigTest extends AbstractTestCase
{
public function testConfigTreeBuilder()
{
$tree = new TreeBuilder();
$node = $tree->root('webpack')->children();
$tree = $this->createTreeBuilder('webpack');
$node = $this->retrieveRootNode($tree, 'webpack')->children();

ResolveConfig::applyConfiguration($node);
$node->end();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
namespace Hostnet\Component\Webpack\Configuration\Config;

use Hostnet\Component\Webpack\Configuration\CodeBlock;
use Hostnet\Tests\AbstractTestCase;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;

/**
* @covers \Hostnet\Component\Webpack\Configuration\Config\ResolveLoaderConfig
*/
class ResolveLoaderConfigTest extends TestCase
class ResolveLoaderConfigTest extends AbstractTestCase
{
public function testConfigTreeBuilder()
{
$tree = new TreeBuilder();
$node = $tree->root('webpack')->children();
$tree = $this->createTreeBuilder('webpack');
$node = $this->retrieveRootNode($tree, 'webpack')->children();

ResolveLoaderConfig::applyConfiguration($node);
$node->end();
Expand Down
7 changes: 4 additions & 3 deletions test/Component/Configuration/Loader/BabelLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
namespace Hostnet\Component\Webpack\Configuration\Loader;

use Hostnet\Component\Webpack\Configuration\CodeBlock;
use Hostnet\Tests\AbstractTestCase;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;

/**
* @covers \Hostnet\Component\Webpack\Configuration\Loader\BabelLoader
*/
class BabelLoaderTest extends TestCase
class BabelLoaderTest extends AbstractTestCase
{
public function testConfigTreeBuilder()
{
$tree = new TreeBuilder();
$node = $tree->root('webpack')->children();
$tree = $this->createTreeBuilder('webpack');
$node = $this->retrieveRootNode($tree, 'webpack')->children();

BabelLoader::applyConfiguration($node);
$node->end();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
namespace Hostnet\Component\Webpack\Configuration\Loader;

use Hostnet\Component\Webpack\Configuration\CodeBlock;
use Hostnet\Tests\AbstractTestCase;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;

/**
* @covers \Hostnet\Component\Webpack\Configuration\Loader\CoffeeScriptLoader
*/
class CoffeeScriptLoaderTest extends TestCase
class CoffeeScriptLoaderTest extends AbstractTestCase
{
public function testConfigTreeBuilder()
{
$tree = new TreeBuilder();
$node = $tree->root('coffee')->children();
$tree = $this->createTreeBuilder('webpack');
$node = $this->retrieveRootNode($tree, 'webpack')->children();

CoffeeScriptLoader::applyConfiguration($node);
$node->end();
Expand Down
7 changes: 4 additions & 3 deletions test/Component/Configuration/Loader/CssLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
namespace Hostnet\Component\Webpack\Configuration\Loader;

use Hostnet\Component\Webpack\Configuration\CodeBlock;
use Hostnet\Tests\AbstractTestCase;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;

/**
* @covers \Hostnet\Component\Webpack\Configuration\Loader\CssLoader
*/
class CssLoaderTest extends TestCase
class CssLoaderTest extends AbstractTestCase
{
public function testConfigTreeBuilder()
{
$tree = new TreeBuilder();
$node = $tree->root('webpack')->children();
$tree = $this->createTreeBuilder('webpack');
$node = $this->retrieveRootNode($tree, 'webpack')->children();

CssLoader::applyConfiguration($node);
$node->end();
Expand Down
7 changes: 4 additions & 3 deletions test/Component/Configuration/Loader/LessLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
namespace Hostnet\Component\Webpack\Configuration\Loader;

use Hostnet\Component\Webpack\Configuration\CodeBlock;
use Hostnet\Tests\AbstractTestCase;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;

/**
* @covers \Hostnet\Component\Webpack\Configuration\Loader\LessLoader
*/
class LessLoaderTest extends TestCase
class LessLoaderTest extends AbstractTestCase
{
public function testConfigTreeBuilder()
{
$tree = new TreeBuilder();
$node = $tree->root('webpack')->children();
$tree = $this->createTreeBuilder('webpack');
$node = $this->retrieveRootNode($tree, 'webpack')->children();

LessLoader::applyConfiguration($node);
$node->end();
Expand Down
29 changes: 15 additions & 14 deletions test/Component/Configuration/Loader/SassLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@
namespace Hostnet\Component\Webpack\Configuration\Loader;

use Hostnet\Component\Webpack\Configuration\CodeBlock;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Hostnet\Tests\AbstractTestCase;

/**
* @covers \Hostnet\Component\Webpack\Configuration\Loader\SassLoader
*/
class SassLoaderTest extends TestCase
class SassLoaderTest extends AbstractTestCase
{
public function testConfigTreeBuilder()
{
$tree = new TreeBuilder();
$node = $tree->root('webpack')->children();
$tree = $this->createTreeBuilder('webpack');
$node = $this->retrieveRootNode($tree, 'webpack')->children();

SassLoader::applyConfiguration($node);
$node->end();
Expand Down Expand Up @@ -47,16 +46,18 @@ public function testGetCodeBlock()

public function testGetCodeBlockWithIncludePaths()
{
$config = new SassLoader([
'loaders' => [
'sass' => [
'enabled' => true,
'include_paths' => ['path1', 'path2'],
'filename' => 'testfile',
'all_chunks' => true,
$config = new SassLoader(
[
'loaders' => [
'sass' => [
'enabled' => true,
'include_paths' => ['path1', 'path2'],
'filename' => 'testfile',
'all_chunks' => true,
],
],
],
]);
]
);
$block = $config->getCodeBlocks()[0];

self::assertTrue($block->has(CodeBlock::ROOT));
Expand Down
Loading

0 comments on commit e12840f

Please sign in to comment.