Skip to content

Commit

Permalink
Add Symfony 6.0 support (#1099)
Browse files Browse the repository at this point in the history
  • Loading branch information
javer committed Dec 10, 2021
1 parent 5a5bf05 commit e864669
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 41 deletions.
20 changes: 11 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,25 @@ jobs:
fail-fast: false
matrix:
php:
- '7.4'
- '8.0'
- '8.1'
symfony-versions: [false]
include:
- description: 'Symfony 4.4'
php: '7.4'
symfony-versions: 4.4.*
- description: 'Symfony 5.3'
php: '7.4'
symfony-versions: 5.3.*
- description: 'Symfony 4.4'
php: '8.0'
symfony-versions: 4.4.*
- description: 'Symfony 5.3'
- description: 'Symfony 5.4'
php: '8.0'
symfony-versions: 5.4.*
- description: 'Symfony 6.0'
php: '8.0'
symfony-versions: 5.3.*
symfony-versions: 6.0.*
- description: 'Symfony 5.4'
php: '8.1'
symfony-versions: 5.4.*
- description: 'Symfony 6.0'
php: '8.1'
symfony-versions: 6.0.*

name: PHP ${{ matrix.php }} ${{ matrix.description }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'

- name: Install dependencies
run: composer install --no-progress --no-interaction --prefer-dist
Expand Down
14 changes: 9 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,24 @@
],

"require": {
"php": "^7.4 || ^8.0",
"php": "^8.0",
"fakerphp/faker": "^1.10",
"myclabs/deep-copy": "^1.10",
"sebastian/comparator": "^3.0 || ^4.0",
"symfony/property-access": "^4.4 || ^5.2",
"symfony/yaml": "^4.4 || ^5.2"
"symfony/property-access": "^4.4 || ^5.4 || ^6.0",
"symfony/yaml": "^4.4 || ^5.4 || ^6.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.4.1",
"phpspec/prophecy": "^1.6",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.3",
"symfony/phpunit-bridge": "^5.1.3",
"symfony/var-dumper": "^4.4 || ^5.2"
"symfony/config": "^4.4 || ^5.4 || ^6.0",
"symfony/dependency-injection": "^4.4 || ^5.4 || ^6.0",
"symfony/finder": "^4.4 || ^5.4 || ^6.0",
"symfony/http-kernel": "^4.4 || ^5.4 || ^6.0",
"symfony/phpunit-bridge": "^5.4 || ^6.0",
"symfony/var-dumper": "^4.4 || ^5.4 || ^6.0"
},
"conflict": {
"symfony/framework-bundle": "<4.4 || >=5.0.0,<5.2.0"
Expand Down
12 changes: 8 additions & 4 deletions fixtures/Bridge/Symfony/Application/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct($environment, $debug)
parent::__construct($environment, $debug);
}

public function registerBundles()
public function registerBundles(): array
{
return [
new FrameworkBundle(),
Expand All @@ -52,11 +52,15 @@ public function build(ContainerBuilder $container): void
public function process(ContainerBuilder $container): void
{
foreach ($container->getDefinitions() as $id => $definition) {
$definition->setPublic(true);
if (str_starts_with($id, 'nelmio_alice.')) {
$definition->setPublic(true);
}
}

foreach ($container->getAliases() as $id => $definition) {
$definition->setPublic(true);
if (str_starts_with($id, 'nelmio_alice.')) {
$definition->setPublic(true);
}
}
}
}, PassConfig::TYPE_OPTIMIZE);
Expand All @@ -67,7 +71,7 @@ public function setConfigurationResource(string $resource): void
$this->config = $resource;
}

public function getProjectDir()
public function getProjectDir(): string
{
return __DIR__;
}
Expand Down
6 changes: 3 additions & 3 deletions fixtures/Symfony/PropertyAccess/FakePropertyAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ public function setValue(&$objectOrArray, $propertyPath, $value): void
$this->__call(__METHOD__, func_get_args());
}

public function getValue($objectOrArray, $propertyPath): void
public function getValue($objectOrArray, $propertyPath): mixed
{
$this->__call(__METHOD__, func_get_args());
}

public function isWritable($objectOrArray, $propertyPath): void
public function isWritable($objectOrArray, $propertyPath): bool
{
$this->__call(__METHOD__, func_get_args());
}

public function isReadable($objectOrArray, $propertyPath): void
public function isReadable($objectOrArray, $propertyPath): bool
{
$this->__call(__METHOD__, func_get_args());
}
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
executionOrder="random">

