File tree Expand file tree Collapse file tree 3 files changed +50
-24
lines changed
Expand file tree Collapse file tree 3 files changed +50
-24
lines changed Original file line number Diff line number Diff line change 11<?php
22namespace PHPMentors \DomainCoder \Resource \Page ;
33
4- use Ray \Di \Injector ;
5- use PHPMentors \DomainCoder \Module \TestModule ;
4+ use PHPMentors \DomainCoder \Test \InjectorAwareTestCase ;
65
7- class IndexTest extends \PHPUnit_Framework_TestCase
6+ class IndexTest extends InjectorAwareTestCase
87{
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-
208 /**
219 * page resource
2210 *
@@ -25,7 +13,7 @@ protected function setUp()
2513 public function resource ()
2614 {
2715 // resource request
28- $ page = $ this ->resource ->get ->uri ('page://self/index ' )->eager ->request ();
16+ $ page = $ this ->createResource () ->get ->uri ('page://self/index ' )->eager ->request ();
2917 $ this ->assertSame (200 , $ page ->code );
3018
3119 return $ page ;
@@ -66,7 +54,7 @@ public function testRenderedHtml($page)
6654 */
6755 public function testOnGet ()
6856 {
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 ();
7058 $ this ->assertSame ('Hello koriym ' , $ page ['greeting ' ]);
7159 }
7260}
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 11<?php
2-
3- use BEAR \Package \Dev \Dev ;
4- use Ray \Di \Injector ;
5- use PHPMentors \DomainCoder \Module \AppModule ;
6-
72error_reporting (E_ALL );
83ini_set ('xdebug.max_nesting_level ' , 300 );
94
1712
1813// clear cache files
1914require $ _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