11
11
namespace Arachne \Codeception \Module ;
12
12
13
13
use Codeception \Module ;
14
- use Codeception \TestCase ;
14
+ use Codeception \TestInterface ;
15
+ use Nette \Caching \Storages \IJournal ;
16
+ use Nette \Caching \Storages \SQLiteJournal ;
15
17
use Nette \Configurator ;
18
+ use Nette \DI \MissingServiceException ;
19
+ use Nette \Http \Session ;
16
20
use Nette \Utils \FileSystem ;
21
+ use ReflectionProperty ;
17
22
18
23
class Container extends Module
19
24
{
@@ -33,25 +38,52 @@ class Container extends Module
33
38
*/
34
39
private $ path ;
35
40
41
+ /**
42
+ * @var Container
43
+ */
44
+ private $ container ;
45
+
36
46
public function _beforeSuite ($ settings = [])
37
47
{
38
48
$ this ->path = $ settings ['path ' ];
39
49
}
40
50
41
- public function _before (TestCase $ test )
51
+ public function _before (TestInterface $ test )
42
52
{
43
53
$ tempDir = $ this ->path .'/ ' .$ this ->config ['tempDir ' ];
44
54
FileSystem::delete ($ tempDir );
45
55
FileSystem::createDir ($ tempDir );
56
+ $ this ->container = null ;
46
57
}
47
58
48
- public function _afterSuite ( )
59
+ public function _after ( TestInterface $ test )
49
60
{
50
- FileSystem::delete ($ this ->path .'/ ' .$ this ->config ['tempDir ' ]);
61
+ if ($ this ->container ) {
62
+ try {
63
+ $ this ->container ->getByType (Session::class)->close ();
64
+ } catch (MissingServiceException $ e ) {
65
+ }
66
+
67
+ try {
68
+ $ journal = $ this ->container ->getByType (IJournal::class);
69
+ if ($ journal instanceof SQLiteJournal) {
70
+ $ property = new ReflectionProperty (SQLiteJournal::class, 'pdo ' );
71
+ $ property ->setAccessible (true );
72
+ $ property ->setValue ($ journal , null );
73
+ }
74
+ } catch (MissingServiceException $ e ) {
75
+ }
76
+
77
+ FileSystem::delete ($ this ->container ->getParameters ()['tempDir ' ]);
78
+ }
51
79
}
52
80
53
81
public function createContainer (array $ configFiles = null )
54
82
{
83
+ if ($ this ->container ) {
84
+ $ this ->fail ('Can \'t create more than one container. ' );
85
+ }
86
+
55
87
$ configurator = new $ this ->config ['configurator ' ]();
56
88
57
89
if ($ this ->config ['logDir ' ]) {
@@ -72,6 +104,8 @@ public function createContainer(array $configFiles = null)
72
104
$ configurator ->addConfig ($ this ->path .'/ ' .$ file , false );
73
105
}
74
106
75
- return $ configurator ->createContainer ();
107
+ $ this ->container = $ configurator ->createContainer ();
108
+
109
+ return $ this ->container ;
76
110
}
77
111
}
0 commit comments