<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="0"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0"/>
</php>

<listeners>
Expand Down
2 changes: 1 addition & 1 deletion phpunit_symfony.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
>

<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="0" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0" />
</php>

<listeners>
Expand Down
12 changes: 3 additions & 9 deletions src/Bridge/Symfony/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,12 @@
*/
final class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('nelmio_alice');

if (method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->getRootNode();
} else {
// BC layer for symfony/config 4.1 and older
$rootNode = $treeBuilder->root('nelmio_alice');
}

$rootNode
$treeBuilder
->getRootNode()
->children()
->scalarNode('locale')
->defaultValue('en_US')
Expand Down
6 changes: 3 additions & 3 deletions src/PropertyAccess/ReflectionPropertyAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function ($object) use ($propertyPath, $value): void {
}
}

public function getValue($objectOrArray, $propertyPath)
public function getValue($objectOrArray, $propertyPath): mixed
{
try {
return $this->decoratedPropertyAccessor->getValue($objectOrArray, $propertyPath);
Expand Down Expand Up @@ -94,12 +94,12 @@ function ($object) use ($propertyPath) {
}
}

public function isWritable($objectOrArray, $propertyPath)
public function isWritable($objectOrArray, $propertyPath): bool
{
return $this->decoratedPropertyAccessor->isWritable($objectOrArray, $propertyPath) || $this->propertyExists($objectOrArray, $propertyPath);
}

public function isReadable($objectOrArray, $propertyPath)
public function isReadable($objectOrArray, $propertyPath): bool
{
return $this->decoratedPropertyAccessor->isReadable($objectOrArray, $propertyPath) || $this->propertyExists($objectOrArray, $propertyPath);
}
Expand Down
6 changes: 3 additions & 3 deletions src/PropertyAccess/StdPropertyAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function setValue(&$objectOrArray, $propertyPath, $value): void
$this->decoratedPropertyAccessor->setValue($objectOrArray, $propertyPath, $value);
}

public function getValue($objectOrArray, $propertyPath)
public function getValue($objectOrArray, $propertyPath): mixed
{
if (false === $objectOrArray instanceof stdClass) {
return $this->decoratedPropertyAccessor->getValue($objectOrArray, $propertyPath);
Expand All @@ -56,15 +56,15 @@ public function getValue($objectOrArray, $propertyPath)
return $objectOrArray->$propertyPath;
}

public function isWritable($objectOrArray, $propertyPath)
public function isWritable($objectOrArray, $propertyPath): bool
{
return ($objectOrArray instanceof stdClass)
? true
: $this->decoratedPropertyAccessor->isWritable($objectOrArray, $propertyPath)
;
}

public function isReadable($objectOrArray, $propertyPath)
public function isReadable($objectOrArray, $propertyPath): bool
{
return ($objectOrArray instanceof stdClass)
? isset($objectOrArray->$propertyPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use ReflectionClass;
use ReflectionMethod;
use stdClass;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
use TypeError;

/**
* @covers \Nelmio\Alice\Generator\Resolver\Value\Chainable\FixturePropertyReferenceResolver
Expand Down Expand Up @@ -225,8 +227,14 @@ public function testThrowsAnExceptionIfReferenceResolvedIsNotAnObject(): void

$resolver = new FixturePropertyReferenceResolver(PropertyAccess::createPropertyAccessor(), $valueResolver);

$this->expectException(UnresolvableValueException::class);
$this->expectExceptionMessage('Could not resolve value "dummy->publicProperty": PropertyAccessor requires a graph of objects or arrays to operate on, but it found type "string" while trying to traverse path "publicProperty" at property "publicProperty".');
if ((new ReflectionMethod(PropertyAccessorInterface::class, 'getValue'))->getParameters()[0]->getType() !== null) {
// Since symfony/property-access 6.0
$this->expectException(TypeError::class);
$this->expectExceptionMessageMatches(sprintf('/^%s/', preg_quote('Symfony\Component\PropertyAccess\PropertyAccessor::getValue(): Argument #1 ($objectOrArray) must be of type object|array, string given', '/')));
} else {
$this->expectException(UnresolvableValueException::class);
$this->expectExceptionMessage('Could not resolve value "dummy->publicProperty": PropertyAccessor requires a graph of objects or arrays to operate on, but it found type "string" while trying to traverse path "publicProperty" at property "publicProperty".');
}

$resolver->resolve($value, new FakeFixture(), $set, [], new GenerationContext());
}
Expand Down

0 comments on commit e864669

Please sign in to comment.