public
Description: My mirror of phpspec
Homepage: http://www.phpspec.org/
Clone URL: git://github.com/tedkulp/phpspec.git
* Merging r189+ changes from branches/zend 
  implementing the PHPSpec ZF App Testing Manifesto

git-svn-id: http://phpspec.googlecode.com/svn/trunk@207 
d6e91ea2-e33a-0410-98df-1d493bd67c58
padraic.brady (author)
Sat Feb 02 16:36:48 -0800 2008
commit  0e429e950e32fd23be80cb5493eaa53c8b0ef4b0
tree    bfb16f7d0d7a524fa422b2f2d1a6ec0d553b4206
parent  76484f9644b8361a014fca80bea6bcc6214b0b72
...
1
2
3
 
4
5
6
...
1
2
3
4
5
6
7
0
@@ -1,6 +1,7 @@
0
 <?php
0
 
0
 require_once 'SpecHelper.php';
0
+require_once 'PHPSpec.php';
0
 
0
 $options = new stdClass;
0
 $options->recursive = true;
...
2
3
4
 
 
5
6
7
...
14
15
16
17
 
 
18
19
20
...
24
25
26
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
30
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
33
34
 
 
 
 
35
36
37
38
...
2
3
4
5
6
7
8
9
...
16
17
18
 
19
20
21
22
23
...
27
28
29
 
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
 
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
0
@@ -2,6 +2,8 @@
0
 
0
 require_once 'SpecHelper.php';
0
 
0
+require_once dirname(__FILE__) . '/_zend/application/Bootstrap.php';
0
+
0
 class DescribeContextZend extends PHPSpec_Context
0
 {
0
 
0
@@ -14,7 +16,8 @@ class DescribeContextZend extends PHPSpec_Context
0
     public function itShouldCreateFrontControllerWhenInstantiated()
0
     {
0
         $context = new DescribeFooController;
0
- $this->spec($context->getFrontController())->should->beAnInstanceOf('Zend_Controller_Front');
0
+ $this->spec($context->getFrontController())->should
0
+ ->beAnInstanceOf('Zend_Controller_Front');
0
     }
0
 
0
     public function itShouldAllowSettingControllerManually()
0
@@ -24,14 +27,168 @@ class DescribeContextZend extends PHPSpec_Context
0
         $this->spec($context->getController())->should->be('Bar');
0
     }
0
 
