[192] r385@phpspec (orig r192): padraic.brady | 2008-01-13 07:47:44 -0700

0 views
Skip to first unread message

nor...@domain51.com

unread,
Jan 13, 2008, 9:47:55 AM1/13/08
to phpspec...@googlegroups.com
Revision
192
Author
phpspec
Date
2008-01-13 07:47:55 -0700 (Sun, 13 Jan 2008)

Log Message

 r385@phpspec (orig r192):  padraic.brady | 2008-01-13 07:47:44 -0700
 * Adding basic support for Zend Http control

Modified Paths

Added Paths

Property Changed

Diff

Property changes:


Name: svk:merge
   - d6e91ea2-e33a-0410-98df-1d493bd67c58:/:191
   + d6e91ea2-e33a-0410-98df-1d493bd67c58:/:192

Modified: branches/zend/build/build.xml (191 => 192)


--- branches/zend/build/build.xml	2008-01-11 16:43:19 UTC (rev 191)
+++ branches/zend/build/build.xml	2008-01-13 14:47:55 UTC (rev 192)
@@ -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.2" /> <!-- 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.2" date="2008-01-11" license="LGPL">
                 * Patched a Predicate issue courtesy of Takagi Masahiro
 				  and Kubo

Added: branches/zend/specs/AllSpecs.php (0 => 192)


--- branches/zend/specs/AllSpecs.php	                        (rev 0)
+++ branches/zend/specs/AllSpecs.php	2008-01-13 14:47:55 UTC (rev 192)
@@ -0,0 +1,10 @@
+<?php
+
+require_once 'SpecHelper.php';
+
+$options = new stdClass;
+$options->recursive = true;
+$options->specdoc = true;
+$options->reporter = 'html';
+
+PHPSpec_Runner::run($options);
\ No newline at end of file

Added: branches/zend/specs/ContextZendSpec.php (0 => 192)


--- branches/zend/specs/ContextZendSpec.php	                        (rev 0)
+++ branches/zend/specs/ContextZendSpec.php	2008-01-13 14:47:55 UTC (rev 192)
@@ -0,0 +1,37 @@
+<?php
+
+require_once 'SpecHelper.php';
+
+class DescribeContextZend extends PHPSpec_Context
+{
+
+    public function itShouldSetControllerNameUsingContextClass()
+    {
+        $context = new DescribeFooController;
+        $this->spec($context->getController())->should->be('Foo');
+    }
+
+    public function itShouldCreateFrontControllerWhenInstantiated()
+    {
+        $context = new DescribeFooController;
+        $this->spec($context->getFrontController())->should->beAnInstanceOf('Zend_Controller_Front');
+    }
+
+    public function itShouldAllowSettingControllerManually()
+    {
+        $context = new DescribeFooController;
+        $context->setController('Bar');
+        $this->spec($context->getController())->should->be('Bar');
+    }
+
+    public function itShouldCreateRequestBeforeEachExample()
+    {
+        $context = new DescribeFooController;
+        $context->beforeEach();
+        $this->spec($context->request())->should->beAnInstanceOf('Zend_Controller_Request_http');
+    }
+}
+
+class DescribeFooController extends PHPSpec_Context_Zend
+{
+}
\ No newline at end of file

Added: branches/zend/specs/SpecHelper.php (0 => 192)


--- branches/zend/specs/SpecHelper.php	                        (rev 0)
+++ branches/zend/specs/SpecHelper.php	2008-01-13 14:47:55 UTC (rev 192)
@@ -0,0 +1,7 @@
+<?php
+
+set_include_path(
+    '.' . PATH_SEPARATOR
+    . dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'src' . PATH_SEPARATOR
+    . get_include_path()
+);
\ No newline at end of file

Added: branches/zend/src/PHPSpec/Context/Zend.php (0 => 192)


--- branches/zend/src/PHPSpec/Context/Zend.php	                        (rev 0)
+++ branches/zend/src/PHPSpec/Context/Zend.php	2008-01-13 14:47:55 UTC (rev 192)
@@ -0,0 +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
+{
+    
+    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)) {
+        	$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;
+        	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);
+    }
+    
+}
\ No newline at end of file

Modified: branches/zend/src/PHPSpec/Runner/Example.php (191 => 192)


--- branches/zend/src/PHPSpec/Runner/Example.php	2008-01-11 16:43:19 UTC (rev 191)
+++ branches/zend/src/PHPSpec/Runner/Example.php	2008-01-13 14:47:55 UTC (rev 192)
@@ -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();
         }
 
         /**
Reply all
Reply to author
Forward
0 new messages