Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.php_cs.cache
.phpunit.result.cache
phpunit.xml
composer.lock
vendor/
13 changes: 13 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

$finder = PhpCsFixer\Finder::create()
->exclude('Resources')
->in(__DIR__)
;

return PhpCsFixer\Config::create()
->setRules([
'@Symfony' => true,
])
->setFinder($finder)
;
69 changes: 65 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,66 @@
language: php
php:
- '7.1'
install: composer install
script: php vendor/bin/phpunit

sudo: false

dist: xenial

env:
global:
- COMPOSER_MEMORY_LIMIT=-1
- SYMFONY_PHPUNIT_DIR=$HOME/.phpunit-bridge

cache:
directories:
- $HOME/.composer/cache
- $HOME/.phpunit-bridge

jobs:
include:
# Lowest
- php: 5.5
dist: trusty
env: NO_FLEX=1 COMPOSER_FLAGS="--prefer-lowest" SYMFONY_DEPRECATIONS_HELPER=weak
- php: 7.1
env: SYMFONY_REQUIRE="4.3.*" COMPOSER_FLAGS="--prefer-lowest"

# Stable
- php: 7.2
env: SYMFONY_REQUIRE="3.4.*" COMPOSER_FLAGS="--prefer-stable"
- php: 7.3
env: SYMFONY_REQUIRE="4.4.*" COMPOSER_FLAGS="--prefer-stable"
- php: 7.4
env: SYMFONY_REQUIRE="5.0.*" COMPOSER_FLAGS="--prefer-stable"

# Dev
- php: 7.4
env: STABILITY=dev

# QA
- stage: QA
name: PHP CS Fixer
php: 7.4
script: vendor/bin/php-cs-fixer fix --dry-run --diff
- name: Coverage
php: 7.4
before_script:
- mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{.disabled,}
- if [[ ! $(php -m | grep -si xdebug) ]]; then echo "xdebug required for coverage"; exit 1; fi
script:
- ./vendor/bin/simple-phpunit -v --coverage-text

allow_failures:
- env: STABILITY=dev

before_install:
- mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{,.disabled} || echo "xdebug not available"
- composer self-update
- if [[ -z $NO_FLEX ]]; then composer global require --no-progress --no-scripts --no-plugins symfony/flex; fi;

install:
- composer update --prefer-dist --no-interaction $COMPOSER_FLAGS
- vendor/bin/simple-phpunit install

script:
- if [[ -v $STABILITY ]]; then composer config minimum-stability $STABILITY; fi;
- composer validate --strict --no-check-lock
- vendor/bin/simple-phpunit -v
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Exercise\HTMLPurifierBundle\DependencyInjection;

use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/ExerciseHTMLPurifierExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Exercise\HTMLPurifierBundle\HTMLPurifiersRegistryInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

class ExerciseHTMLPurifierExtension extends Extension
Expand Down
3 changes: 1 addition & 2 deletions Form/Listener/HTMLPurifierListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class HTMLPurifierListener implements EventSubscriberInterface
private $profile;

