File tree Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Okapi \CodeTransformer \Tests \Functional ;
4+
5+ use Okapi \CodeTransformer \Tests \Stubs \Kernel \EmptyKernel ;
6+ use Okapi \CodeTransformer \Tests \Stubs \Kernel \ExceptionOnDoubleInitializationKernel ;
7+ use Okapi \CodeTransformer \Tests \Util ;
8+ use Okapi \Singleton \Exceptions \AlreadyInitializedException ;
9+ use PHPUnit \Framework \Attributes \RunTestsInSeparateProcesses ;
10+ use PHPUnit \Framework \TestCase ;
11+
12+ #[RunTestsInSeparateProcesses]
13+ class AlreadyInitializedKernelTest extends TestCase
14+ {
15+ public function testInitializedKernelTwice (): void
16+ {
17+ Util::clearCache ();
18+
19+ EmptyKernel::init ();
20+ EmptyKernel::init ();
21+
22+ $ this ->assertTrue (true );
23+ }
24+
25+ public function testInitializeKernelTwiceWithExceptionOnDoubleInitializationOption (): void
26+ {
27+ Util::clearCache ();
28+
29+ $ this ->expectException (AlreadyInitializedException::class);
30+
31+ ExceptionOnDoubleInitializationKernel::init ();
32+ ExceptionOnDoubleInitializationKernel::init ();
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Okapi \CodeTransformer \Tests \Stubs \Kernel ;
4+
5+ use Okapi \CodeTransformer \CodeTransformerKernel ;
6+ use Okapi \CodeTransformer \Tests \Util ;
7+
8+ class EmptyKernel extends CodeTransformerKernel
9+ {
10+ protected ?string $ cacheDir = Util::CACHE_DIR ;
11+
12+ protected array $ transformers = [];
13+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ /** @noinspection PhpUnhandledExceptionInspection */
3+ namespace Okapi \CodeTransformer \Tests \Stubs \Kernel ;
4+
5+ use Exception ;
6+
7+ class ExceptionOnDoubleInitializationKernel extends EmptyKernel
8+ {
9+ private int $ initCount = 0 ;
10+
11+ protected bool $ throwExceptionOnDoubleInitialization = true ;
12+
13+ protected function preInit (): void
14+ {
15+ $ this ->initCount ++;
16+
17+ if ($ this ->initCount > 1 ) {
18+ throw new Exception ('I should not be initialized twice! ' );
19+ }
20+
21+ parent ::preInit ();
22+ }
23+ }
You can’t perform that action at this time.
0 commit comments