File tree 3 files changed +41
-3
lines changed
3 files changed +41
-3
lines changed Original file line number Diff line number Diff line change 28
28
"bamarni/composer-bin-plugin" : " ^1.8" ,
29
29
"dama/doctrine-test-bundle" : " ^7.0|^8.0" ,
30
30
"doctrine/common" : " ^3.2" ,
31
+ "doctrine/collections" : " ^1.7|^2.0" ,
31
32
"doctrine/doctrine-bundle" : " ^2.10" ,
32
33
"doctrine/doctrine-migrations-bundle" : " ^2.2|^3.0" ,
33
34
"doctrine/mongodb-odm-bundle" : " ^4.6|^5.0" ,
43
44
},
44
45
"autoload" : {
45
46
"psr-4" : { "Zenstruck\\ Foundry\\ " : " src/" },
46
- "files" : [" src/functions.php" , " src/Persistence/functions.php" ]
47
+ "files" : [" src/functions.php" , " src/Persistence/functions.php" , " src/phpunit_helper.php " ]
47
48
},
48
49
"autoload-dev" : {
49
50
"psr-4" : {
Original file line number Diff line number Diff line change 16
16
use Symfony \Bundle \FrameworkBundle \Test \KernelTestCase ;
17
17
use Zenstruck \Foundry \Persistence \PersistenceManager ;
18
18
19
+ use function Zenstruck \Foundry \restorePhpUnitErrorHandler ;
20
+
19
21
/**
20
22
* @author Kevin Bond <kevinbond@gmail.com>
21
23
*/
@@ -34,7 +36,10 @@ public static function _resetDatabase(): void
34
36
35
37
PersistenceManager::resetDatabase (
36
38
static fn () => static ::bootKernel (),
37
- static fn () => static ::ensureKernelShutdown (),
39
+ static function (): void {
40
+ static ::ensureKernelShutdown ();
41
+ restorePhpUnitErrorHandler ();
42
+ },
38
43
);
39
44
}
40
45
@@ -51,7 +56,10 @@ public static function _resetSchema(): void
51
56
52
57
PersistenceManager::resetSchema (
53
58
static fn () => static ::bootKernel (),
54
- static fn () => static ::ensureKernelShutdown (),
59
+ static function (): void {
60
+ static ::ensureKernelShutdown ();
61
+ restorePhpUnitErrorHandler ();
62
+ },
55
63
);
56
64
}
57
65
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Zenstruck \Foundry ;
6
+
7
+ /**
8
+ * When using ResetDatabase trait, we're booting the kernel,
9
+ * which registers the Symfony's error handler too soon.
10
+ * It is then impossible for PHPUnit to handle deprecations.
11
+ *
12
+ * This method tries to mitigate this problem by restoring the error handler.
13
+ *
14
+ * @see https://github.com/symfony/symfony/issues/53812
15
+ *
16
+ * @internal
17
+ */
18
+ function restorePhpUnitErrorHandler (): void
19
+ {
20
+ while (true ) {
21
+ $ previousHandler = set_error_handler (static fn () => null ); // @phpstan-ignore-line
22
+ restore_error_handler ();
23
+ $ isPhpUnitErrorHandler = ($ previousHandler instanceof \PHPUnit \Runner \ErrorHandler); // @phpstan-ignore-line
24
+ if ($ previousHandler === null || $ isPhpUnitErrorHandler ) {
25
+ break ;
26
+ }
27
+ restore_error_handler ();
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments