Skip to content

Commit

Permalink
Allow Symfony 6 and PHP 8
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Dec 17, 2021
1 parent ec3efc2 commit f1ac25b
Show file tree
Hide file tree
Showing 23 changed files with 124 additions and 78 deletions.
6 changes: 3 additions & 3 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ cache:

init:
- SET PATH=C:\tools\php;%PATH%
- SET COMPOSER_BINARY=C:\tools\composer.phar

install:
- ps: Set-Service wuauserv -StartupType Manual
Expand All @@ -24,9 +25,8 @@ install:
- echo memory_limit=3G >> php.ini
- IF NOT EXIST C:\tools\composer.phar (cd C:\tools && appveyor DownloadFile https://getcomposer.org/composer.phar)
- cd %APPVEYOR_BUILD_FOLDER%
- php C:\tools\composer.phar global show hirak/prestissimo --quiet || php C:\tools\composer.phar global require hirak/prestissimo --no-progress
- php C:\tools\composer.phar update --no-ansi --no-interaction --no-progress --no-suggest --optimize-autoloader --prefer-stable
- php C:\tools\composer.phar update --no-interaction --no-progress --optimize-autoloader --prefer-stable

test_script:
- cd %APPVEYOR_BUILD_FOLDER%
- php vendor\phpunit\phpunit\phpunit
- php vendor\bin\simple-phpunit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/vendor/
/.php_cs.cache
.phpunit.result.cache
/composer.lock
/phpunit.xml
13 changes: 8 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ language: php

matrix:
include:
- php: 7.0
- php: 7.0
env: COMPOSER_FLAGS='--prefer-lowest'
- php: 7.1
- php: 7.1
env: COMPOSER_FLAGS='--prefer-lowest'
Expand All @@ -17,9 +14,15 @@ matrix:
- php: 7.3
env: COMPOSER_FLAGS='--prefer-lowest'
- php: 7.4
env: ANALYSIS=1
- php: 7.4
env: COMPOSER_FLAGS='--prefer-lowest'
- php: 8.0
- php: 8.0
env: COMPOSER_FLAGS='--prefer-lowest'
- php: 8.1
env: ANALYSIS=1
- php: 8.1
env: COMPOSER_FLAGS='--prefer-lowest'
- php: nightly
allow_failures:
- php: nightly
Expand All @@ -34,7 +37,7 @@ install:
- if [ $ANALYSIS == 1 ]; then travis_retry composer update --working-dir=./dev-tools --no-suggest; fi

script:
- vendor/bin/phpunit --verbose --coverage-clover=coverage.clover
- vendor/bin/simple-phpunit --verbose --coverage-clover=coverage.clover
- if [ $ANALYSIS == 1 ]; then ./dev-tools/analyse.sh || travis_terminate 1; fi

after_script:
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}
],
"require": {
"php": ">=7.0",
"php": ">=7.1",
"ext-mbstring": "*"
},
"conflict": {
Expand All @@ -35,12 +35,12 @@
"mikey179/vfsstream": "~1.6.8",
"mockery/mockery": "^1.3",
"nette/di": "~2.4",
"phpunit/phpunit": "^5.7.27",
"pimple/pimple": "~1.1",
"plumphp/plum": "~0.1",
"symfony/config": "^3.4 || ^4.3 || ^5.0",
"symfony/dependency-injection": "^3.4 || ^4.3 || ^5.0",
"symfony/http-kernel": "^3.4 || ^4.3 || ^5.0",
"symfony/config": "^3.4 || ^4.3 || ^5.0 || ^6.0",
"symfony/dependency-injection": "^3.4 || ^4.3 || ^5.0 || ^6.0",
"symfony/http-kernel": "^3.4 || ^4.3 || ^5.0 || ^6.0",
"symfony/phpunit-bridge": "^5.4 || ^6.0",
"twig/twig": "^2.12.1 || ~3.0",
"zendframework/zend-modulemanager": "~2.2",
"zendframework/zend-servicemanager": "~2.2",
Expand Down
14 changes: 10 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="vendor/autoload.php" colors="true">
<php>
<!-- Baseline Deprecations https://symfony.com/doc/current/components/phpunit_bridge.html#baseline-deprecations -->
<env name="SYMFONY_DEPRECATIONS_HELPER" value="baselineFile=./tests/allowed.json&amp;max[direct]=0" />
</php>

<testsuites>
<testsuite name="cocur/slugify Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<coverage>
<include>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</include>
</coverage>

<listeners>
<listener class="\Mockery\Adapter\Phpunit\TestListener" />
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
</phpunit>
2 changes: 1 addition & 1 deletion src/Bridge/League/SlugifyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SlugifyServiceProvider extends AbstractServiceProvider
SlugifyInterface::class,
];

