11
11
namespace Arachne \Codeception \Module ;
12
12
13
13
use Arachne \Codeception \Connector \Nette as NetteConnector ;
14
- use Arachne \Codeception \Module \Container as ContainerModule ;
15
14
use Codeception \Lib \Framework ;
16
15
use Codeception \TestInterface ;
17
- use Nette \DI \ Container ;
18
- use Nette \DI \ MissingServiceException ;
16
+ use Nette \Http \ IRequest ;
17
+ use Nette \Http \ IResponse ;
19
18
20
19
/**
21
20
* @author Jáchym Toušek <enumag@gmail.com>
@@ -26,21 +25,6 @@ class Nette extends Framework
26
25
'followRedirects ' => true ,
27
26
];
28
27
29
- /**
30
- * @var array
31
- */
32
- private $ configFiles ;
33
-
34
- /**
35
- * @var Container
36
- */
37
- private $ container ;
38
-
39
- /**
40
- * @var callable
41
- */
42
- private $ containerAccessor ;
43
-
44
28
/**
45
29
* @var string
46
30
*/
@@ -54,30 +38,15 @@ public function _beforeSuite($settings = [])
54
38
public function _before (TestInterface $ test )
55
39
{
56
40
$ this ->configFiles = null ;
57
- $ this ->container = null ;
58
- $ this ->containerAccessor = function () {
59
- if (!$ this ->container ) {
60
- $ this ->container = $ this ->getModule (ContainerModule::class)->createContainer ();
61
- }
62
-
63
- return $ this ->container ;
64
- };
65
-
66
41
$ this ->client = new NetteConnector ();
67
- $ this ->client ->setContainerAccessor ($ this ->containerAccessor );
42
+ $ this ->client ->setContainerAccessor (function () {
43
+ return $ this ->getModule (Container::class)->getContainer ();
44
+ });
68
45
$ this ->client ->followRedirects ($ this ->config ['followRedirects ' ]);
69
46
70
47
parent ::_before ($ test );
71
48
}
72
49
73
- public function useConfigFiles (array $ configFiles )
74
- {
75
- if ($ this ->container ) {
76
- $ this ->fail ('Can \'t set configFiles after the container is created. ' );
77
- }
78
- $ this ->configFiles = $ configFiles ;
79
- }
80
-
81
50
public function _after (TestInterface $ test )
82
51
{
83
52
parent ::_after ($ test );
@@ -94,9 +63,8 @@ public function seeRedirectTo($url)
94
63
if ($ this ->config ['followRedirects ' ]) {
95
64
$ this ->fail ('Method seeRedirectTo only works when followRedirects option is disabled ' );
96
65
}
97
- $ container = call_user_func ($ this ->containerAccessor );
98
- $ request = $ container ->getByType ('Nette\Http\IRequest ' );
99
- $ response = $ container ->getByType ('Nette\Http\IResponse ' );
66
+ $ request = $ this ->getModule (Container::class)->grabService (IRequest::class);
67
+ $ response = $ this ->getModule (Container::class)->grabService (IResponse::class);
100
68
if ($ response ->getHeader ('Location ' ) !== $ request ->getUrl ()->getHostUrl ().$ url && $ response ->getHeader ('Location ' ) !== $ url ) {
101
69
$ this ->fail ('Couldn \'t confirm redirect target to be " ' .$ url .'", Location header contains " ' .$ response ->getHeader ('Location ' ).'". ' );
102
70
}
0 commit comments