Skip to content

Commit

Permalink
Add CompilerPass to check if framework_bundle.property_access is enab…
Browse files Browse the repository at this point in the history
…led (#1124)
  • Loading branch information
xElysioN authored Nov 14, 2022
1 parent 0297bae commit e7d3275
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# This file is part of the Alice package.
#
# (c) Nelmio <hello@nelm.io>
#
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this source code.
#

framework:
annotations:
enabled: false
secret: NelmioAliceBundleSecret
serializer:
enabled: true
router:
resource: ~
strict_requirements: '%kernel.debug%'
utf8: true
test: ~
session:
enabled: false
property_access: false
5 changes: 1 addition & 4 deletions fixtures/Definition/Flag/MutableFlag.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@ class MutableFlag implements FlagInterface
*/
private $stringValue;

/**
* @var
*/
private $object;

public function __construct(string $stringValue, $object)
{
$this->stringValue = $stringValue;
$this->object = $object;
}

public function __toString(): string
{
return $this->stringValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* This file is part of the Alice package.
*
* (c) Nelmio <hello@nelm.io>
*
* 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\Bridge\Symfony\DependencyInjection\Compiler;

use LogicException;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class CheckBundleDependenciesPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
if (!$container->has('property_accessor')) {
throw new LogicException('NelmioAliceBundle requires framework_bundle.property_access to be enabled.');
}
}
}
2 changes: 2 additions & 0 deletions src/Bridge/Symfony/NelmioAliceBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Nelmio\Alice\Bridge\Symfony;

use Nelmio\Alice\Bridge\Symfony\DependencyInjection\Compiler\CheckBundleDependenciesPass;
use Nelmio\Alice\Bridge\Symfony\DependencyInjection\Compiler\RegisterFakerProvidersPass;
use Nelmio\Alice\Bridge\Symfony\DependencyInjection\Compiler\RegisterTagServicesPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -24,6 +25,7 @@ public function build(ContainerBuilder $container): void
{
parent::build($container);

$container->addCompilerPass(new CheckBundleDependenciesPass());
$container->addCompilerPass(new RegisterFakerProvidersPass());
$container->addCompilerPass(
new RegisterTagServicesPass(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
* This file is part of the Alice package.
*
* (c) Nelmio <hello@nelm.io>
*
* 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\Bridge\Symfony\DependencyInjection;

use LogicException;
use Nelmio\Alice\Symfony\KernelFactory;
use PHPUnit\Framework\TestCase;

/**
* @coversNothing
*
* @group integration
*/
class CheckBundleDependenciesPassTest extends TestCase
{
public function testPropertyAccessDisabled(): void
{
static::expectException(LogicException::class);
static::expectExceptionMessage('NelmioAliceBundle requires framework_bundle.property_access to be enabled.');

$kernel = KernelFactory::createKernel(
__DIR__.'/../../../../fixtures/Bridge/Symfony/Application/config_property_access_disabled.yml',
);
$kernel->boot();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ public function testIfParsedValueIsDynamicArrayThenUniqueFlagAppliesToItsElement
/** @var DynamicArrayValue $result */
static::assertEquals(10, $result->getQuantifier());
static::assertInstanceOf(UniqueValue::class, $result->getElement());
// @phpstan-ignore-next-line
static::assertStringStartsWith('Dummy#', $result->getElement()->getId());
static::assertEquals('parsed_value', $result->getElement()->getValue());
}
Expand Down

0 comments on commit e7d3275

Please sign in to comment.