Skip to content
Merged
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"psr/container": "^1.0 || ^2.0",
"symfony/deprecation-contracts": "^3.1",
"symfony/http-foundation": "^6.4.14 || ^7.0 || ^8.0",
"symfony/http-kernel": "^6.4 || ^7.0 || ^8.0",
"symfony/http-kernel": "^6.4.13 || ^7.0 || ^8.0",
"symfony/property-access": "^6.4 || ^7.0 || ^8.0",
"symfony/property-info": "^6.4 || ^7.1 || ^8.0",
"symfony/serializer": "^6.4 || ^7.0 || ^8.0",
Expand Down
3 changes: 2 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
backupGlobals="false"
bootstrap="tests/Fixtures/app/bootstrap.php"
colors="true"
cacheDirectory=".phpunit.cache">
cacheDirectory=".phpunit.cache"
failOnRisky="true">
<php>
<ini name="error_reporting" value="-1"/>
<ini name="memory_limit" value="-1"/>
Expand Down
7 changes: 0 additions & 7 deletions src/Doctrine/Odm/Tests/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\HttpKernel\Kernel;

/**
Expand All @@ -43,12 +42,6 @@ public function registerBundles(): array
return [
new FrameworkBundle(),
new DoctrineMongoDBBundle(),
new class extends Bundle {
public function shutdown(): void
{
restore_exception_handler();
}
},
];
}

Expand Down
33 changes: 33 additions & 0 deletions src/Doctrine/Odm/Tests/DoctrineMongoDbOdmFilterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Repository\DocumentRepository;
use Doctrine\Persistence\ManagerRegistry;
use PHPUnit\Framework\Attributes\After;
use PHPUnit\Framework\Attributes\Before;
use PHPUnit\Framework\Attributes\DataProvider;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\ErrorHandler\ErrorHandler;

/**
* @internal
Expand All @@ -37,6 +40,8 @@ abstract class DoctrineMongoDbOdmFilterTestCase extends KernelTestCase

protected string $filterClass;

private bool $symfonyErrorHandlerWasRegistered = false;

protected function setUp(): void
{
self::bootKernel();
Expand All @@ -46,6 +51,34 @@ protected function setUp(): void
$this->repository = $this->manager->getRepository($this->resourceClass);
}

/**
* Symfony\Bundle\FrameworkBundle\FrameworkBundle::boot() registers Symfony's ErrorHandler via
* set_exception_handler() but never unregisters it: each kernel boot leaks one entry on the
* exception handler stack, which PHPUnit flags as Risky. Track whether the handler was already
* present before the test so we only pop the entry our own test introduced.
*/
#[Before]
protected function captureExceptionHandlerStack(): void
{
$this->symfonyErrorHandlerWasRegistered = self::isSymfonyErrorHandlerRegistered();
}

#[After]
protected function restoreExceptionHandlerStack(): void
{
if (!$this->symfonyErrorHandlerWasRegistered && self::isSymfonyErrorHandlerRegistered()) {
restore_exception_handler();
}
}

private static function isSymfonyErrorHandlerRegistered(): bool
{
$current = set_exception_handler(static fn () => null);
restore_exception_handler();

return \is_array($current) && $current[0] instanceof ErrorHandler;
}