/**
* @param HTMLPurifiersRegistryInterface $registry
* @param string $profile
* @param string $profile
*/
public function __construct(HTMLPurifiersRegistryInterface $registry, $profile)
{
Expand Down
47 changes: 47 additions & 0 deletions Form/TypeExtension/ForwardCompatTypeExtensionTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Exercise\HTMLPurifierBundle\Form\TypeExtension;

use Symfony\Component\Form\FormTypeExtensionInterface;

if (method_exists(FormTypeExtensionInterface::class, 'getExtendedTypes')) {
eval('
namespace Exercise\HTMLPurifierBundle\Form\TypeExtension;

/**
* @internal
*/
trait ForwardCompatTypeExtensionTrait
{
private static function doGetExtendedTypes(): iterable
{
}

public static function getExtendedTypes(): iterable
{
return self::doGetExtendedTypes();
}
}
');
} else {
/**
* @internal
*/
trait ForwardCompatTypeExtensionTrait
{
/**
* @return iterable
*/
private static function doGetExtendedTypes()
{
}

/**
* @return iterable
*/
public static function getExtendedTypes()
{
return self::doGetExtendedTypes();
}
}
}
7 changes: 3 additions & 4 deletions Form/TypeExtension/HTMLPurifierTextTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

class HTMLPurifierTextTypeExtension extends AbstractTypeExtension
{
use ForwardCompatTypeExtensionTrait;

private $purifiersRegistry;

public function __construct(HTMLPurifiersRegistryInterface $registry)
Expand All @@ -28,10 +30,7 @@ public function getExtendedType()
return TextType::class;
}

/**
* {@inheritdoc}
*/
public static function getExtendedTypes()
private static function doGetExtendedTypes()
{
return [TextType::class];
}
Expand Down
22 changes: 19 additions & 3 deletions Tests/CacheWarmer/SerializerCacheWarmerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,35 @@ class SerializerCacheWarmerTest extends TestCase
{
public function testShouldBeRequired()
{
$cacheWarmer = new SerializerCacheWarmer(array(), new \HTMLPurifier());
$cacheWarmer = new SerializerCacheWarmer([], new \HTMLPurifier());
$this->assertFalse($cacheWarmer->isOptional());
}

public function testFailsWhenNotWriteable()
{
$path = sys_get_temp_dir().'/'.uniqid('htmlpurifierbundle_fails');

if (false === @mkdir($path, 0000)) {
$this->markTestSkipped('Tmp dir is not writeable.');
}

$this->expectException('RuntimeException');

$cacheWarmer = new SerializerCacheWarmer([$path], new \HTMLPurifier());
$cacheWarmer->warmUp(null);

@rmdir($path);
}

public function testShouldCreatePaths()
{
if (!is_writable(sys_get_temp_dir())) {
$this->markTestSkipped(sprintf('The system temp directory "%s" is not writeable for the current system user.', sys_get_temp_dir()));
}

$path = sys_get_temp_dir() . '/' . uniqid('htmlpurifierbundle');
$path = sys_get_temp_dir().'/'.uniqid('htmlpurifierbundle');

$cacheWarmer = new SerializerCacheWarmer(array($path), new \HTMLPurifier());
$cacheWarmer = new SerializerCacheWarmer([$path], new \HTMLPurifier());
$cacheWarmer->warmUp(null);

$this->assertTrue(is_dir($path));
Expand Down
42 changes: 32 additions & 10 deletions Tests/DependencyInjection/Compiler/HTMLPurifierPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Exercise\HTMLPurifierBundle\DependencyInjection\Compiler\HTMLPurifierPass;
use Exercise\HTMLPurifierBundle\HTMLPurifiersRegistry;
use Exercise\HTMLPurifierBundle\HTMLPurifiersRegistryInterface;
use Exercise\HTMLPurifierBundle\Tests\ForwardCompatTestTrait;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -14,21 +16,40 @@

class HTMLPurifierPassTest extends TestCase
{
use ForwardCompatTestTrait;

/** @var ContainerBuilder|MockObject */
private $container;

private function doSetUp()
{
$this->container = $this->createPartialMock(ContainerBuilder::class, [
'hasAlias',
'findDefinition',
'findTaggedServiceIds',
'getDefinition',
]);
}

private function doTearDown()
{
$this->container = null;
}

public function testProcessOnlyIfRegistryInterfaceIsDefined()
{
$container = $this->createMock(ContainerBuilder::class);
$container->expects($this->once())
$this->container->expects($this->once())
->method('hasAlias')
->with(HTMLPurifiersRegistryInterface::class)
->willReturn(false)
;
$container->expects($this->never())
$this->container->expects($this->never())
->method('findDefinition')
;

$pass = new HTMLPurifierPass();

$pass->process($container);
$pass->process($this->container);
}

public function testProcess()
Expand All @@ -54,27 +75,28 @@ public function testProcess()

public function testProcessDoNothingIfRegistryIsNotDefined()
{
$container = $this->createMock(ContainerBuilder::class);
$container
$this->container
->expects($this->once())
->method('hasAlias')
->with(HTMLPurifiersRegistryInterface::class)
->willReturn(true)
;
$container
$this->container
->expects($this->once())
->method('findDefinition')
->with(HTMLPurifiersRegistryInterface::class)
->willThrowException($this->createMock(ServiceNotFoundException::class))
;
$container
$this->container
->expects($this->never())
->method('findTaggedServiceIds')
;

$pass = new HTMLPurifierPass();
$pass->process($container);
$pass->process($this->container);
}
}

class DummyPurifier extends \HTMLPurifier {}
class DummyPurifier extends \HTMLPurifier
{
}
Loading