2
2
3
3
namespace Tests \Cases \DI ;
4
4
5
+ use Contributte \Tester \Environment ;
6
+ use Contributte \Tester \Utils \ContainerBuilder ;
7
+ use Contributte \Tester \Utils \Neonkit ;
5
8
use Doctrine \Common \Annotations \CachedReader ;
6
9
use Doctrine \Common \Annotations \Reader ;
7
10
use Doctrine \Common \Cache \ApcuCache ;
8
11
use Doctrine \Common \Cache \Cache ;
9
12
use Doctrine \Common \Cache \PhpFileCache ;
10
- use Exception ;
11
13
use Nette \DI \Compiler ;
12
- use Nette \DI \Container ;
13
- use Nette \DI \ContainerLoader ;
14
14
use Nette \InvalidStateException ;
15
15
use Nettrine \Annotations \DI \AnnotationsExtension ;
16
16
use Nettrine \Cache \DI \CacheExtension ;
17
17
use Tester \Assert ;
18
18
use Tester \TestCase ;
19
- use Tests \Toolkit \NeonLoader ;
20
- use Tests \Toolkit \Tests ;
21
19
22
20
require __DIR__ . '/../../bootstrap.php ' ;
23
21
@@ -26,39 +24,35 @@ final class AnnotationsExtensionTest extends TestCase
26
24
27
25
public function testAutowiredCache (): void
28
26
{
29
- $ loader = new ContainerLoader (Tests::TEMP_PATH , true );
30
- $ class = $ loader ->load (static function (Compiler $ compiler ): void {
31
- $ compiler ->addExtension ('annotations ' , new AnnotationsExtension ());
32
- $ compiler ->addExtension ('cache ' , new CacheExtension ());
33
- $ compiler ->addConfig ([
34
- 'parameters ' => [
35
- 'tempDir ' => Tests::TEMP_PATH ,
36
- ],
37
- ]);
38
- $ compiler ->addDependencies ([__FILE__ ]);
39
- }, __METHOD__ );
40
-
41
- $ container = new $ class ();
42
- assert ($ container instanceof Container);
27
+ $ container = ContainerBuilder::of ()
28
+ ->withCompiler (function (Compiler $ compiler ): void {
29
+ $ compiler ->addExtension ('annotations ' , new AnnotationsExtension ());
30
+ $ compiler ->addExtension ('cache ' , new CacheExtension ());
31
+ $ compiler ->addConfig ([
32
+ 'parameters ' => [
33
+ 'tempDir ' => Environment::getTestDir (),
34
+ ],
35
+ ]);
36
+ $ compiler ->addDependencies ([__FILE__ ]);
37
+ })
38
+ ->build ();
43
39
44
40
Assert::type (CachedReader::class, $ container ->getByType (Reader::class));
45
41
Assert::type (PhpFileCache::class, $ container ->getService ('cache.driver ' ));
46
42
}
47
43
48
44
public function testProvidedCache (): void
49
45
{
50
- $ loader = new ContainerLoader (Tests::TEMP_PATH , true );
51
- $ class = $ loader ->load (static function (Compiler $ compiler ): void {
52
- $ compiler ->addExtension ('annotations ' , new AnnotationsExtension ());
53
- $ compiler ->addConfig (NeonLoader::load ('
54
- annotations:
55
- cache: Doctrine\Common\Cache\ApcuCache
56
- ' ));
57
- $ compiler ->addDependencies ([__FILE__ ]);
58
- }, __METHOD__ );
59
-
60
- $ container = new $ class ();
61
- assert ($ container instanceof Container);
46
+ $ container = ContainerBuilder::of ()
47
+ ->withCompiler (function (Compiler $ compiler ): void {
48
+ $ compiler ->addExtension ('annotations ' , new AnnotationsExtension ());
49
+ $ compiler ->addConfig (Neonkit::load ('
50
+ annotations:
51
+ cache: Doctrine\Common\Cache\ApcuCache
52
+ ' ));
53
+ $ compiler ->addDependencies ([__FILE__ ]);
54
+ })
55
+ ->build ();
62
56
63
57
Assert::type (CachedReader::class, $ container ->getByType (Reader::class));
64
58
Assert::type (ApcuCache::class, $ container ->getService ('annotations.cache ' ));
@@ -67,17 +61,13 @@ public function testProvidedCache(): void
67
61
68
62
public function testNoCache (): void
69
63
{
70
- Assert::type (new Exception (), new InvalidStateException ());
71
-
72
64
Assert::exception (function (): void {
73
- $ loader = new ContainerLoader (Tests::TEMP_PATH , true );
74
- $ class = $ loader ->load (static function (Compiler $ compiler ): void {
75
- $ compiler ->addExtension ('annotations ' , new AnnotationsExtension ());
76
- $ compiler ->addDependencies ([__FILE__ ]);
77
- }, __METHOD__ );
78
-
79
- $ container = new $ class ();
80
- Assert::true ($ container instanceof Container);
65
+ ContainerBuilder::of ()
66
+ ->withCompiler (function (Compiler $ compiler ): void {
67
+ $ compiler ->addExtension ('annotations ' , new AnnotationsExtension ());
68
+ $ compiler ->addDependencies ([__FILE__ ]);
69
+ })
70
+ ->build ();
81
71
}, InvalidStateException::class, "Service 'annotations.reader' (type of Doctrine\Common\Annotations\Reader): Service of type Doctrine\Common\Cache\Cache not found. Did you add it to configuration file? " );
82
72
}
83
73
0 commit comments