Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ final class TestClientPass implements CompilerPassInterface
public function process(ContainerBuilder $container): void
{
if (
!class_exists(Client::class)
|| !class_exists(AbstractBrowser::class)
!class_exists(AbstractBrowser::class)
|| !trait_exists(HttpClientTrait::class)
// after the HttpClientTrait check: Client uses that trait
|| !class_exists(Client::class)
|| !$container->hasParameter('test.client.parameters')
) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
namespace ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler;

use ApiPlatform\Test\Client;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\HttpClient\HttpClientTrait;

final class TestClientPassTest extends TestCase
{
Expand Down Expand Up @@ -65,4 +67,28 @@ public function testProcess(): void

$this->testClientPass->process($this->containerBuilderProphecy->reveal());
}

/**
* ApiPlatform\Test\Client uses HttpClientTrait, so checking for the client class
* must not autoload it before the pass knows that symfony/http-client is installed.
*/
#[RunInSeparateProcess]
public function testProcessWithoutHttpClient(): void
{
foreach (spl_autoload_functions() as $autoloader) {
spl_autoload_unregister($autoloader);
spl_autoload_register(static function (string $class) use ($autoloader): void {
if (HttpClientTrait::class !== $class) {
$autoloader($class);
}
});
}

$container = new ContainerBuilder();
$container->setParameter('test.client.parameters', []);

$this->testClientPass->process($container);

self::assertFalse($container->hasDefinition('test.api_platform.client'));
}
}
Loading