-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into check-identity-of-parameter
- Loading branch information
Showing
31 changed files
with
609 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/Tests export-ignore | ||
/phpunit.xml.dist export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
tests: | ||
name: PHPUnit PHP ${{ matrix.php }} ${{ matrix.dependency }} (Symfony ${{ matrix.symfony }}) | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
php: | ||
- '8.1' | ||
- '8.2' | ||
- '8.3' | ||
dependency: | ||
- '' | ||
symfony: | ||
- '5.4.*' | ||
- '6.3.*' | ||
- '6.4.*' | ||
- '7.0.*' | ||
include: | ||
- php: '8.1' | ||
symfony: '5.4.*' | ||
dependency: 'lowest' | ||
exclude: | ||
- php: '8.1' | ||
symfony: '7.0.*' | ||
fail-fast: false | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
extensions: pcov | ||
tools: flex | ||
|
||
- name: Get Composer Cache Directory | ||
id: composer-cache | ||
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | ||
|
||
- name: Cache dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: ${{ steps.composer-cache.outputs.dir }} | ||
key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} | ||
restore-keys: ${{ matrix.php }}-composer- | ||
|
||
- name: Update project dependencies | ||
if: matrix.dependency == '' | ||
run: composer update --no-progress --ansi --prefer-stable | ||
env: | ||
SYMFONY_REQUIRE: ${{ matrix.symfony }} | ||
|
||
- name: Update project dependencies lowest | ||
if: matrix.dependency == 'lowest' | ||
run: composer update --no-progress --ansi --prefer-stable --prefer-lowest | ||
env: | ||
SYMFONY_REQUIRE: ${{ matrix.symfony }} | ||
|
||
- name: Validate composer | ||
run: composer validate --strict --no-check-lock | ||
|
||
- name: Run tests | ||
run: vendor/bin/phpunit |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
<?php | ||
|
||
namespace Matthias\SymfonyDependencyInjectionTest\PhpUnit; | ||
|
||
use PHPUnit\Framework\Constraint\Constraint; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
final class DefinitionDecoratesConstraint extends Constraint | ||
{ | ||
private const INVALID_BEHAVIORS = [ | ||
ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE => 'RUNTIME_EXCEPTION_ON_INVALID_REFERENCE', | ||
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE => 'EXCEPTION_ON_INVALID_REFERENCE', | ||
ContainerInterface::NULL_ON_INVALID_REFERENCE => 'NULL_ON_INVALID_REFERENCE', | ||
ContainerInterface::IGNORE_ON_INVALID_REFERENCE => 'IGNORE_ON_INVALID_REFERENCE', | ||
ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE => 'IGNORE_ON_UNINITIALIZED_REFERENCE', | ||
]; | ||
|
||
private string $serviceId; | ||
private string $decoratedServiceId; | ||
private ?string $renamedId; | ||
private int $priority; | ||
private ?int $invalidBehavior; | ||
|
||
public function __construct(string $serviceId, string $decoratedServiceId, ?string $renamedId = null, int $priority = 0, ?int $invalidBehavior = null) | ||
{ | ||
$this->serviceId = $serviceId; | ||
$this->decoratedServiceId = $decoratedServiceId; | ||
$this->renamedId = $renamedId; | ||
$this->priority = $priority; | ||
$this->invalidBehavior = $invalidBehavior; | ||
} | ||
|
||
public function toString(): string | ||
{ | ||
return sprintf( | ||
'"%s" decorates service "%s"%s with priority "%d" and "%s" behavior.', | ||
$this->serviceId, | ||
$this->decoratedServiceId, | ||
$this->renamedId !== null ? sprintf(' and renames it to "%s"', $this->renamedId) : '', | ||
$this->priority, | ||
self::INVALID_BEHAVIORS[$this->invalidBehavior ?? 0] | ||
); | ||
} | ||
|
||
public function evaluate($other, string $description = '', bool $returnResult = false): bool | ||
{ | ||
if (!($other instanceof ContainerBuilder)) { | ||
throw new \InvalidArgumentException( | ||
'Expected an instance of Symfony\Component\DependencyInjection\ContainerBuilder' | ||
); | ||
} | ||
|
||
return $this->evaluateServiceDefinition($other, $returnResult); | ||
} | ||
|
||
private function evaluateServiceDefinition(ContainerBuilder $containerBuilder, bool $returnResult): bool | ||
{ | ||
if (!$containerBuilder->has($this->serviceId)) { | ||
if ($returnResult) { | ||
return false; | ||
} | ||
|
||
$this->fail( | ||
$this->serviceId, | ||
sprintf( | ||
'The container builder has no service "%s"', | ||
$this->serviceId | ||
) | ||
); | ||
} | ||
|
||
$definition = $containerBuilder->findDefinition($this->serviceId); | ||
|
||
$decorated = $definition->getDecoratedService(); | ||
|
||
if ($decorated === null) { | ||
if ($returnResult) { | ||
return false; | ||
} | ||
|
||
$this->fail( | ||
$this->serviceId, | ||
sprintf( | ||
'The container builder has a service "%s", but it does not decorate any service', | ||
$this->serviceId | ||
) | ||
); | ||
} | ||
|
||
if ($decorated[0] !== $this->decoratedServiceId) { | ||
if ($returnResult) { | ||
return false; | ||
} | ||
|
||
$this->fail( | ||
$this->serviceId, | ||
sprintf( | ||
'The container builder has a decorator service "%s", but it does decorate service "%s".', | ||
$this->serviceId, | ||
$decorated[0] | ||
) | ||
); | ||
} | ||
|
||
if ($decorated[1] !== $this->renamedId) { | ||
if ($returnResult) { | ||
return false; | ||
} | ||
|
||
$this->fail( | ||
$this->serviceId, | ||
sprintf( | ||
'The container builder has a decorator service "%s", but it does not rename decorated service to "%s".', | ||
$this->serviceId, | ||
$this->renamedId | ||
) | ||
); | ||
} | ||
|
||
if ($decorated[2] !== $this->priority) { | ||
if ($returnResult) { | ||
return false; | ||
} | ||
|
||
$this->fail( | ||
$this->serviceId, | ||
sprintf( | ||
'The container builder has a decorator service "%s", but it does not decorate at expected "%d" priority.', | ||
$this->serviceId, | ||
$this->priority | ||
) | ||
); | ||
} | ||
|
||
if (($decorated[3] ?? null) !== $this->invalidBehavior) { | ||
if ($returnResult) { | ||
return false; | ||
} | ||
|
||
$this->fail( | ||
$this->serviceId, | ||
sprintf( | ||
'The container builder has a decorator service "%s", but it does not decorate with expected "%s" behavior.', | ||
$this->serviceId, | ||
self::INVALID_BEHAVIORS[$this->invalidBehavior] | ||
) | ||
); | ||
} | ||
|
||
return true; | ||
} | ||
} |
Oops, something went wrong.