#[DataProvider('provideApplyTestData')]
public function testApply(?array $properties, array $filterParameters, array $expectedPipeline, ?callable $factory = null, ?string $resourceClass = null): void
{
Expand Down
7 changes: 0 additions & 7 deletions src/Doctrine/Orm/Tests/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\HttpKernel\Kernel;

/**
Expand All @@ -44,12 +43,6 @@ public function registerBundles(): array
new FrameworkBundle(),
new DoctrineBundle(),
new TestBundle(),
new class extends Bundle {
public function shutdown(): void
{
restore_exception_handler();
}
},
];
}

Expand Down
33 changes: 33 additions & 0 deletions src/Doctrine/Orm/Tests/DoctrineOrmFilterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
use ApiPlatform\Doctrine\Orm\Util\QueryNameGenerator;
use Doctrine\ORM\EntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use PHPUnit\Framework\Attributes\After;
use PHPUnit\Framework\Attributes\Before;
use PHPUnit\Framework\Attributes\DataProvider;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\ErrorHandler\ErrorHandler;

/**
* @internal
Expand All @@ -38,6 +41,8 @@ abstract class DoctrineOrmFilterTestCase extends KernelTestCase

protected string $filterClass;

private bool $symfonyErrorHandlerWasRegistered = false;

protected function setUp(): void
{
self::bootKernel();
Expand All @@ -46,6 +51,34 @@ protected function setUp(): void
$this->repository = $this->managerRegistry->getManagerForClass(Dummy::class)->getRepository(Dummy::class);
}

/**
* Symfony\Bundle\FrameworkBundle\FrameworkBundle::boot() registers Symfony's ErrorHandler via
* set_exception_handler() but never unregisters it: each kernel boot leaks one entry on the
* exception handler stack, which PHPUnit flags as Risky. Track whether the handler was already
* present before the test so we only pop the entry our own test introduced.
*/
#[Before]
protected function captureExceptionHandlerStack(): void
{
$this->symfonyErrorHandlerWasRegistered = self::isSymfonyErrorHandlerRegistered();
}

#[After]
protected function restoreExceptionHandlerStack(): void
{
if (!$this->symfonyErrorHandlerWasRegistered && self::isSymfonyErrorHandlerRegistered()) {
restore_exception_handler();
}
}

private static function isSymfonyErrorHandlerRegistered(): bool
{
$current = set_exception_handler(static fn () => null);
restore_exception_handler();

return \is_array($current) && $current[0] instanceof ErrorHandler;
}

#[DataProvider('provideApplyTestData')]
public function testApply(?array $properties, array $filterParameters, string $expectedDql, ?array $expectedParameters = null, ?callable $factory = null, ?string $resourceClass = null): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/State/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"php": ">=8.2",
"api-platform/metadata": "^4.3",
"psr/container": "^1.0 || ^2.0",
"symfony/http-kernel": "^6.4 || ^7.0 || ^8.0",
"symfony/http-kernel": "^6.4.13 || ^7.0 || ^8.0",
"symfony/serializer": "^6.4 || ^7.0 || ^8.0",
"symfony/translation-contracts": "^3.0",
"symfony/deprecation-contracts": "^3.1"
Expand Down
34 changes: 34 additions & 0 deletions src/Symfony/Bundle/Test/ApiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
namespace ApiPlatform\Symfony\Bundle\Test;

use ApiPlatform\Metadata\IriConverterInterface;
use PHPUnit\Framework\Attributes\After;
use PHPUnit\Framework\Attributes\Before;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\BrowserKit\AbstractBrowser;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\ErrorHandler\ErrorHandler;
use Symfony\Component\HttpClient\HttpClientTrait;

/**
Expand All @@ -38,6 +41,37 @@ abstract class ApiTestCase extends KernelTestCase
*/
protected static ?bool $alwaysBootKernel = null;

private bool $symfonyErrorHandlerWasRegistered = false;

/**
* Symfony\Bundle\FrameworkBundle\FrameworkBundle::boot() registers Symfony's ErrorHandler via
* set_exception_handler() but never unregisters it: each kernel boot leaks one entry on the
* exception handler stack, which PHPUnit flags as Risky. Track whether the handler was already
* present before the test (e.g. the kernel was booted from setUpBeforeClass) so we only pop
* the entry our own test introduced.
*/
#[Before]
protected function captureExceptionHandlerStack(): void
{
$this->symfonyErrorHandlerWasRegistered = self::isSymfonyErrorHandlerRegistered();
}

#[After]
protected function restoreExceptionHandlerStack(): void
{
if (!$this->symfonyErrorHandlerWasRegistered && self::isSymfonyErrorHandlerRegistered()) {
restore_exception_handler();
}
}

private static function isSymfonyErrorHandlerRegistered(): bool
{
$current = set_exception_handler(static fn () => null);
restore_exception_handler();

return \is_array($current) && $current[0] instanceof ErrorHandler;
}

/**
* Creates a Client.
*
Expand Down
5 changes: 0 additions & 5 deletions src/Symfony/Tests/EventListener/ErrorListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@

class ErrorListenerTest extends TestCase
{
protected function tearDown(): void
{
restore_exception_handler();
}

public function testDuplicateException(): void
{
$exception = new \Exception();
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"api-platform/openapi": "^4.3",
"symfony/asset": "^6.4 || ^7.0 || ^8.0",
"symfony/finder": "^6.4 || ^7.0 || ^8.0",
"symfony/http-kernel": "^6.4.13 || ^7.0 || ^8.0",
"symfony/property-info": "^6.4 || ^7.0 || ^8.0",
"symfony/property-access": "^6.4 || ^7.0 || ^8.0",
"symfony/serializer": "^6.4 || ^7.0 || ^8.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Validator/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"php": ">=8.2",
"api-platform/metadata": "^4.3",
"symfony/type-info": "^7.3 || ^8.0",
"symfony/http-kernel": "^6.4 || ^7.1 || ^8.0",
"symfony/http-kernel": "^6.4.13 || ^7.1 || ^8.0",
"symfony/serializer": "^6.4 || ^7.1 || ^8.0",
"symfony/validator": "^6.4.11 || ^7.1 || ^8.0",
"symfony/web-link": "^6.4 || ^7.1 || ^8.0"
Expand Down
6 changes: 0 additions & 6 deletions tests/Fixtures/app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,6 @@ public function registerBundles(): array
return $bundles;
}

public function shutdown(): void
{
parent::shutdown();
restore_exception_handler();
}

public function getProjectDir(): string
{
return __DIR__;
Expand Down
Loading