0
- public function itShouldCreateRequestBeforeEachExample()
0
+ public function itShouldAllowSettingModuleDirs()
0
+ {
0
+ PHPSpec_Context_Zend::addModuleDirectory('/path/to/module');
0
+ $this->spec(PHPSpec_Context_Zend::getModuleDirectories())->should
0
+ ->be(array('/path/to/module'));
0
+ }
0
+
0
+ public function itShouldAllowSettingSetupCallbackFunction()
0
+ {
0
+ PHPSpec_Context_Zend::setFrontControllerSetupCallback(array('Bootstrap','prepare'));
0
+ $context = new DescribeFooController;
0
+ $context->beforeEach();
0
+ $this->spec(
0
+ Zend_Controller_Front::getInstance()->getControllerDirectory()
0
+ )->should->be(array('default'=>'./application/controllers'));
0
+ }
0
+
0
+ public function itShouldClearFrontControllerBeforeEachExample()
0
+ {
0
+ PHPSpec_Context_Zend::addModuleDirectory(
0
+ dirname(__FILE__) . DIRECTORY_SEPARATOR . '_modules'
0
+ );
0
+ $context = new DescribeFooController;
0
+ $context->beforeEach();
0
+ $this->spec(
0
+ Zend_Controller_Front::getInstance()->getControllerDirectory()
0
+ )->should->be(
0
+ array('Default'=>dirname(__FILE__) . DIRECTORY_SEPARATOR
0
+ . '_modules' . DIRECTORY_SEPARATOR
0
+ . 'Default' . DIRECTORY_SEPARATOR
0
+ . 'controllers')
0
+ );
0
+ }
0
+
0
+ public function itShouldFormulateAndDispatchGetRequest()
0
+ {
0
+ $this->setControllerDirectory();
0
+ $context = new DescribeFooController;
0
+ $context->beforeEach();
0
+ $context->setController('index');
0
+ $response = $context->get('index');
0
+ $this->spec($response)->should->match("/This is Index/");
0
+ }
0
+
0
+ public function itShouldFormulateAndDispatchPostRequest()
0
+ {
0
+ $this->setControllerDirectory();
0
+ $context = new DescribeFooController;
0
+ $context->beforeEach();
0
+ $context->setController('index');
0
+ $response = $context->post('index');
0
+ $this->spec($response)->should->match("/This is Index/");
0
+ }
0
+
0
+ public function itShouldPreserveInstanceOfPhpspecRequest()
0
+ {
0
+ $this->setControllerDirectory();
0
+ $context = new DescribeFooController;
0
+ $context->beforeEach();
0
+ $context->setController('index');
0
+ $response = $context->get('index');
0
+ $this->spec($context->request())->should->beAnInstanceOf('Zend_Controller_Request_Http');
0
+ }
0
+
0
+ public function itShouldReturnInstanceOfPhpspecResponseFromRequest()
0
+ {
0
+ $this->setControllerDirectory();
0
+ $context = new DescribeFooController;
0
+ $context->beforeEach();
0
+ $context->setController('index');
0
+ $response = $context->get('index');
0
+ $this->spec($response)->should->beAnInstanceOf('PHPSpec_Context_Zend_Response');
0
+ }
0
+
0
+ public function itShouldPreserveInstanceOfPhpspecResponse()
0
     {
0
+ $this->setControllerDirectory();
0
         $context = new DescribeFooController;
0
         $context->beforeEach();
0
- $this->spec($context->request())->should->beAnInstanceOf('Zend_Controller_Request_http');
0
+ $context->setController('index');
0
+ $context->get('index');
0
+ $this->spec($context->response())
0
+ ->should->beAnInstanceOf('PHPSpec_Context_Zend_Response');
0
+ }
0
+
0
+ public function itShouldFormulateAndDispatchRequestWithUserParams()
0
+ {
0
+ $this->setControllerDirectory();
0
+ $context = new DescribeFooController;
0
+ $context->beforeEach();
0
+ $context->setController('index');
0
+ $response = $context->get('userparam', array(), array('text'=>'This is User Param'));
0
+ $this->spec($response)->should->match("/This is User Param/");
0
+ }
0
+
0
+ public function itShouldDispatchARelativeUriPath()
0
+ {
0
+ $this->setControllerDirectory();
0
+ $context = new DescribeFooController;
0
+ $context->beforeEach();
0
+ $response = $context->post('/index/userparam/text/userparampage');
0
+ $this->spec($response)->should->match("/userparampage/");
0
+ }
0
+
0
+ public function itShouldDispatchRelativePathWithoutOpeningSlash()
0
+ {
0
+ $this->setControllerDirectory();
0
+ $context = new DescribeFooController;
0
+ $context->beforeEach();
0
+ $response = $context->post('index/userparam/text/userparampage');
0
+ $this->spec($response)->should->match("/userparampage/");
0
+ }
0
+
0
+ public function itShouldAttachBesuccessMatcherToResponse()
0
+ {
0
+ $context = new DescribeFooController;
0
+ $response = new PHPSpec_Context_Zend_Response;
0
+ $response->setContext($context);
0
+ $response->setHttpResponseCode(200);
0
+ $response->should->beSuccess();
0
+ }
0
+
0
+ public function itShouldAttachBesuccessMatcherToResponseAndFailIfNo200ResponseCode()
0
+ {
0
+ $context = new DescribeFooController;
0
+ $response = new PHPSpec_Context_Zend_Response;
0
+ $response->setContext($context);
0
+ $response->setHttpResponseCode(300);
0
+ $response->shouldNot->beSuccess();
0
+ }
0
+
0
+ public function itShouldAttachHavetextMatcherToResponse()
0
+ {
0
+ $context = new DescribeFooController;
0
+ $response = new PHPSpec_Context_Zend_Response;
0
+ $response->setContext($context);
0
+ $response->setBody('I Am Text');
0
+ $response->should->haveText('I Am Text');
0
+ }
0
+
0
+ public function after()
0
+ {
0
+ PHPSpec_Context_Zend::clearModuleDirectories();
0
+ PHPSpec_Context_Zend::clearControllerDirectories();
0
+ PHPSpec_Context_Zend::clearFrontControllerSetupCallback();
0
+ }
0
+
0
+ public function setControllerDirectory()
0
+ {
0
+ PHPSpec_Context_Zend::addControllerDirectory(
0
+ dirname(__FILE__)
0
+ . DIRECTORY_SEPARATOR . '_zend'
0
+ . DIRECTORY_SEPARATOR . 'application'
0
+ . DIRECTORY_SEPARATOR . 'controllers'
0
+ );
0
     }
