Skip to content

Commit

Permalink
Maintenance PR (nelmio#1032)
Browse files Browse the repository at this point in the history
- Update Travis and the composer.json to bump and use PHP 7.3 & 7.4 only
- Adapt the Symfony kernel used for fixtures and gitignore to avoid leaving a `var` directory tangling
- Apply PHP-CS-Fixer
- Fix PHPUnit deprecations
  - Migrate to phpspec/prophecy-phpunit
  - Fix the usage of some deprecated assertions
- Bump PHPUnit to 8.5.4 minimum and allow PHPUnit 9.0
- Allow Symfony 5 locally in tests
- Bump the covers validator to 1.1
  • Loading branch information
theofidry authored May 15, 2020
1 parent d71f301 commit 2dc7ec1
Show file tree
Hide file tree
Showing 113 changed files with 639 additions and 241 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/composer.lock
/dist/
/fixtures/Bridge/Symfony/Application/cache/
/fixtures/Bridge/Symfony/Application/var/
!/fixtures/Bridge/Symfony/Application/var/.gitkeep
/vendor/
/vendor-bin/*/bin/
/vendor-bin/*/vendor/
Expand Down
2 changes: 1 addition & 1 deletion .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ $finder = Finder::create()
])
->exclude([
__DIR__.'/fixtures/Parser/files/php',
__DIR__.'/Bridge/Symfony/Application/cache',
__DIR__.'/Bridge/Symfony/Application/var',
])
;

Expand Down
12 changes: 5 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ cache:
- "$HOME/.composer/cache/files"

php:
- '7.1'
- '7.2'
- '7.3'
- '7.4'

Expand All @@ -17,15 +15,15 @@ env:
matrix:
fast_finish: true
include:
- php: '7.1'
- php: '7.3'
env: COMPOSER_FLAGS='--prefer-lowest'
- php: '7.2'
- php: '7.4'
env: COVERAGE='true'
- php: '7.2'
- php: '7.4'
env: SYMFONY_VERSION='~3.4.0'
- php: '7.2'
- php: '7.4'
env: SYMFONY_VERSION='~4.4.0'
- php: '7.2'
- php: '7.4'
env: SYMFONY_VERSION='~5.0.0'

before_install:
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
],

"require": {
"php": "^7.1",
"php": "^7.3",
"fzaninotto/faker": "^1.6",
"myclabs/deep-copy": "^1.5.2",
"sebastian/comparator": "^3.0 || ^4.0",
Expand All @@ -31,8 +31,9 @@
"bamarni/composer-bin-plugin": "^1.1.0",
"php-mock/php-mock": "^2.0",
"phpspec/prophecy": "^1.6",
"phpunit/phpunit": "^7.0 || ^8.5",
"symfony/phpunit-bridge": "^3.4.5 || ^4.0.5 || ^5.0",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^8.5.4 || ^9.0",
"symfony/phpunit-bridge": "^5.0",
"symfony/var-dumper": "^3.4 || ^4.0 || ^5.0"
},
"conflict": {
Expand Down
5 changes: 5 additions & 0 deletions fixtures/Bridge/Symfony/Application/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,9 @@ public function setConfigurationResource(string $resource)
{
$this->config = $resource;
}

public function getProjectDir()
{
return __DIR__;
}
}
2 changes: 1 addition & 1 deletion fixtures/Definition/Object/ImmutableObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

namespace Nelmio\Alice\Definition\Object;

use Nelmio\Alice\ObjectInterface;
use function Nelmio\Alice\deep_clone;
use Nelmio\Alice\ObjectInterface;

