File tree 3 files changed +50
-24
lines changed
3 files changed +50
-24
lines changed Original file line number Diff line number Diff line change 1
1
<?php
2
2
namespace PHPMentors \DomainCoder \Resource \Page ;
3
3
4
- use Ray \Di \Injector ;
5
- use PHPMentors \DomainCoder \Module \TestModule ;
4
+ use PHPMentors \DomainCoder \Test \InjectorAwareTestCase ;
6
5
7
- class IndexTest extends \PHPUnit_Framework_TestCase
6
+ class IndexTest extends InjectorAwareTestCase
8
7
{
9
- /**
10
- * @var \BEAR\Resource\ResourceInterface
11
- */
12
- private $ resource ;
13
-
14
- protected function setUp ()
15
- {
16
- parent ::setUp ();
17
- $ this ->resource = clone $ GLOBALS ['RESOURCE ' ];
18
- }
19
-
20
8
/**
21
9
* page resource
22
10
*
@@ -25,7 +13,7 @@ protected function setUp()
25
13
public function resource ()
26
14
{
27
15
// resource request
28
- $ page = $ this ->resource ->get ->uri ('page://self/index ' )->eager ->request ();
16
+ $ page = $ this ->createResource () ->get ->uri ('page://self/index ' )->eager ->request ();
29
17
$ this ->assertSame (200 , $ page ->code );
30
18
31
19
return $ page ;
@@ -66,7 +54,7 @@ public function testRenderedHtml($page)
66
54
*/
67
55
public function testOnGet ()
68
56
{
69
- $ page = $ this ->resource ->get ->uri ('page://self/index ' )->withQuery (['name ' => 'koriym ' ])->eager ->request ();
57
+ $ page = $ this ->createResource () ->get ->uri ('page://self/index ' )->withQuery (['name ' => 'koriym ' ])->eager ->request ();
70
58
$ this ->assertSame ('Hello koriym ' , $ page ['greeting ' ]);
71
59
}
72
60
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /*
3
+ * Copyright (c) 2014 KUBO Atsuhiro <[email protected] >,
4
+ * All rights reserved.
5
+ *
6
+ * This file is part of Domain Coder.
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ */
21
+
22
+ namespace PHPMentors \DomainCoder \Test ;
23
+
24
+ use Ray \Di \Injector ;
25
+
26
+ use PHPMentors \DomainCoder \Module \AppModule ;
27
+
28
+ abstract class InjectorAwareTestCase extends \PHPUnit_Framework_TestCase
29
+ {
30
+ /**
31
+ * @var \BEAR\Resource\ResourceInterface
32
+ */
33
+ private static $ resource ;
34
+
35
+ /**
36
+ * @return \BEAR\Resource\ResourceInterface
37
+ */
38
+ protected function createResource ()
39
+ {
40
+ if (self ::$ resource === null ) {
41
+ self ::$ resource = Injector::create ([new AppModule ('test ' )])->getInstance ('\BEAR\Resource\ResourceInterface ' );
42
+ }
43
+
44
+ return self ::$ resource ;
45
+ }
46
+ }
Original file line number Diff line number Diff line change 1
1
<?php
2
-
3
- use BEAR \Package \Dev \Dev ;
4
- use Ray \Di \Injector ;
5
- use PHPMentors \DomainCoder \Module \AppModule ;
6
-
7
2
error_reporting (E_ALL );
8
3
ini_set ('xdebug.max_nesting_level ' , 300 );
9
4
17
12
18
13
// clear cache files
19
14
require $ _ENV ['APP_DIR ' ] . '/bin/clear.php ' ;
20
-
21
- // set the resource client
22
- $ GLOBALS ['RESOURCE ' ] = Injector::create ([new AppModule ('test ' )])->getInstance ('\BEAR\Resource\ResourceInterface ' );
You can’t perform that action at this time.
0 commit comments