Skip to content
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ php:
- 7.1
- 7.2
- 7.3
- 7.4snapshot
- 7.4

install:
- if [ "$dependencies" = "lowest" ]; then composer update --prefer-lowest --no-interaction; fi
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ RUN composer update ${COMPOSER_FLAGS}
COPY ./src ./src
COPY ./tests ./tests
COPY ./Makefile ./Makefile
COPY ./phpstan.neon ./
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ docker_build:
docker build --build-arg PHP_VERSION=7.2 --build-arg COMPOSER_FLAGS="--prefer-lowest" -t isocontent:7.2-lowdeps .
docker build --build-arg PHP_VERSION=7.3 -t isocontent:7.3 .
docker build --build-arg PHP_VERSION=7.3 --build-arg COMPOSER_FLAGS="--prefer-lowest" -t isocontent:7.3-lowdeps .
docker build --build-arg PHP_VERSION=7.4 -t isocontent:7.4 .
docker build --build-arg PHP_VERSION=7.4 --build-arg COMPOSER_FLAGS="--prefer-lowest" -t isocontent:7.4-lowdeps .

docker_test: docker_build
docker run -it --rm isocontent:7.1 ./vendor/bin/phpunit tests --colors
Expand All @@ -24,6 +26,8 @@ docker_test: docker_build
docker run -it --rm isocontent:7.2-lowdeps ./vendor/bin/phpunit tests --colors
docker run -it --rm isocontent:7.3 ./vendor/bin/phpunit tests --colors
docker run -it --rm isocontent:7.3-lowdeps ./vendor/bin/phpunit tests --colors
docker run -it --rm isocontent:7.4 ./vendor/bin/phpunit tests --colors
docker run -it --rm isocontent:7.4-lowdeps ./vendor/bin/phpunit tests --colors

docker_phpstan: docker_build
docker run -it --rm isocontent:7.1 ./vendor/bin/phpstan analyse src --level 7
Expand All @@ -32,4 +36,6 @@ docker_phpstan: docker_build
docker run -it --rm isocontent:7.2-lowdeps ./vendor/bin/phpstan analyse src --level 7
docker run -it --rm isocontent:7.3 ./vendor/bin/phpstan analyse src --level 7
docker run -it --rm isocontent:7.3-lowdeps ./vendor/bin/phpstan analyse src --level 7
docker run -it --rm isocontent:7.4 ./vendor/bin/phpstan analyse src --level 7
docker run -it --rm isocontent:7.4-lowdeps ./vendor/bin/phpstan analyse src --level 7

