Diff
Property changes:
Name: svk:merge
- d6e91ea2-e33a-0410-98df-1d493bd67c58:/:203
+ d6e91ea2-e33a-0410-98df-1d493bd67c58:/:204
Modified: trunk/build/build.xml (203 => 204)
--- trunk/build/build.xml 2008-01-16 17:35:15 UTC (rev 203)
+++ trunk/build/build.xml 2008-01-17 12:11:30 UTC (rev 204)
@@ -44,7 +44,7 @@
<property name="spec.src.default" value="${project.basedir}/.." />
<property name="spec.src.classpath" value="/src" />
<property name="spec.name" value="PHPSpec" />
- <property name="spec.version" value="0.2.3" /> <!-- VERSION FOR EDITING -->
+ <property name="spec.version" value="0.3.0devel" /> <!-- VERSION FOR EDITING -->
<property name="spec.stability" value="stable" />
<property name="spec.svn.baseurl" value="http://phpspec.googlecode.com/svn/" />
<property name="spec.svn.url" value="${svn.url}/trunk" />
@@ -207,6 +207,7 @@
<dirroles key="scripts">script</dirroles>
<dirroles key="tests">test</dirroles>
+ <dirroles key="tests">specs</dirroles>
<dirroles key="docs">doc</dirroles>
<replacement path="scripts/phpspec" type="pear-config" from="@php_bin@" to="php_bin" />
<replacement path="scripts/phpspec.bat" type="pear-config" from="@php_bin@" to="php_bin" />
@@ -216,6 +217,11 @@
<install as="phpspec.bat" name="scripts/phpspec.bat" />
</release>
+ <changelog version="0.3.0" date="${date}" license="LGPL">
+ * Added Zend Framework Context class to enable BDD
+ application to ZF Controller development
+ </changelog>
+
<changelog version="0.2.3" date="2008-01-11" license="LGPL">
* Patched a Predicate issue courtesy KUBO Atsuhiro
* Reminder to self that no regression testing coupled with
Copied: trunk/specs (from rev 203, branches/zend/specs)
Modified: trunk/specs/AllSpecs.php (203 => 204)
--- branches/zend/specs/AllSpecs.php 2008-01-16 17:35:15 UTC (rev 203)
+++ trunk/specs/AllSpecs.php 2008-01-17 12:11:30 UTC (rev 204)
@@ -1,7 +1,6 @@
<?php
require_once 'SpecHelper.php';
-require_once 'PHPSpec.php';
$options = new stdClass;
$options->recursive = true;
Modified: trunk/specs/ContextZendSpec.php (203 => 204)
--- branches/zend/specs/ContextZendSpec.php 2008-01-16 17:35:15 UTC (rev 203)
+++ trunk/specs/ContextZendSpec.php 2008-01-17 12:11:30 UTC (rev 204)
@@ -2,8 +2,6 @@
require_once 'SpecHelper.php';
-require_once dirname(__FILE__) . '/_zend/application/Bootstrap.php';
-
class DescribeContextZend extends PHPSpec_Context
{
@@ -16,8 +14,7 @@
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()
@@ -27,168 +24,14 @@
$this->spec($context->getController())->should->be('Bar');
}
- public function itShouldAllowSettingModuleDirs()
+ public function itShouldCreateRequestBeforeEachExample()
{
- 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(
- Zend_Controller_Front::getInstance()->getControllerDirectory()
- )->should->be(array('default'=>'./application/controllers'));
+ $this->spec($context->request())->should->beAnInstanceOf('Zend_Controller_Request_http');
}
-
- 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
Copied: trunk/src/PHPSpec/Context (from rev 203, branches/zend/src/PHPSpec/Context)
Modified: trunk/src/PHPSpec/Context/Zend.php (203 => 204)
--- branches/zend/src/PHPSpec/Context/Zend.php 2008-01-16 17:35:15 UTC (rev 203)
+++ trunk/src/PHPSpec/Context/Zend.php 2008-01-17 12:11:30 UTC (rev 204)
@@ -1,232 +1,142 @@
-<?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)
- {
+<?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);
if (!empty($getArray)) {
- $_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()
- {
+ $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()
+ {
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 _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);
- }
-
+ }
+ 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);
+ }
+
}
\ No newline at end of file
Modified: trunk/src/PHPSpec/Runner/Example.php (203 => 204)
--- trunk/src/PHPSpec/Runner/Example.php 2008-01-16 17:35:15 UTC (rev 203)
+++ trunk/src/PHPSpec/Runner/Example.php 2008-01-17 12:11:30 UTC (rev 204)
@@ -14,14 +14,14 @@
*
* @category PHPSpec
* @package PHPSpec
- * @copyright Copyright (c) 2007 P\xE1draic 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\xE1draic 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_Runner_Example
@@ -75,8 +75,12 @@
$this->_context->clearCurrentSpecification();
/**
- * spec execution
- */
+ * Spec execution
+ * *Each methods are reserved for internal stepping setup/teardown
+ */
+ if (method_exists($this->_context, 'beforeEach')) {
+ $this->_context->beforeEach();
+ }
if (method_exists($this->_context, 'before')) {
$this->_context->before();
}
@@ -88,6 +92,9 @@
if (method_exists($this->_context, 'after')) {
$this->_context->after();
+ }
+ if (method_exists($this->_context, 'afterEach')) {
+ $this->_context->afterEach();
}
/**