Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
119 additions
and
28 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
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
43 changes: 43 additions & 0 deletions
43
src/Bridge/Symfony/Bundle/DependencyInjection/Compiler/TestPass.php
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,43 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler; | ||
|
||
use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\Client; | ||
use Symfony\Component\BrowserKit\AbstractBrowser; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Component\HttpClient\HttpClientTrait; | ||
|
||
final class TestPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
if ( | ||
!class_exists(AbstractBrowser::class) || | ||
!trait_exists(HttpClientTrait::class) || | ||
!$container->hasParameter('test.client.parameters') | ||
) { | ||
return; | ||
} | ||
|
||
$container->setDefinition( | ||
'test.api_platform.client', | ||
(new Definition(Client::class, [new Reference('test.client')])) | ||
->setShared(false) | ||
->setPublic(true) | ||
); | ||
} | ||
} |
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
68 changes: 68 additions & 0 deletions
68
tests/Bridge/Symfony/Bundle/DependencyInjection/Compiler/TestPassTest.php
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,68 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Core\Tests\Bridge\Symfony\Bundle\DependencyInjection\Compiler; | ||
|
||
use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\TestPass; | ||
use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\Client; | ||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\Argument; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
|
||
final class TestPassTest extends TestCase | ||
{ | ||
private $containerBuilderProphecy; | ||
private $testPass; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->containerBuilderProphecy = $this->prophesize(ContainerBuilder::class); | ||
$this->testPass = new TestPass(); | ||
} | ||
|
||
public function testConstruct(): void | ||
{ | ||
self::assertInstanceOf(CompilerPassInterface::class, $this->testPass); | ||
} | ||
|
||
public function testProcessWithoutTestClientParameters(): void | ||
{ | ||
$this->containerBuilderProphecy->hasParameter('test.client.parameters')->willReturn(false)->shouldBeCalledOnce(); | ||
$this->containerBuilderProphecy->setDefinition('test.api_platform.client', Argument::type(Definition::class))->shouldNotBeCalled(); | ||
|
||
$this->testPass->process($this->containerBuilderProphecy->reveal()); | ||
} | ||
|
||
public function testProcess(): void | ||
{ | ||
$this->containerBuilderProphecy->hasParameter('test.client.parameters')->willReturn(true)->shouldBeCalledOnce(); | ||
$this->containerBuilderProphecy | ||
->setDefinition( | ||
'test.api_platform.client', | ||
Argument::allOf( | ||
Argument::type(Definition::class), | ||
Argument::that(function (Definition $testClientDefinition) { | ||
return | ||
Client::class === $testClientDefinition->getClass() && | ||
!$testClientDefinition->isShared() && | ||
$testClientDefinition->isPublic(); | ||
}) | ||
) | ||
) | ||
->shouldBeCalledOnce(); | ||
|
||
$this->testPass->process($this->containerBuilderProphecy->reveal()); | ||
} | ||
} |
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