public function register()
public function register(): void
{
$this->container->share(SlugifyInterface::class, function () {
$options = [];
Expand Down
4 changes: 2 additions & 2 deletions src/Bridge/Nette/SlugifyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
class SlugifyExtension extends CompilerExtension
{
public function loadConfiguration()
public function loadConfiguration(): void
{
$builder = $this->getContainerBuilder();

Expand All @@ -28,7 +28,7 @@ public function loadConfiguration()
->setAutowired(false);
}

public function beforeCompile()
public function beforeCompile(): void
{
$builder = $this->getContainerBuilder();

Expand Down
3 changes: 2 additions & 1 deletion src/Bridge/Symfony/CocurSlugifyBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Cocur\Slugify\Bridge\Symfony;

use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\HttpKernel\Bundle\Bundle;

/**
Expand All @@ -24,7 +25,7 @@
*/
class CocurSlugifyBundle extends Bundle
{
public function getContainerExtension()
public function getContainerExtension(): ExtensionInterface
{
return new CocurSlugifyExtension();
}
Expand Down
11 changes: 7 additions & 4 deletions src/Bridge/Symfony/CocurSlugifyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

namespace Cocur\Slugify\Bridge\Symfony;

use Cocur\Slugify\Bridge\Twig\SlugifyExtension;
use Cocur\Slugify\Slugify;
use Cocur\Slugify\SlugifyInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
Expand All @@ -33,7 +36,7 @@ class CocurSlugifyExtension extends Extension
* @param mixed[] $configs
* @param ContainerBuilder $container
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
Expand All @@ -45,18 +48,18 @@ public function load(array $configs, ContainerBuilder $container)
// Extract slugify arguments from config
$slugifyArguments = array_intersect_key($config, array_flip(['lowercase', 'trim', 'strip_tags', 'separator', 'regexp', 'rulesets']));

$container->setDefinition('cocur_slugify', new Definition('Cocur\Slugify\Slugify', [$slugifyArguments]));
$container->setDefinition('cocur_slugify', new Definition(Slugify::class, [$slugifyArguments]));
$container
->setDefinition(
'cocur_slugify.twig.slugify',
new Definition(
'Cocur\Slugify\Bridge\Twig\SlugifyExtension',
SlugifyExtension::class,
[new Reference('cocur_slugify')]
)
)
->addTag('twig.extension')
->setPublic(false);
$container->setAlias('slugify', 'cocur_slugify');
$container->setAlias('Cocur\Slugify\SlugifyInterface', 'cocur_slugify');
$container->setAlias(SlugifyInterface::class, 'cocur_slugify');
}
}
2 changes: 1 addition & 1 deletion src/Bridge/Symfony/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Configuration implements ConfigurationInterface
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('cocur_slugify');

Expand Down
2 changes: 1 addition & 1 deletion tests/Bridge/Laravel/SlugifyProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SlugifyProviderTest extends MockeryTestCase
/** @var SlugifyServiceProvider */
private $provider;

protected function setUp()
protected function setUp(): void
{
$this->app = new Application();
$this->provider = new SlugifyServiceProvider($this->app);
Expand Down
2 changes: 1 addition & 1 deletion tests/Bridge/Latte/SlugifyHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
class SlugifyHelperTest extends MockeryTestCase
{
protected function setUp()
protected function setUp(): void
{
$this->slugify = m::mock('Cocur\Slugify\SlugifyInterface');
$this->helper = new SlugifyHelper($this->slugify);
Expand Down
13 changes: 11 additions & 2 deletions tests/Bridge/League/SlugifyServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function testProvidesSlugify()
$slugify = $container->get(SlugifyInterface::class);

$this->assertInstanceOf(SlugifyInterface::class, $slugify);
$this->assertAttributeInstanceOf(DefaultRuleProvider::class, 'provider', $slugify);
$this->assertInstanceOf(DefaultRuleProvider::class, $this->getProperty($slugify, 'provider'));
}

public function testProvidesSlugifyAsSharedService()
Expand Down Expand Up @@ -65,7 +65,7 @@ public function testProvidesSlugifyUsingSharedProvider()

$slugify = $container->get(SlugifyInterface::class);

$this->assertAttributeSame($ruleProvider, 'provider', $slugify);
$this->assertSame($ruleProvider, $this->getProperty($slugify, 'provider'));
}

/**
Expand All @@ -83,4 +83,13 @@ private function getRuleProviderMock()

return $ruleProvider;
}

private function getProperty(SlugifyInterface $slugify, string $name)
{
$reflection = new \ReflectionClass($slugify);
$prop = $reflection->getProperty($name);
$prop->setAccessible(true);

return $prop->getValue($slugify);
}
}
2 changes: 1 addition & 1 deletion tests/Bridge/Nette/SlugifyExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
class SlugifyExtensionTest extends MockeryTestCase
{
protected function setUp()
protected function setUp(): void
{
$this->extension = new SlugifyExtension();
}
Expand Down
61 changes: 32 additions & 29 deletions tests/Bridge/Symfony/CocurSlugifyExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
namespace Cocur\Slugify\Tests\Bridge\Symfony;

use Cocur\Slugify\Bridge\Symfony\CocurSlugifyExtension;
use Mockery as m;
use Mockery\Adapter\Phpunit\MockeryTestCase;
use Cocur\Slugify\SlugifyInterface;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

/**
* CocurSlugifyExtensionTest
Expand All @@ -26,9 +28,9 @@
* @license http://www.opensource.org/licenses/MIT The MIT License
* @group unit
*/
class CocurSlugifyExtensionTest extends MockeryTestCase
class CocurSlugifyExtensionTest extends TestCase
{
protected function setUp()
protected function setUp(): void
{
$this->extension = new CocurSlugifyExtension();
}
Expand All @@ -38,36 +40,37 @@ protected function setUp()
*/
public function testLoad()
{
$twigDefinition = m::mock('Symfony\Component\DependencyInjection\Definition');
$twigDefinition = $this->createMock(Definition::class);
$twigDefinition
->shouldReceive('addTag')
->with('twig.extension')
->once()
->andReturn($twigDefinition);
->expects($this->once())
->method('addTag')
->with($this->equalTo('twig.extension'))
->willReturn($twigDefinition);
$twigDefinition
->shouldReceive('setPublic')
->with(false)
->once();
->expects($this->once())
->method('setPublic')
->with($this->equalTo(false))
->willReturn($twigDefinition);

$container = m::mock('Symfony\Component\DependencyInjection\ContainerBuilder');
$container = $this->createMock(ContainerBuilder::class);
$container
->shouldReceive('setDefinition')
->with('cocur_slugify', m::type('Symfony\Component\DependencyInjection\Definition'))
->once();
->expects($this->exactly(2))
->method('setDefinition')
->withConsecutive(
[$this->equalTo('cocur_slugify'), $this->isInstanceOf(Definition::class)],
[$this->equalTo('cocur_slugify.twig.slugify', $this->isInstanceOf(Definition::class))]
)
->willReturnOnConsecutiveCalls(
$this->createMock(Definition::class),
$twigDefinition
);
$container
->shouldReceive('setDefinition')
->with('cocur_slugify.twig.slugify', m::type('Symfony\Component\DependencyInjection\Definition'))
->once()
->andReturn($twigDefinition);
$container
->shouldReceive('setAlias')
->with('slugify', 'cocur_slugify')
->once();
$container
->shouldReceive('setAlias')
->with('Cocur\Slugify\SlugifyInterface', 'cocur_slugify')
->once();

->expects($this->exactly(2))
->method('setAlias')
->withConsecutive(
[$this->equalTo('slugify'), $this->equalTo('cocur_slugify')],
[$this->equalTo(SlugifyInterface::class), $this->equalTo('cocur_slugify')]
);
$this->extension->load([], $container);
}
}
Loading

0 comments on commit f1ac25b

Please sign in to comment.