1717
1818final class TokenizerBootloaderTest extends TestCase
1919{
20- #[DataProvider('readCacheDataProvider ' )]
20+ #[DataProvider('boolValuesDataProvider ' )]
2121 public function testCastingReadCacheEnvVariable (mixed $ readCache , bool $ expected ): void
2222 {
2323 $ binder = m::spy (BinderInterface::class);
2424 $ dirs = m::mock (DirectoriesInterface::class);
2525 $ env = m::mock (EnvironmentInterface::class);
2626
2727 $ env ->shouldReceive ('get ' )->once ()->with ('TOKENIZER_CACHE_TARGETS ' , false )->andReturn ($ readCache );
28+ $ env ->shouldReceive ('get ' )->once ()->with ('TOKENIZER_LOAD_CLASSES ' , true )->andReturn (true );
29+ $ env ->shouldReceive ('get ' )->once ()->with ('TOKENIZER_LOAD_ENUMS ' , false )->andReturn (false );
30+ $ env ->shouldReceive ('get ' )->once ()->with ('TOKENIZER_LOAD_INTERFACES ' , false )->andReturn (false );
2831
2932 $ dirs ->shouldReceive ('get ' )->once ()->with ('app ' )->andReturn ('app/ ' );
3033 $ dirs ->shouldReceive ('get ' )->once ()->with ('resources ' )->andReturn ('resources/ ' );
@@ -40,7 +43,73 @@ public function testCastingReadCacheEnvVariable(mixed $readCache, bool $expected
4043 $ this ->assertSame ($ expected , $ initConfig ['cache ' ]['enabled ' ]);
4144 }
4245
43- public static function readCacheDataProvider (): \Traversable
46+ #[DataProvider('boolValuesDataProvider ' )]
47+ public function testCastingLoadClassesEnvVariable (mixed $ classes , bool $ expected ): void
48+ {
49+ $ dirs = m::mock (DirectoriesInterface::class);
50+ $ env = m::mock (EnvironmentInterface::class);
51+
52+ $ env ->shouldReceive ('get ' )->once ()->with ('TOKENIZER_CACHE_TARGETS ' , false )->andReturn (false );
53+ $ env ->shouldReceive ('get ' )->once ()->with ('TOKENIZER_LOAD_CLASSES ' , true )->andReturn ($ classes );
54+ $ env ->shouldReceive ('get ' )->once ()->with ('TOKENIZER_LOAD_ENUMS ' , false )->andReturn (false );
55+ $ env ->shouldReceive ('get ' )->once ()->with ('TOKENIZER_LOAD_INTERFACES ' , false )->andReturn (false );
56+
57+ $ dirs ->shouldReceive ('get ' )->once ()->with ('app ' )->andReturn ('app/ ' );
58+ $ dirs ->shouldReceive ('get ' )->once ()->with ('resources ' )->andReturn ('resources/ ' );
59+ $ dirs ->shouldReceive ('get ' )->once ()->with ('config ' )->andReturn ('config/ ' );
60+ $ dirs ->shouldReceive ('get ' )->once ()->with ('runtime ' )->andReturn ('runtime/ ' );
61+
62+ $ bootloader = new TokenizerBootloader ($ config = new ConfigManager (new DirectoryLoader ('config ' )));
63+ $ bootloader ->init (m::spy (BinderInterface::class), $ dirs , $ env );
64+
65+ $ this ->assertSame ($ expected , $ config ->getConfig (TokenizerConfig::CONFIG )['load ' ]['classes ' ]);
66+ }
67+
68+ #[DataProvider('boolValuesDataProvider ' )]
69+ public function testCastingLoadEnumsEnvVariable (mixed $ enums , bool $ expected ): void
70+ {
71+ $ dirs = m::mock (DirectoriesInterface::class);
72+ $ env = m::mock (EnvironmentInterface::class);
73+
74+ $ env ->shouldReceive ('get ' )->once ()->with ('TOKENIZER_CACHE_TARGETS ' , false )->andReturn (false );
75+ $ env ->shouldReceive ('get ' )->once ()->with ('TOKENIZER_LOAD_CLASSES ' , true )->andReturn (false );
76+ $ env ->shouldReceive ('get ' )->once ()->with ('TOKENIZER_LOAD_ENUMS ' , false )->andReturn ($ enums );
77+ $ env ->shouldReceive ('get ' )->once ()->with ('TOKENIZER_LOAD_INTERFACES ' , false )->andReturn (false );
78+
79+ $ dirs ->shouldReceive ('get ' )->once ()->with ('app ' )->andReturn ('app/ ' );
80+ $ dirs ->shouldReceive ('get ' )->once ()->with ('resources ' )->andReturn ('resources/ ' );
81+ $ dirs ->shouldReceive ('get ' )->once ()->with ('config ' )->andReturn ('config/ ' );
82+ $ dirs ->shouldReceive ('get ' )->once ()->with ('runtime ' )->andReturn ('runtime/ ' );
83+
84+ $ bootloader = new TokenizerBootloader ($ config = new ConfigManager (new DirectoryLoader ('config ' )));
85+ $ bootloader ->init (m::spy (BinderInterface::class), $ dirs , $ env );
86+
87+ $ this ->assertSame ($ expected , $ config ->getConfig (TokenizerConfig::CONFIG )['load ' ]['enums ' ]);
88+ }
89+
90+ #[DataProvider('boolValuesDataProvider ' )]
91+ public function testCastingLoadInterfacesEnvVariable (mixed $ interfaces , bool $ expected ): void
92+ {
93+ $ dirs = m::mock (DirectoriesInterface::class);
94+ $ env = m::mock (EnvironmentInterface::class);
95+
96+ $ env ->shouldReceive ('get ' )->once ()->with ('TOKENIZER_CACHE_TARGETS ' , false )->andReturn (false );
97+ $ env ->shouldReceive ('get ' )->once ()->with ('TOKENIZER_LOAD_CLASSES ' , true )->andReturn (false );
98+ $ env ->shouldReceive ('get ' )->once ()->with ('TOKENIZER_LOAD_ENUMS ' , false )->andReturn (false );
99+ $ env ->shouldReceive ('get ' )->once ()->with ('TOKENIZER_LOAD_INTERFACES ' , false )->andReturn ($ interfaces );
100+
101+ $ dirs ->shouldReceive ('get ' )->once ()->with ('app ' )->andReturn ('app/ ' );
102+ $ dirs ->shouldReceive ('get ' )->once ()->with ('resources ' )->andReturn ('resources/ ' );
103+ $ dirs ->shouldReceive ('get ' )->once ()->with ('config ' )->andReturn ('config/ ' );
104+ $ dirs ->shouldReceive ('get ' )->once ()->with ('runtime ' )->andReturn ('runtime/ ' );
105+
106+ $ bootloader = new TokenizerBootloader ($ config = new ConfigManager (new DirectoryLoader ('config ' )));
107+ $ bootloader ->init (m::spy (BinderInterface::class), $ dirs , $ env );
108+
109+ $ this ->assertSame ($ expected , $ config ->getConfig (TokenizerConfig::CONFIG )['load ' ]['interfaces ' ]);
110+ }
111+
112+ public static function boolValuesDataProvider (): \Traversable
44113 {
45114 yield [true , true ];
46115 yield [false , false ];
0 commit comments