class ImmutableObject implements ObjectInterface
{
Expand Down
11 changes: 11 additions & 0 deletions fixtures/Entity/DummyWithPrivatePropertyChild.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

/*
* This file is part of the Alice package.
*
* (c) Nelmio <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Nelmio\Alice\Entity;

class DummyWithPrivatePropertyChild extends DummyWithPrivateProperty
Expand Down
4 changes: 3 additions & 1 deletion fixtures/Symfony/KernelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

namespace Nelmio\Alice\Symfony;

use function bin2hex;
use Nelmio\Alice\Bridge\Symfony\Application\AppKernel;
use function random_bytes;
use Symfony\Component\HttpKernel\KernelInterface;

class KernelFactory
Expand All @@ -28,7 +30,7 @@ public static function createKernel(
): KernelInterface {
if (null !== $config) {
if (false === array_key_exists($config, static::$environments)) {
static::$environments[$config] = uniqid();
static::$environments[$config] = bin2hex(random_bytes(8));
}

$environment = static::$environments[$config];
Expand Down
12 changes: 8 additions & 4 deletions phpunit_symfony.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
enforceTimeLimit="true"
>

<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="0" />
</php>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>

<testsuites>
<testsuite name="Independent tests">
<directory>tests/Bridge/Symfony</directory>
Expand All @@ -29,8 +37,4 @@
<directory>src/Bridge/Symfony</directory>
</whitelist>
</filter>

<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="0" />
</php>
</phpunit>
3 changes: 2 additions & 1 deletion src/Bridge/Symfony/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ final class Configuration implements ConfigurationInterface
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('nelmio_alice');

if (method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->getRootNode();
} else {
Expand All @@ -41,7 +42,7 @@ public function getConfigTreeBuilder()
->defaultValue('en_US')
->info('Default locale for the Faker Generator')
->validate()
->always($this->createStringValidatorClosure('nelmio_alice.locale'))
->always($this->createStringValidatorClosure())
->end()
->end()
->scalarNode('seed')
Expand Down
2 changes: 1 addition & 1 deletion src/Definition/Value/ArrayValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

namespace Nelmio\Alice\Definition\Value;

use Nelmio\Alice\Definition\ValueInterface;
use function Nelmio\Alice\deep_clone;
use Nelmio\Alice\Definition\ValueInterface;

final class ArrayValue implements ValueInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Definition/Value/DynamicArrayValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

namespace Nelmio\Alice\Definition\Value;

use function Nelmio\Alice\deep_clone;
use Nelmio\Alice\Definition\ValueInterface;
use Nelmio\Alice\Throwable\Error\TypeErrorFactory;
use function Nelmio\Alice\deep_clone;

/**
* Value object representing an array like "10x @user0". '10' is called "quantifier" and "@user0" is called "element".
Expand Down
2 changes: 1 addition & 1 deletion src/Definition/Value/FunctionCallValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

namespace Nelmio\Alice\Definition\Value;

use Nelmio\Alice\Definition\ValueInterface;
use function Nelmio\Alice\deep_clone;
use Nelmio\Alice\Definition\ValueInterface;

/**
* Value object representing '<name()>'.
Expand Down
2 changes: 1 addition & 1 deletion src/Definition/Value/ListValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

namespace Nelmio\Alice\Definition\Value;

use Nelmio\Alice\Definition\ValueInterface;
use function Nelmio\Alice\deep_clone;
use Nelmio\Alice\Definition\ValueInterface;

/**
* Value representing a list of values which will be chained. For example '<foo()> <{bar}>' will be composed of a
Expand Down
2 changes: 1 addition & 1 deletion src/Definition/Value/ParameterValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

namespace Nelmio\Alice\Definition\Value;

use function Nelmio\Alice\deep_clone;
use Nelmio\Alice\Definition\ValueInterface;
use Nelmio\Alice\Throwable\Error\TypeErrorFactory;
use function Nelmio\Alice\deep_clone;

/**
* Value object representing '<{param}>'.
Expand Down
2 changes: 1 addition & 1 deletion src/Definition/Value/UniqueValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

namespace Nelmio\Alice\Definition\Value;

use function Nelmio\Alice\deep_clone;
use Nelmio\Alice\Definition\ValueInterface;
use Nelmio\Alice\Throwable\Exception\InvalidArgumentExceptionFactory;
use function Nelmio\Alice\deep_clone;

final class UniqueValue implements ValueInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
use Nelmio\Alice\FixtureBuilder\Denormalizer\FlagParserInterface;
use Nelmio\Alice\FixtureInterface;
use Nelmio\Alice\IsAServiceTrait;
use Nelmio\Alice\Throwable\Exception\LogicExceptionFactory;
use Nelmio\Alice\Throwable\Exception\FixtureBuilder\Denormalizer\FlagParser\FlagParserExceptionFactory;
use Nelmio\Alice\Throwable\Exception\LogicExceptionFactory;

final class ReferenceRangeNameDenormalizer implements ChainableFixtureDenormalizerInterface, FlagParserAwareInterface
{
Expand Down Expand Up @@ -89,7 +89,7 @@ public function denormalize(

$referencedName = $matches['name'];
$allFlag = ($matches['flag'] ?? null) === '*';
$idFlags = $this->flagParser->parse($fixtureId);
$idFlags = $this->flagParser->parse($fixtureId);

$fixtureIds = $this->buildReferencedValues($builtFixtures, $referencedName, $allFlag);

Expand Down
2 changes: 1 addition & 1 deletion src/Parser/IncludeProcessor/DefaultIncludeProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

namespace Nelmio\Alice\Parser\IncludeProcessor;

use function array_reverse;
use Nelmio\Alice\FileLocatorInterface;
use Nelmio\Alice\IsAServiceTrait;
use Nelmio\Alice\Parser\IncludeProcessorInterface;
use Nelmio\Alice\ParserInterface;
use Nelmio\Alice\Throwable\Error\TypeErrorFactory;
use Nelmio\Alice\Throwable\Exception\InvalidArgumentExceptionFactory;
use function array_reverse;

final class DefaultIncludeProcessor implements IncludeProcessorInterface
{
Expand Down
4 changes: 2 additions & 2 deletions src/Parser/IncludeProcessor/IncludeDataMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public function mergeInclude(array $data, array $includeData): array
foreach ($data as $class => $fixtures) {
// $class is either a FQCN or 'parameters'
$includeData[$class] = (
array_key_exists($class, $includeData)
array_key_exists($class, $includeData)
&& is_array($includeData[$class])
&& is_array($fixtures)
)
)
? array_merge($includeData[$class], $fixtures)
: $fixtures
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

use Nelmio\Alice\Symfony\KernelFactory;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\Config\Definition\Processor;

/**
* @covers \Nelmio\Alice\Bridge\Symfony\DependencyInjection\Configuration
Expand Down Expand Up @@ -117,7 +117,7 @@ public function testFunctionsBlacklistMustAnArray()
$processor = new Processor();

$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessageRegExp('/^Invalid type for path "nelmio_alice.functions_blacklist"\. Expected array, but got string/');
$this->expectExceptionMessageMatches('/^Invalid type for path "nelmio_alice.functions_blacklist"\. Expected array, but got string/');

$processor->processConfiguration(
$configuration,
Expand Down Expand Up @@ -171,7 +171,7 @@ public function testLoadingLimitMustBeAnInteger()
$processor = new Processor();

$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessageRegExp('/^Invalid type for path "nelmio_alice.loading_limit"\. Expected int, but got boolean\./');
$this->expectExceptionMessageMatches('/^Invalid type for path "nelmio_alice.loading_limit"\. Expected int, but got boolean\./');

$processor->processConfiguration(
$configuration,
Expand Down Expand Up @@ -207,7 +207,7 @@ public function testMaxUniqueValuesRetryMustBeAnInteger()
$processor = new Processor();

$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessageRegExp('/^Invalid type for path "nelmio_alice.max_unique_values_retry"\. Expected int, but got boolean\./');
$this->expectExceptionMessageMatches('/^Invalid type for path "nelmio_alice.max_unique_values_retry"\. Expected int, but got boolean\./');

$processor->processConfiguration(
$configuration,
Expand Down
8 changes: 0 additions & 8 deletions tests/Definition/Fixture/FixtureIdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@
*/

declare(strict_types=1);
/*
* This file is part of the Alice package.
*
* (c) Nelmio <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Nelmio\Alice\Definition\Fixture;

Expand Down
3 changes: 3 additions & 0 deletions tests/Definition/Fixture/SimpleFixtureWithFlagsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
use Nelmio\Alice\Definition\SpecificationBagFactory;
use Nelmio\Alice\FixtureInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;

/**
* @covers \Nelmio\Alice\Definition\Fixture\SimpleFixtureWithFlags
*/
class SimpleFixtureWithFlagsTest extends TestCase
{
use ProphecyTrait;

public function testIsAFixtureWithFlags()
{
$this->assertTrue(is_a(SimpleFixtureWithFlags::class, FixtureWithFlagsInterface::class, true));
Expand Down
3 changes: 3 additions & 0 deletions tests/Definition/Fixture/TemplatingFixtureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@
use Nelmio\Alice\Definition\SpecificationBagFactory;
use Nelmio\Alice\FixtureInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;

/**
* @covers \Nelmio\Alice\Definition\Fixture\TemplatingFixture
*/
class TemplatingFixtureTest extends TestCase
{
use ProphecyTrait;

public function testIsAFixture()
{
$this->assertTrue(is_a(TemplatingFixture::class, FixtureInterface::class, true));
Expand Down
3 changes: 3 additions & 0 deletions tests/Definition/MethodCall/ConfiguratorMethodCallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
use Nelmio\Alice\Definition\ServiceReference\MutableReference;
use Nelmio\Alice\Entity\StdClassFactory;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;

/**
* @covers \Nelmio\Alice\Definition\MethodCall\ConfiguratorMethodCall
*/
class ConfiguratorMethodCallTest extends TestCase
{
use ProphecyTrait;

public function testIsAMethodCall()
{
$this->assertTrue(is_a(ConfiguratorMethodCall::class, MethodCallInterface::class, true));
Expand Down
3 changes: 3 additions & 0 deletions tests/Definition/MethodCall/OptionalMethodCallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
use Nelmio\Alice\Definition\ServiceReference\MutableReference;
use Nelmio\Alice\Entity\StdClassFactory;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;

/**
* @covers \Nelmio\Alice\Definition\MethodCall\OptionalMethodCall
*/
class OptionalMethodCallTest extends TestCase
{
use ProphecyTrait;

public function testIsAMethodCall()
{
$this->assertTrue(is_a(OptionalMethodCall::class, MethodCallInterface::class, true));
Expand Down
Loading

0 comments on commit 2dc7ec1

Please sign in to comment.