File tree 4 files changed +59
-19
lines changed
4 files changed +59
-19
lines changed Original file line number Diff line number Diff line change @@ -165,25 +165,7 @@ public function _before(TestInterface $test)
165
165
$ this ->di ['db ' ]->begin ();
166
166
$ this ->debugSection ('Database ' , 'Transaction started ' );
167
167
}
168
-
169
- // localize
170
- $ bootstrap = $ this ->bootstrapFile ;
171
- $ this ->client ->setApplication (function () use ($ bootstrap ) {
172
- $ currentDi = Di::getDefault ();
173
- /** @noinspection PhpIncludeInspection */
174
- $ application = require $ bootstrap ;
175
- $ di = $ application ->getDI ();
176
- if ($ currentDi ->has ('db ' )) {
177
- $ di ['db ' ] = $ currentDi ['db ' ];
178
- }
179
- if ($ currentDi ->has ('session ' )) {
180
- $ di ['session ' ] = $ currentDi ['session ' ];
181
- }
182
- if ($ di ->has ('cookies ' )) {
183
- $ di ['cookies ' ]->useEncryption (false );
184
- }
185
- return $ application ;
186
- });
168
+ $ this ->client ->setApplication ($ application );
187
169
}
188
170
189
171
/**
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \Controllers ;
4
+
5
+ use Phalcon \Mvc \Controller ;
6
+
7
+ class DatetimeController extends Controller
8
+ {
9
+ public function indexAction ()
10
+ {
11
+ echo "class: " . get_class ($ this ->getDI ()->get ('datetime ' ));
12
+ }
13
+
14
+ public function splAction ()
15
+ {
16
+ echo spl_object_hash ($ this ->getDI ());
17
+ }
18
+ }
Original file line number Diff line number Diff line change @@ -97,11 +97,27 @@ function ($view) use ($di) {
97
97
});
98
98
99
99
100
+ $ di ->set ('datetime ' , function () {
101
+ return new DateTime ();
102
+ });
103
+
104
+
100
105
$ router = $ di ->getRouter ();
101
106
102
107
$ router ->add ('/ ' , [
103
108
'controller ' => 'App\Controllers\Index ' ,
104
109
'action ' => 'index '
105
110
])->setName ('front.index ' );
106
111
112
+ $ router ->add ('/datetime ' , [
113
+ 'controller ' => 'App\Controllers\Datetime ' ,
114
+ 'action ' => 'index '
115
+ ])->setName ('front.datetime ' );
116
+
117
+ $ router ->add ('/datetime/spl ' , [
118
+ 'controller ' => 'App\Controllers\Datetime ' ,
119
+ 'action ' => 'spl '
120
+ ])->setName ('front.spl ' );
121
+
122
+
107
123
return new Application ($ di );
Original file line number Diff line number Diff line change @@ -150,6 +150,30 @@ public function testContainerMethods()
150
150
$ module ->_after ($ test );
151
151
}
152
152
153
+ public function testReplaceService ()
154
+ {
155
+ $ module = $ this ->getPhalconModule ();
156
+ $ test = new Codeception \Test \Unit ();
157
+ $ module ->_before ($ test );
158
+ $ diHash = spl_object_hash ($ module ->di );
159
+
160
+ $ datetime = $ module ->grabServiceFromContainer ('datetime ' );
161
+ $ this ->assertInstanceOf ('DateTime ' , $ datetime );
162
+ $ this ->assertEquals ($ diHash , spl_object_hash ($ module ->di ));
163
+
164
+ $ std = $ module ->addServiceToContainer ('datetime ' , function () {
165
+ return new \stdClass ();
166
+ }, false );
167
+ $ this ->assertInstanceOf ('stdClass ' , $ std );
168
+ $ this ->assertInstanceOf ('stdClass ' , $ module ->grabServiceFromContainer ('datetime ' ));
169
+ $ this ->assertEquals ($ diHash , spl_object_hash ($ module ->di ));
170
+ $ module ->amOnPage ('/datetime/spl ' );
171
+ $ module ->see ($ diHash );
172
+ $ module ->amOnPage ('/datetime ' );
173
+ $ module ->see ('class: stdClass ' );
174
+ $ module ->_after ($ test );
175
+ }
176
+
153
177
public function testRoutes ()
154
178
{
155
179
$ module = $ this ->getPhalconModule ();
You can’t perform that action at this time.
0 commit comments