0
 }
0
 
0
+/**
0
+ * DescribeFooController is just an entry point. The actual controller
0
+ * is manually set so we don't need subclass bloat for specs
0
+ */
0
 class DescribeFooController extends PHPSpec_Context_Zend
0
 {
0
 }
0
\ No newline at end of file
...
14
15
16
17
 
18
19
20
21
22
23
24
 
25
26
27
...
14
15
16
 
17
18
19
20
21
22
23
 
24
25
26
27
0
@@ -14,14 +14,14 @@
0
  *
0
  * @category PHPSpec
0
  * @package PHPSpec
0
- * @copyright Copyright (c) 2007 Pdraic Brady, Travis Swicegood
0
+ * @copyright Copyright (c) 2007 Pádraic Brady, Travis Swicegood
0
  * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
0
  */
0
 
0
 /**
0
  * @category PHPSpec
0
  * @package PHPSpec
0
- * @copyright Copyright (c) 2007 Pdraic Brady, Travis Swicegood
0
+ * @copyright Copyright (c) 2007 Pádraic Brady, Travis Swicegood
0
  * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
0
  */
0
 class PHPSpec_Context implements Countable
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
108
 
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
143
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
 
161
162
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
0
@@ -1,142 +1,232 @@
0
-<?php
0
-/**
0
- * PHPSpec
0
- *
0
- * LICENSE
0
- *
0
- * This file is subject to the GNU Lesser General Public License Version 3
0
- * that is bundled with this package in the file LICENSE.
0
- * It is also available through the world-wide-web at this URL:
0
- * http://www.gnu.org/licenses/lgpl-3.0.txt
0
- * If you did not receive a copy of the license and are unable to
0
- * obtain it through the world-wide-web, please send an email
0
- * to license@phpspec.org so we can send you a copy immediately.
0
- *
0
- * @category PHPSpec
0
- * @package PHPSpec
0
- * @copyright Copyright (c) 2007 Pádraic Brady, Travis Swicegood
0
- * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
0
- */
0
-
0
-require_once 'Zend/Controller/Front.php';
0
-require_once 'Zend/Controller/Request/Http.php';
0
-
0
-/**
0
- * @category PHPSpec
0
- * @package PHPSpec
0
- * @copyright Copyright (c) 2007 Pádraic Brady, Travis Swicegood
0
- * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
0
- */
0
-class PHPSpec_Context_Zend extends PHPSpec_Context
0
-{
0
-
0
- protected static $_moduleDirectories = array();
0
-
0
- protected $_controller = '';
0
-
0
- /**
0
- * Zend Framework; instance of Front Controller
0
- *
0
- * @var Zend_Controller_Front
0
- */
0
- protected $_frontController = null;
0
-
0
- /**
0
- * Zend Framework; instance of HTTP Request
0
- *
0
- * @var Zend_Controller_Request_Http
0
- */
0
- protected $_request = null;
0
-
0
- /**
0
- * Zend Framework; instance of HTTP Response
0
- *
0
- * @var Zend_Controller_Response_Http
0
- */
0
- protected $_response = null;
0
-
0
- public function __construct()
0
- {
0
- parent::__construct();
0
- $this->_setController();
0
- $this->_frontController = Zend_Controller_Front::getInstance();
0
- }
0
-
0
- public static function addModuleDirectory($path)
0
- {
0
- self::$_moduleDirectories[] = $path;
0
- }
0
-
0
- public static function getModuleDirectories()
0
- {
0
- return self::$_moduleDirectories;
0
- }
0
-
0
- public function beforeEach()
0
- {
0
- $this->_request = new Zend_Controller_Request_Http;
0
- $this->_clearFrontController();
0
- }
0
-
0
- public function get($actionName, array $getArray = null, array $paramArray = null)
0
- {
0
- $this->request()->setControllerName($this->getController());
0
- $this->request()->setActionName($actionName);
0
+<?php
0
+/**
0
+ * PHPSpec
0
+ *
0
+ * LICENSE
0
+ *
0
+ * This file is subject to the GNU Lesser General Public License Version 3
0
+ * that is bundled with this package in the file LICENSE.
0
+ * It is also available through the world-wide-web at this URL:
0
+ * http://www.gnu.org/licenses/lgpl-3.0.txt
0
+ * If you did not receive a copy of the license and are unable to
0
+ * obtain it through the world-wide-web, please send an email
0
+ * to license@phpspec.org so we can send you a copy immediately.
0
+ *
0
+ * @category PHPSpec
0
+ * @package PHPSpec
0
+ * @copyright Copyright (c) 2007 Pádraic Brady, Travis Swicegood
0
+ * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
0
+ */
0
+
0
+require_once 'Zend/Controller/Front.php';
0
+
0
+require_once 'Zend/Controller/Request/Http.php';
0
+
0
+/**
0
+ * @category PHPSpec
0
+ * @package PHPSpec
0
+ * @copyright Copyright (c) 2007 Pádraic Brady, Travis Swicegood
0
+ * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
0
+ */
0
+class PHPSpec_Context_Zend extends PHPSpec_Context
0
+{
0
+
0
+ const BASE_URL = 'http://www.example.com';
0
+
0
+ protected static $_moduleDirectories = array();
0
+
0
+ protected static $_controllerDirectories = array();
0
+
0
+ protected static $_frontControllerSetupCallback = null;
0
+
0
+ /**
0
+ * Name of the Controller being specified; captured usually
0
+ * from the Context classname.
0
+ *
0
+ * @var string
0
+ */
0
+ protected $_controller = '';
0
+
0
+ /**
0
+ * Zend Framework; instance of Front Controller
0
+ *
0
+ * @var Zend_Controller_Front
0
+ */
0
+ protected $_frontController = null;
0
+
0
+ /**
0
+ * Zend Framework; instance of HTTP Request
0
+ *
0
+ * @var Zend_Controller_Request_Http
0
+ */
0
+ protected $_request = null;
0
+
0
+ /**
0
+ * Zend Framework; instance of HTTP Response
0
+ *
0
+ * @var Zend_Controller_Response_Http
0
+ */
0
+ protected $_response = null;
0
+
0
+ public function __construct()
0
+ {
0
+ parent::__construct();
0
+ $this->_setController();
0
+ $this->_frontController = Zend_Controller_Front::getInstance();
0
+ }
0
+
0
+ public static function setFrontControllerSetupCallback($callback)
0
+ {
0
+ self::$_frontControllerSetupCallback = $callback;
0
+ }
0
+
0
+ public static function clearFrontControllerSetupCallback()
0
+ {
0
+ self::$_frontControllerSetupCallback = null;
0
+ }
0
+
0
+ public static function addModuleDirectory($path)
0
+ {
0
+ self::$_moduleDirectories[] = $path;
0
+ }
0
+
0
+ public static function getModuleDirectories()
0
+ {
0
+ return self::$_moduleDirectories;
0
+ }
0
+
0
+ public static function clearModuleDirectories()
0
+ {
0
+ self::$_moduleDirectories = array();
0
+ }
0
+
0
+ public static function addControllerDirectory($path, $module = null)
0
+ {
0
+ if (!isset($module)) {
0
+ $module = 'NULL';
0
+ }
0
+
0
+ self::$_controllerDirectories[$module] = $path;
0
+ }
0
+
0
+ public static function getControllerDirectories()
0
+ {
0
+ return self::$_controllerDirectories;
0
+ }
0
+
0
+ public static function clearControllerDirectories()
0
+ {
0
+ self::$_controllerDirectories = array();
0
+ }
0
+
0
+ public function beforeEach()
0
+ {
0
+ $_GET = array();
0
+ $_POST = array();
0
+ $_COOKIE = array();
0
+ $this->_clearFrontController();
0
+ }
0
+
0
+ public function get($actionName, array $getArray = null, array $paramArray = null)
0
+ {
0
         if (!empty($getArray)) {
0
- $this->request()->setParams($getArray); // override later with subclass!
0
- }
0
- if (!empty($paramArray)) {
0
- $this->request()->setParams($paramArray);
0
- }
0
- $this->_response = $this->_frontController->dispatch($this->request());
0
- return $this->response();
0
- }
0
-
0
- /**
0
- * Returns current Request_Http object
0
- *
0
- * @return Zend_Controller_Request_Http
0
- */
0
- public function request()
0
- {
0
- return $this->_request;
0
- }
0
-
0
- public function response()
0
- {
0
+ $_GET = $getArray;
0
+ }
0
+ $this->_response = $this->_makeRequest($actionName, $paramArray);
0
+ return $this->response();
0
+ }
0
+
0
+ public function post($actionName, array $postArray = null, array $paramArray = null)
0
+ {
0
+ if (!empty($postArray)) {
0
+ $_POST = $postArray;
0
+ }
0
+ $this->_response = $this->_makeRequest($actionName, $paramArray);
0
+ return $this->response();
0
+ }
0
+
0
+ /**
0
+ * Returns current Request_Http object
0
+ *
0
+ * @return Zend_Controller_Request_Http
0
+ */
0
+ public function request()
0
+ {
0
+ return $this->_request;
0
+ }
0
+
0
+ public function response()
0
+ {
0
         if (!isset($this->_response)) {
0
- throw new PHPSpec_Exception('No response has been retrieved yet;
0
+ throw new PHPSpec_Exception('No response has been retrieved yet;
0
           make a get or post request first');
0
- }
0
- return $this->_response;
0
- }
0
-
0
- public function setController($controllerName)
0
- {
0
- $this->_controller = $controllerName;
0
- }
0
-
0
- public function getController()
0
- {
0
- return $this->_controller;
0
- }
0
-
0
- public function getFrontController()
0
- {
0
- return $this->_frontController;
0
- }
0
-
0
- protected function _clearFrontController() {
0
- $this->_frontController->resetInstance();
0
- $this->_frontController->returnResponse(true);
0
- foreach (self::getModuleDirectories() as $path) {
0
- $this->_frontController->addModuleDirectory($path);
0
- }
0
- }
0
-
0
- protected function _setController()
0
- {
0
- $this->_controller = substr(get_class($this), 8, strlen(substr(get_class($this), 8))-10);
0
- }
0
-
0
+ }
0
+ return $this->_response;
0
+ }
0
+
0
+ public function setController($controllerName)
0
+ {
0
+ $this->_controller = $controllerName;
0
+ }
0
+
0
+ public function getController()
0
+ {
0
+ return $this->_controller;
0
+ }
0
+
0
+ public function getFrontController()
0
+ {
0
+ return $this->_frontController;
0
+ }
0
+
0
+ protected function _makeRequest($actionName, array $paramArray = null)
0
+ {
0
+ if (preg_match("%/%", $actionName)) {
0
+ $uri = self::BASE_URL
0
+ . (substr($actionName, 0, 1) == '/' ? $actionName : '/' . $actionName);
0
+ } else {
0
+ $uri = self::BASE_URL . '/' . $this->getController()
0
+ . (!empty($actionName) ? '/' . $actionName : '');
0
+ }
0
+ $this->_request = new Zend_Controller_Request_Http($uri);
0
+ if (!empty($paramArray)) {
0
+ $this->request()->setParams($paramArray);
0
+ }
0
+ $response = $this->_frontController->dispatch(
0
+ $this->request(),
0
+ new PHPSpec_Context_Zend_Response
0
+ );
0
+ $response->setContext($this);
0
+ return $response;
0
+ }
0
+
0
+ protected function _clearFrontController() {
0
+ $this->_frontController->resetInstance();
0
+ if (count(self::$_frontControllerSetupCallback) > 0) {
0
+ call_user_func(array(
0
+ self::$_frontControllerSetupCallback[0],
0
+ self::$_frontControllerSetupCallback[1]
0
+ ));
0
+ } else {
0
+ $this->_frontController->returnResponse(true);
0
+ $this->_frontController->throwExceptions(true);
0
+ foreach (self::getControllerDirectories() as $module=>$path) {
0
+ if ($module == 'NULL') {
0
+ $module = null;
0
+ }
0
+ $this->_frontController->addControllerDirectory($path, $module);
0
+ }
0
+ foreach (self::getModuleDirectories() as $path) {
0
+ $this->_frontController->addModuleDirectory($path);
0
+ }
0
+ }
0
+
0
+ }
0
+
0
+ protected function _setController()
0
+ {
0
+ $controllerClassName = substr(get_class($this), 8);
0
+ $this->_controller = substr($controllerClassName, 0, strlen($controllerClassName)-10);
0
+ }
0
+
0
 }
0
\ No newline at end of file
...
38
39
40
41
 
 
 
 
 
 
42
43
44
...
38
39
40
 
41
42
43
44
45
46
47
48
49
0
@@ -38,7 +38,12 @@ class PHPSpec_Framework
0
             return false;
0
         }
