Diff
Property changes:
Name: svk:merge
- d6e91ea2-e33a-0410-98df-1d493bd67c58:/:206
+ d6e91ea2-e33a-0410-98df-1d493bd67c58:/:207
Modified: trunk/specs/AllSpecs.php (206 => 207)
--- trunk/specs/AllSpecs.php 2008-01-18 15:00:13 UTC (rev 206)
+++ trunk/specs/AllSpecs.php 2008-02-03 00:37:24 UTC (rev 207)
@@ -1,6 +1,7 @@
<?php
require_once 'SpecHelper.php';
+require_once 'PHPSpec.php';
$options = new stdClass;
$options->recursive = true;
Modified: trunk/specs/ContextZendSpec.php (206 => 207)
--- trunk/specs/ContextZendSpec.php 2008-01-18 15:00:13 UTC (rev 206)
+++ trunk/specs/ContextZendSpec.php 2008-02-03 00:37:24 UTC (rev 207)
@@ -2,6 +2,8 @@
require_once 'SpecHelper.php';
+require_once dirname(__FILE__) . '/_zend/application/Bootstrap.php';
+
class DescribeContextZend extends PHPSpec_Context
{
@@ -14,7 +16,8 @@
public function itShouldCreateFrontControllerWhenInstantiated()
{
$context = new DescribeFooController;
- $this->spec($context->getFrontController())->should->beAnInstanceOf('Zend_Controller_Front');
+ $this->spec($context->getFrontController())->should
+ ->beAnInstanceOf('Zend_Controller_Front');
}
public function itShouldAllowSettingControllerManually()
@@ -24,14 +27,168 @@
$this->spec($context->getController())->should->be('Bar');
}
- public function itShouldCreateRequestBeforeEachExample()
+ public function itShouldAllowSettingModuleDirs()
{
+ PHPSpec_Context_Zend::addModuleDirectory('/path/to/module');
+ $this->spec(PHPSpec_Context_Zend::getModuleDirectories())->should
+ ->be(array('/path/to/module'));
+ }
+
+ public function itShouldAllowSettingSetupCallbackFunction()
+ {
+ PHPSpec_Context_Zend::setFrontControllerSetupCallback(array('Bootstrap','prepare'));
$context = new DescribeFooController;
$context->beforeEach();
- $this->spec($context->request())->should->beAnInstanceOf('Zend_Controller_Request_http');
+ $this->spec(
+ Zend_Controller_Front::getInstance()->getControllerDirectory()
+ )->should->be(array('default'=>'./application/controllers'));
}
+
+ public function itShouldClearFrontControllerBeforeEachExample()
+ {
+ PHPSpec_Context_Zend::addModuleDirectory(
+ dirname(__FILE__) . DIRECTORY_SEPARATOR . '_modules'
+ );
+ $context = new DescribeFooController;
+ $context->beforeEach();
+ $this->spec(
+ Zend_Controller_Front::getInstance()->getControllerDirectory()
+ )->should->be(
+ array('Default'=>dirname(__FILE__) . DIRECTORY_SEPARATOR
+ . '_modules' . DIRECTORY_SEPARATOR
+ . 'Default' . DIRECTORY_SEPARATOR
+ . 'controllers')
+ );
+ }
+
+ public function itShouldFormulateAndDispatchGetRequest()
+ {
+ $this->setControllerDirectory();
+ $context = new DescribeFooController;
+ $context->beforeEach();
+ $context->setController('index');
+ $response = $context->get('index');
+ $this->spec($response)->should->match("/This is Index/");
+ }
+
+ public function itShouldFormulateAndDispatchPostRequest()
+ {
+ $this->setControllerDirectory();
+ $context = new DescribeFooController;
+ $context->beforeEach();
+ $context->setController('index');
+ $response = $context->post('index');
+ $this->spec($response)->should->match("/This is Index/");
+ }
+
+ public function itShouldPreserveInstanceOfPhpspecRequest()
+ {
+ $this->setControllerDirectory();
+ $context = new DescribeFooController;
+ $context->beforeEach();
+ $context->setController('index');
+ $response = $context->get('index');
+ $this->spec($context->request())->should->beAnInstanceOf('Zend_Controller_Request_Http');
+ }
+
+ public function itShouldReturnInstanceOfPhpspecResponseFromRequest()
+ {
+ $this->setControllerDirectory();
+ $context = new DescribeFooController;
+ $context->beforeEach();
+ $context->setController('index');
+ $response = $context->get('index');
+ $this->spec($response)->should->beAnInstanceOf('PHPSpec_Context_Zend_Response');
+ }
+
+ public function itShouldPreserveInstanceOfPhpspecResponse()
+ {
+ $this->setControllerDirectory();
+ $context = new DescribeFooController;
+ $context->beforeEach();
+ $context->setController('index');
+ $context->get('index');
+ $this->spec($context->response())
+ ->should->beAnInstanceOf('PHPSpec_Context_Zend_Response');
+ }
+
+ public function itShouldFormulateAndDispatchRequestWithUserParams()
+ {
+ $this->setControllerDirectory();
+ $context = new DescribeFooController;
+ $context->beforeEach();
+ $context->setController('index');
+ $response = $context->get('userparam', array(), array('text'=>'This is User Param'));
+ $this->spec($response)->should->match("/This is User Param/");
+ }
+
+ public function itShouldDispatchARelativeUriPath()
+ {
+ $this->setControllerDirectory();
+ $context = new DescribeFooController;
+ $context->beforeEach();
+ $response = $context->post('/index/userparam/text/userparampage');
+ $this->spec($response)->should->match("/userparampage/");
+ }
+
+ public function itShouldDispatchRelativePathWithoutOpeningSlash()
+ {
+ $this->setControllerDirectory();
+ $context = new DescribeFooController;
+ $context->beforeEach();
+ $response = $context->post('index/userparam/text/userparampage');
+ $this->spec($response)->should->match("/userparampage/");
+ }
+
+ public function itShouldAttachBesuccessMatcherToResponse()
+ {
+ $context = new DescribeFooController;
+ $response = new PHPSpec_Context_Zend_Response;
+ $response->setContext($context);
+ $response->setHttpResponseCode(200);
+ $response->should->beSuccess();
+ }
+
+ public function itShouldAttachBesuccessMatcherToResponseAndFailIfNo200ResponseCode()
+ {
+ $context = new DescribeFooController;
+ $response = new PHPSpec_Context_Zend_Response;
+ $response->setContext($context);
+ $response->setHttpResponseCode(300);
+ $response->shouldNot->beSuccess();
+ }
+
+ public function itShouldAttachHavetextMatcherToResponse()
+ {
+ $context = new DescribeFooController;
+ $response = new PHPSpec_Context_Zend_Response;
+ $response->setContext($context);
+ $response->setBody('I Am Text');
+ $response->should->haveText('I Am Text');
+ }
+
+ public function after()
+ {
+ PHPSpec_Context_Zend::clearModuleDirectories();
+ PHPSpec_Context_Zend::clearControllerDirectories();
+ PHPSpec_Context_Zend::clearFrontControllerSetupCallback();
+ }
+
+ public function setControllerDirectory()
+ {
+ PHPSpec_Context_Zend::addControllerDirectory(
+ dirname(__FILE__)
+ . DIRECTORY_SEPARATOR . '_zend'
+ . DIRECTORY_SEPARATOR . 'application'
+ . DIRECTORY_SEPARATOR . 'controllers'
+ );
+ }
}
+/**
+ * DescribeFooController is just an entry point. The actual controller
+ * is manually set so we don't need subclass bloat for specs
+ */
class DescribeFooController extends PHPSpec_Context_Zend
{
}
\ No newline at end of file
Modified: trunk/src/PHPSpec/Context/Zend.php (206 => 207)
--- trunk/src/PHPSpec/Context/Zend.php 2008-01-18 15:00:13 UTC (rev 206)
+++ trunk/src/PHPSpec/Context/Zend.php 2008-02-03 00:37:24 UTC (rev 207)
@@ -1,142 +1,232 @@
-<?php
-/**
- * PHPSpec
- *
- * LICENSE
- *
- * This file is subject to the GNU Lesser General Public License Version 3
- * that is bundled with this package in the file LICENSE.
- * It is also available through the world-wide-web at this URL:
- * http://www.gnu.org/licenses/lgpl-3.0.txt
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to lic...@phpspec.org so we can send you a copy immediately.
- *
- * @category PHPSpec
- * @package PHPSpec
- * @copyright Copyright (c) 2007 Pádraic Brady, Travis Swicegood
- * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
- */
-
-require_once 'Zend/Controller/Front.php';
-require_once 'Zend/Controller/Request/Http.php';
-
-/**
- * @category PHPSpec
- * @package PHPSpec
- * @copyright Copyright (c) 2007 Pádraic Brady, Travis Swicegood
- * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
- */
-class PHPSpec_Context_Zend extends PHPSpec_Context
-{
-
- protected static $_moduleDirectories = array();
-
- protected $_controller = '';
-
- /**
- * Zend Framework; instance of Front Controller
- *
- * @var Zend_Controller_Front
- */
- protected $_frontController = null;
-
- /**
- * Zend Framework; instance of HTTP Request
- *
- * @var Zend_Controller_Request_Http
- */
- protected $_request = null;
-
- /**
- * Zend Framework; instance of HTTP Response
- *
- * @var Zend_Controller_Response_Http
- */
- protected $_response = null;
-
- public function __construct()
- {
- parent::__construct();
- $this->_setController();
- $this->_frontController = Zend_Controller_Front::getInstance();
- }
-
- public static function addModuleDirectory($path)
- {
- self::$_moduleDirectories[] = $path;
- }
-
- public static function getModuleDirectories()
- {
- return self::$_moduleDirectories;
- }
-
- public function beforeEach()
- {
- $this->_request = new Zend_Controller_Request_Http;
- $this->_clearFrontController();
- }
-
- public function get($actionName, array $getArray = null, array $paramArray = null)
- {
- $this->request()->setControllerName($this->getController());
- $this->request()->setActionName($actionName);
+<?php
+/**
+ * PHPSpec
+ *
+ * LICENSE
+ *
+ * This file is subject to the GNU Lesser General Public License Version 3
+ * that is bundled with this package in the file LICENSE.
+ * It is also available through the world-wide-web at this URL:
+ * http://www.gnu.org/licenses/lgpl-3.0.txt
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to lic...@phpspec.org so we can send you a copy immediately.
+ *
+ * @category PHPSpec
+ * @package PHPSpec
+ * @copyright Copyright (c) 2007 Pádraic Brady, Travis Swicegood
+ * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
+ */
+
+require_once 'Zend/Controller/Front.php';
+
+require_once 'Zend/Controller/Request/Http.php';
+
+/**
+ * @category PHPSpec
+ * @package PHPSpec
+ * @copyright Copyright (c) 2007 Pádraic Brady, Travis Swicegood
+ * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
+ */
+class PHPSpec_Context_Zend extends PHPSpec_Context
+{
+
+ const BASE_URL = 'http://www.example.com';
+
+ protected static $_moduleDirectories = array();
+
+ protected static $_controllerDirectories = array();
+
+ protected static $_frontControllerSetupCallback = null;
+
+ /**
+ * Name of the Controller being specified; captured usually
+ * from the Context classname.
+ *
+ * @var string
+ */
+ protected $_controller = '';
+
+ /**
+ * Zend Framework; instance of Front Controller
+ *
+ * @var Zend_Controller_Front
+ */
+ protected $_frontController = null;
+
+ /**
+ * Zend Framework; instance of HTTP Request
+ *
+ * @var Zend_Controller_Request_Http
+ */
+ protected $_request = null;
+
+ /**
+ * Zend Framework; instance of HTTP Response
+ *
+ * @var Zend_Controller_Response_Http
+ */
+ protected $_response = null;
+
+ public function __construct()
+ {
+ parent::__construct();
+ $this->_setController();
+ $this->_frontController = Zend_Controller_Front::getInstance();
+ }
+
+ public static function setFrontControllerSetupCallback($callback)
+ {
+ self::$_frontControllerSetupCallback = $callback;
+ }
+
+ public static function clearFrontControllerSetupCallback()
+ {
+ self::$_frontControllerSetupCallback = null;
+ }
+
+ public static function addModuleDirectory($path)
+ {
+ self::$_moduleDirectories[] = $path;
+ }
+
+ public static function getModuleDirectories()
+ {
+ return self::$_moduleDirectories;
+ }
+
+ public static function clearModuleDirectories()
+ {
+ self::$_moduleDirectories = array();
+ }
+
+ public static function addControllerDirectory($path, $module = null)
+ {
+ if (!isset($module)) {
+ $module = 'NULL';
+ }
+
+ self::$_controllerDirectories[$module] = $path;
+ }
+
+ public static function getControllerDirectories()
+ {
+ return self::$_controllerDirectories;
+ }
+
+ public static function clearControllerDirectories()
+ {
+ self::$_controllerDirectories = array();
+ }
+
+ public function beforeEach()
+ {
+ $_GET = array();
+ $_POST = array();
+ $_COOKIE = array();
+ $this->_clearFrontController();
+ }
+
+ public function get($actionName, array $getArray = null, array $paramArray = null)
+ {
if (!empty($getArray)) {
- $this->request()->setParams($getArray); // override later with subclass!
- }
- if (!empty($paramArray)) {
- $this->request()->setParams($paramArray);
- }
- $this->_response = $this->_frontController->dispatch($this->request());
- return $this->response();
- }
-
- /**
- * Returns current Request_Http object
- *
- * @return Zend_Controller_Request_Http
- */
- public function request()
- {
- return $this->_request;
- }
-
- public function response()
- {
+ $_GET = $getArray;
+ }
+ $this->_response = $this->_makeRequest($actionName, $paramArray);
+ return $this->response();
+ }
+
+ public function post($actionName, array $postArray = null, array $paramArray = null)
+ {
+ if (!empty($postArray)) {
+ $_POST = $postArray;
+ }
+ $this->_response = $this->_makeRequest($actionName, $paramArray);
+ return $this->response();
+ }
+
+ /**
+ * Returns current Request_Http object
+ *
+ * @return Zend_Controller_Request_Http
+ */
+ public function request()
+ {
+ return $this->_request;
+ }
+
+ public function response()
+ {
if (!isset($this->_response)) {
- throw new PHPSpec_Exception('No response has been retrieved yet;
+ throw new PHPSpec_Exception('No response has been retrieved yet;
make a get or post request first');
- }
- return $this->_response;
- }
-
- public function setController($controllerName)
- {
- $this->_controller = $controllerName;
- }
-
- public function getController()
- {
- return $this->_controller;
- }
-
- public function getFrontController()
- {
- return $this->_frontController;
- }
-
- protected function _clearFrontController() {
- $this->_frontController->resetInstance();
- $this->_frontController->returnResponse(true);
- foreach (self::getModuleDirectories() as $path) {
- $this->_frontController->addModuleDirectory($path);
- }
- }
-
- protected function _setController()
- {
- $this->_controller = substr(get_class($this), 8, strlen(substr(get_class($this), 8))-10);
- }
-
+ }
+ return $this->_response;
+ }
+
+ public function setController($controllerName)
+ {
+ $this->_controller = $controllerName;
+ }
+
+ public function getController()
+ {
+ return $this->_controller;
+ }
+
+ public function getFrontController()
+ {
+ return $this->_frontController;
+ }
+
+ protected function _makeRequest($actionName, array $paramArray = null)
+ {
+ if (preg_match("%/%", $actionName)) {
+ $uri = self::BASE_URL
+ . (substr($actionName, 0, 1) == '/' ? $actionName : '/' . $actionName);
+ } else {
+ $uri = self::BASE_URL . '/' . $this->getController()
+ . (!empty($actionName) ? '/' . $actionName : '');
+ }
+ $this->_request = new Zend_Controller_Request_Http($uri);
+ if (!empty($paramArray)) {
+ $this->request()->setParams($paramArray);
+ }
+ $response = $this->_frontController->dispatch(
+ $this->request(),
+ new PHPSpec_Context_Zend_Response
+ );
+ $response->setContext($this);
+ return $response;
+ }
+
+ protected function _clearFrontController() {
+ $this->_frontController->resetInstance();
+ if (count(self::$_frontControllerSetupCallback) > 0) {
+ call_user_func(array(
+ self::$_frontControllerSetupCallback[0],
+ self::$_frontControllerSetupCallback[1]
+ ));
+ } else {
+ $this->_frontController->returnResponse(true);
+ $this->_frontController->throwExceptions(true);
+ foreach (self::getControllerDirectories() as $module=>$path) {
+ if ($module == 'NULL') {
+ $module = null;
+ }
+ $this->_frontController->addControllerDirectory($path, $module);
+ }
+ foreach (self::getModuleDirectories() as $path) {
+ $this->_frontController->addModuleDirectory($path);
+ }
+ }
+
+ }
+
+ protected function _setController()
+ {
+ $controllerClassName = substr(get_class($this), 8);
+ $this->_controller = substr($controllerClassName, 0, strlen($controllerClassName)-10);
+ }
+
}
\ No newline at end of file
Modified: trunk/src/PHPSpec/Context.php (206 => 207)
--- trunk/src/PHPSpec/Context.php 2008-01-18 15:00:13 UTC (rev 206)
+++ trunk/src/PHPSpec/Context.php 2008-02-03 00:37:24 UTC (rev 207)
@@ -14,14 +14,14 @@
*
* @category PHPSpec
* @package PHPSpec
- * @copyright Copyright (c) 2007 P�draic Brady, Travis Swicegood
+ * @copyright Copyright (c) 2007 Pádraic Brady, Travis Swicegood
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
*/
/**
* @category PHPSpec
* @package PHPSpec
- * @copyright Copyright (c) 2007 P�draic Brady, Travis Swicegood
+ * @copyright Copyright (c) 2007 Pádraic Brady, Travis Swicegood
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
*/
class PHPSpec_Context implements Countable
Modified: trunk/src/PHPSpec/Framework.php (206 => 207)
--- trunk/src/PHPSpec/Framework.php 2008-01-18 15:00:13 UTC (rev 206)
+++ trunk/src/PHPSpec/Framework.php 2008-02-03 00:37:24 UTC (rev 207)
@@ -38,7 +38,12 @@
return false;
}
$path = dirname(dirname(__FILE__));
- include_once $path . '/' . str_replace('_', '/', $class) . '.php';
+ $file = $path . '/' . str_replace('_', '/', $class) . '.php';
+ if (!file_exists($file)) {
+ throw new PHPSpec_Exception('include_once("' . $file . '"): file does not exist');
+ } else {
+ include_once $file;
+ }
}
}
Copied: trunk/src/PHPSpec/Matcher/Match.php (from rev 195, branches/zend/src/PHPSpec/Matcher/Match.php) (0 => 207)
--- trunk/src/PHPSpec/Matcher/Match.php (rev 0)
+++ trunk/src/PHPSpec/Matcher/Match.php 2008-02-03 00:37:24 UTC (rev 207)
@@ -0,0 +1,59 @@
+<?php
+/**
+ * PHPSpec
+ *
+ * LICENSE
+ *
+ * This file is subject to the GNU Lesser General Public License Version 3
+ * that is bundled with this package in the file LICENSE.
+ * It is also available through the world-wide-web at this URL:
+ * http://www.gnu.org/licenses/lgpl-3.0.txt
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to lic...@phpspec.org so we can send you a copy immediately.
+ *
+ * @category PHPSpec
+ * @package PHPSpec
+ * @copyright Copyright (c) 2007 P\xE1draic Brady, Travis Swicegood
+ * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
+ */
+
+/**
+ * @category PHPSpec
+ * @package PHPSpec
+ * @copyright Copyright (c) 2007 P\xE1draic Brady, Travis Swicegood
+ * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
+ */
+class PHPSpec_Matcher_Match implements PHPSpec_Matcher_Interface
+{
+
+ protected $_expected = null;
+
+ protected $_actual = null;
+
+ public function __construct($expected)
+ {
+ $this->_expected = $expected;
+ }
+
+ public function matches($actual)
+ {
+ $this->_actual = $actual;
+ return (bool) preg_match($this->_expected, $this->_actual);
+ }
+
+ public function getFailureMessage()
+ {
+ return 'expected match for ' . strval($this->_expected) . ' PCRE regular expression, got ' . strval($this->_actual) . ' (using match())';
+ }
+
+ public function getNegativeFailureMessage()
+ {
+ return 'expected no match for ' . strval($this->_expected) . ' PCRE regular expression, got ' . strval($this->_actual) . ' (using match())';
+ }
+
+ public function getDescription()
+ {
+ return 'match ' . strval($this->_expected) . ' PCRE regular expression';
+ }
+}
\ No newline at end of file
Modified: trunk/src/PHPSpec/Specification.php (206 => 207)
--- trunk/src/PHPSpec/Specification.php 2008-01-18 15:00:13 UTC (rev 206)
+++ trunk/src/PHPSpec/Specification.php 2008-02-03 00:37:24 UTC (rev 207)
@@ -122,7 +122,9 @@
// check for Matcher references
$matchers = array(
- 'equal', 'be', 'beEqualTo', 'beAnInstanceOf', 'beGreaterThan', 'beTrue', 'beFalse', 'beEmpty', 'beLessThan', 'beGreaterThanOrEqualTo', 'beLessThanOrEqualTo', 'beSet', 'beNull', 'beOfType', 'beIdenticalTo', 'match', 'throw'
+ 'equal', 'be', 'beEqualTo', 'beAnInstanceOf', 'beGreaterThan', 'beTrue', 'beFalse', 'beEmpty', 'beLessThan', 'beGreaterThanOrEqualTo', 'beLessThanOrEqualTo', 'beSet', 'beNull', 'beOfType', 'beIdenticalTo', 'match', 'throw',
+
+ 'beSuccess', 'haveText'
);
if (in_array($method, $matchers)) {
$this->setExpectedValue(array_shift($args));
@@ -338,11 +340,19 @@
*
* @param DSL method call which was found to be a Matcher reference
* @return null
+ * @todo Refactor Matcher inclusion into a more extensible system
*/
protected function _createMatcher($method)
{
$matcherClass = 'PHPSpec_Matcher_' . ucfirst($method);
- $this->_matcher = new $matcherClass( $this->getExpectedValue() );
+ try {
+ if (class_exists($matcherClass, true)) {
+ $this->_matcher = new $matcherClass( $this->getExpectedValue() );
+ }
+ } catch (PHPSpec_Exception $e) {
+ $matcherClass = 'PHPSpec_Context_Zend_Matcher_' . ucfirst($method);
+ $this->_matcher = new $matcherClass( $this->getExpectedValue() );
+ }
}
/**
Copied: trunk/tests/Matcher/Match (from rev 195, branches/zend/tests/Matcher/Match)