7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@
"ext-dom": "ext-dom is required for DOMParser usage",
"ext-json": "ext-json is required for JSONRenderer usage",
"symfony/framework-bundle": "for Symfony integration",
"symfony/serializer": "for serialization of AST"
"symfony/serializer": "for serialization of AST",
"twig/twig": "for Symfony integration"
},
"require-dev": {
"ext-dom": "*",
"ext-json": "*",
"phpunit/phpunit": "^7.5.6 || ^8.0",
"spatie/phpunit-watcher": "^1.8",
"symfony/var-dumper": "^4.2",
"phpspec/prophecy": "^1.10",
"phpstan/phpstan": "^0.11.2",
"symfony/framework-bundle": "^3.4 || ^4.2",
"symfony/serializer": "^3.4 || ^4.2",
"satooshi/php-coveralls": "^2.1"
"satooshi/php-coveralls": "^2.1",
"twig/twig": "^1.28 || ^2.0"
},
"autoload": {
"psr-4": {
Expand Down
13 changes: 13 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
parameters:
reportUnmatchedIgnoredErrors: false
excludes_analyse:
- 'vendor/*'

ignoreErrors:
# Symfony 3.4 compatibility
- '/Call to function method_exists\(\) with .Symfony\\\\Component…. and .getRootNode. will always evaluate to false/'
- '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::children\(\).#'
- '/Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder::getRootNode\(\)/'
- '/Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder::root\(\)/'
- '/Class Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder constructor invoked with 0 parameters, 1-3 required./'
- '/Class Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder does not have a constructor and must be instantiated without any parameters/'
14 changes: 11 additions & 3 deletions src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@ class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder(): TreeBuilder
{
$builder = new TreeBuilder();
/** @var ArrayNodeDefinition $root */
$root = $builder->root('isocontent');
if (method_exists(TreeBuilder::class, 'getRootNode')) {
$builder = new TreeBuilder('isocontent');

/** @var ArrayNodeDefinition $rootNode */
$root = $builder->getRootNode();
} else {
$builder = new TreeBuilder();

/** @var ArrayNodeDefinition $rootNode */
$root= $builder->root('isocontent');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacing

}

$root
->children()
Expand Down
28 changes: 28 additions & 0 deletions src/Bridge/Symfony/Bundle/Extension/Twig/IsoContentExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Isocontent\Bridge\Symfony\Bundle\Extension\Twig;

use Isocontent\AST\NodeList;
use Isocontent\Renderer\HTMLRenderer;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

/**
* Twig extension for displaying IsoContent
*
* @author Yohan Giarelli <[email protected]>
*/
class IsoContentExtension extends AbstractExtension
{
public function getFunctions()
{
return [
new TwigFunction('display_isocontent', [$this, 'displayIsoContent']),
];
}

public function displayIsoContent(NodeList $ast): ?string
{
return (new HTMLRenderer)->render($ast);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace Isocontent\Tests\Bridge\Symfony\Bundle\Extension\Twig;

use Isocontent\AST\BlockNode;
use Isocontent\AST\NodeList;
use Isocontent\AST\TextNode;
use Isocontent\Bridge\Symfony\Bundle\Extension\Twig\IsoContentExtension;
use PHPUnit\Framework\TestCase;
use Twig\TwigFunction;

class IsoContentExtensionTest extends TestCase
{
/**
* @dataProvider astProvider
*/
public function testDisplayIsoContentFunction(NodeList $ast, string $expect)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests methods should be written un snake_case.

{
$extension = new IsoContentExtension();
$this->assertEquals($expect, $extension->displayIsoContent($ast));
}

/**
* @dataProvider functionProvider
*/
public function testGetTwigFunctions(string $expect,TwigFunction $function)
{
$this->assertSame($expect, $function->getName());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing new line

public function testGetFunction(){
$extension = new IsoContentExtension();
$this->assertTrue(is_array($extension->getFunctions()));
$functions = $extension->getFunctions();
$this->assertInstanceOf(TwigFunction::class,$functions[0]);
}
public static function astProvider()
{
return [
[
NodeList::fromArray([TextNode::fromText('Foo')]),
'Foo',
],
[
NodeList::fromArray([
BlockNode::fromBlockType('inline_text', [], NodeList::fromArray([
TextNode::fromText('Foo')
])),
]),
'<span>Foo</span>',
],
[
NodeList::fromArray([
BlockNode::fromBlockType('paragraph', [], NodeList::fromArray([
TextNode::fromText('Some paragraph '),
BlockNode::fromBlockType('inline_text', [], NodeList::fromArray([
TextNode::fromText('with some inline text'),
])),
BlockNode::fromBlockType('list', ['ordered' => false], NodeList::fromArray([
BlockNode::fromBlockType('list_item', [], NodeList::fromArray([
TextNode::fromText('Unsorted'),
])),
BlockNode::fromBlockType('list_item', [], NodeList::fromArray([
TextNode::fromText('data'),
]))
]))
])),
]),
'<p>Some paragraph <span>with some inline text</span><ul><li>Unsorted</li><li>data</li></ul></p>'
],
[
NodeList::fromArray([]),
''
],

];
}

public function functionProvider()
{
$extension = new IsoContentExtension();
$function = $extension->getFunctions();
return[
['display_isocontent', $function[0]],
];
}
}
12 changes: 11 additions & 1 deletion tests/E2E/HTML2HTMLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,17 @@ public function htmlProvider(): array
[
'<ul><li>foo</li><li>bar</li><li>baz <ol><li>qux</li></ol></li></ul>' .
'<blockquote><p>Foobar</p></blockquote><br />'
]
],
[ '<h4>Heading with a <strong>strong</strong></h4>'.
'<p><span>Always escape your element &acd;</span></p>'.
'<br />'.
'<ul><li>Some <strong>element</strong></li><li>are more <em>important than other</em></li></ul>'
],
[ '<h4>Heading with <strong>strong and <em>emphasis</em></strong> text </h4>'.
'<h5>Some <em>emphasis with<strong>too</strong></em></h5>'
],
[ '<p>Some paragraph with some <span> inline text <br /> with a return </span></p>'
],
];
}
}
Loading