0
         $path = dirname(dirname(__FILE__));
0
- include_once $path . '/' . str_replace('_', '/', $class) . '.php';
0
+ $file = $path . '/' . str_replace('_', '/', $class) . '.php';
0
+ if (!file_exists($file)) {
0
+ throw new PHPSpec_Exception('include_once("' . $file . '"): file does not exist');
0
+ } else {
0
+ include_once $file;
0
+ }
0
     }
0
 
0
 }
...
122
123
124
125
 
 
 
126
127
128
...
338
339
340
 
341
342
343
344
345
 
 
 
 
 
 
 
 
346
347
348
...
122
123
124
 
125
126
127
128
129
130
...
340
341
342
343
344
345
346
347
 
348
349
350
351
352
353
354
355
356
357
358
0
@@ -122,7 +122,9 @@ class PHPSpec_Specification
0
 
0
         // check for Matcher references
0
         $matchers = array(
0
- 'equal', 'be', 'beEqualTo', 'beAnInstanceOf', 'beGreaterThan', 'beTrue', 'beFalse', 'beEmpty', 'beLessThan', 'beGreaterThanOrEqualTo', 'beLessThanOrEqualTo', 'beSet', 'beNull', 'beOfType', 'beIdenticalTo', 'match', 'throw'
0
+ 'equal', 'be', 'beEqualTo', 'beAnInstanceOf', 'beGreaterThan', 'beTrue', 'beFalse', 'beEmpty', 'beLessThan', 'beGreaterThanOrEqualTo', 'beLessThanOrEqualTo', 'beSet', 'beNull', 'beOfType', 'beIdenticalTo', 'match', 'throw',
0
+
0
+ 'beSuccess', 'haveText'
0
         );
0
         if (in_array($method, $matchers)) {
0
             $this->setExpectedValue(array_shift($args));
0
@@ -338,11 +340,19 @@ class PHPSpec_Specification
0
      *
0
      * @param DSL method call which was found to be a Matcher reference
0
      * @return null
0
+ * @todo Refactor Matcher inclusion into a more extensible system
0
      */
0
     protected function _createMatcher($method)
0
     {
0
         $matcherClass = 'PHPSpec_Matcher_' . ucfirst($method);
0
- $this->_matcher = new $matcherClass( $this->getExpectedValue() );
0
+ try {
0
+ if (class_exists($matcherClass, true)) {
0
+ $this->_matcher = new $matcherClass( $this->getExpectedValue() );
0
+ }
0
+ } catch (PHPSpec_Exception $e) {
0
+ $matcherClass = 'PHPSpec_Context_Zend_Matcher_' . ucfirst($method);
0
+ $this->_matcher = new $matcherClass( $this->getExpectedValue() );
0
+ }
0
     }
0
 
0
     /**

Comments

    No one has commented yet.