import v1.1.0_RC2 | 2009-09-20

This commit is contained in:
2019-07-17 22:19:00 +02:00
parent 3b7ba80568
commit 38c146901c
2504 changed files with 101817 additions and 62316 deletions

View File

@ -1,4 +1,24 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* 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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Test
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: DomQuery.php 16874 2009-07-20 12:46:00Z mikaelkael $
*/
/** PHPUnit_Framework_Constraint */
require_once 'PHPUnit/Framework/Constraint.php';
@ -7,12 +27,12 @@ require_once 'Zend/Dom/Query.php';
/**
* Zend_Dom_Query-based PHPUnit Constraint
*
*
* @uses PHPUnit_Framework_Constraint
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (C) 2008 - Present, Zend Technologies, Inc.
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Test_PHPUnit_Constraint_DomQuery extends PHPUnit_Framework_Constraint
{
@ -72,7 +92,7 @@ class Zend_Test_PHPUnit_Constraint_DomQuery extends PHPUnit_Framework_Constraint
/**
* Constructor; setup constraint state
*
*
* @param string $path CSS selector path
* @return void
*/
@ -83,8 +103,8 @@ class Zend_Test_PHPUnit_Constraint_DomQuery extends PHPUnit_Framework_Constraint
/**
* Indicate negative match
*
* @param bool $flag
*
* @param bool $flag
* @return void
*/
public function setNegate($flag = true)
@ -94,8 +114,8 @@ class Zend_Test_PHPUnit_Constraint_DomQuery extends PHPUnit_Framework_Constraint
/**
* Whether or not path is a straight XPath expression
*
* @param bool $flag
*
* @param bool $flag
* @return Zend_Test_PHPUnit_Constraint_DomQuery
*/
public function setUseXpath($flag = true)
@ -106,7 +126,7 @@ class Zend_Test_PHPUnit_Constraint_DomQuery extends PHPUnit_Framework_Constraint
/**
* Evaluate an object to see if it fits the constraints
*
*
* @param string $other String to examine
* @param null|string Assertion type
* @return bool
@ -176,11 +196,11 @@ class Zend_Test_PHPUnit_Constraint_DomQuery extends PHPUnit_Framework_Constraint
/**
* Report Failure
*
*
* @see PHPUnit_Framework_Constraint for implementation details
* @param mixed $other CSS selector path
* @param string $description
* @param bool $not
* @param string $description
* @param bool $not
* @return void
* @throws PHPUnit_Framework_ExpectationFailedException
*/
@ -236,7 +256,7 @@ class Zend_Test_PHPUnit_Constraint_DomQuery extends PHPUnit_Framework_Constraint
/**
* Complete implementation
*
*
* @return string
*/
public function toString()
@ -246,8 +266,8 @@ class Zend_Test_PHPUnit_Constraint_DomQuery extends PHPUnit_Framework_Constraint
/**
* Check to see if content is matched in selected nodes
*
* @param Zend_Dom_Query_Result $result
*
* @param Zend_Dom_Query_Result $result
* @param string $match Content to match
* @return bool
*/
@ -269,9 +289,9 @@ class Zend_Test_PHPUnit_Constraint_DomQuery extends PHPUnit_Framework_Constraint
/**
* Check to see if content is NOT matched in selected nodes
*
* @param Zend_Dom_Query_Result $result
* @param string $match
*
* @param Zend_Dom_Query_Result $result
* @param string $match
* @return bool
*/
protected function _notMatchContent($result, $match)
@ -292,8 +312,8 @@ class Zend_Test_PHPUnit_Constraint_DomQuery extends PHPUnit_Framework_Constraint
/**
* Check to see if content is matched by regex in selected nodes
*
* @param Zend_Dom_Query_Result $result
*
* @param Zend_Dom_Query_Result $result
* @param string $pattern
* @return bool
*/
@ -315,8 +335,8 @@ class Zend_Test_PHPUnit_Constraint_DomQuery extends PHPUnit_Framework_Constraint
/**
* Check to see if content is NOT matched by regex in selected nodes
*
* @param Zend_Dom_Query_Result $result
*
* @param Zend_Dom_Query_Result $result
* @param string $pattern
* @return bool
*/
@ -338,8 +358,8 @@ class Zend_Test_PHPUnit_Constraint_DomQuery extends PHPUnit_Framework_Constraint
/**
* Determine if content count matches criteria
*
* @param Zend_Dom_Query_Result $result
*
* @param Zend_Dom_Query_Result $result
* @param int $test Value against which to test
* @param string $type assertion type
* @return boolean
@ -364,8 +384,8 @@ class Zend_Test_PHPUnit_Constraint_DomQuery extends PHPUnit_Framework_Constraint
/**
* Get node content, minus node markup tags
*
* @param DOMNode $node
*
* @param DOMNode $node
* @return string
*/
protected function _getNodeContent(DOMNode $node)

View File

@ -1,15 +1,35 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* 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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Test
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 16874 2009-07-20 12:46:00Z mikaelkael $
*/
/** PHPUnit_Framework_ExpectationFailedException */
require_once 'PHPUnit/Framework/ExpectationFailedException.php';
/**
* Zend_Test_PHPUnit_Constraint_Exception
*
* Zend_Test_PHPUnit_Constraint_Exception
*
* @uses PHPUnit_Framework_ExpectationFailedException
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (C) 2008 - Present, Zend Technologies, Inc.
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Test_PHPUnit_Constraint_Exception extends PHPUnit_Framework_ExpectationFailedException
{

View File

@ -1,15 +1,35 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* 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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Test
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Redirect.php 16874 2009-07-20 12:46:00Z mikaelkael $
*/
/** PHPUnit_Framework_Constraint */
require_once 'PHPUnit/Framework/Constraint.php';
/**
* Redirection constraints
*
*
* @uses PHPUnit_Framework_Constraint
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (C) 2008 - Present, Zend Technologies, Inc.
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Test_PHPUnit_Constraint_Redirect extends PHPUnit_Framework_Constraint
{
@ -51,7 +71,7 @@ class Zend_Test_PHPUnit_Constraint_Redirect extends PHPUnit_Framework_Constraint
/**
* Constructor; setup constraint state
*
*
* @return void
*/
public function __construct()
@ -60,8 +80,8 @@ class Zend_Test_PHPUnit_Constraint_Redirect extends PHPUnit_Framework_Constraint
/**
* Indicate negative match
*
* @param bool $flag
*
* @param bool $flag
* @return void
*/
public function setNegate($flag = true)
@ -71,7 +91,7 @@ class Zend_Test_PHPUnit_Constraint_Redirect extends PHPUnit_Framework_Constraint
/**
* Evaluate an object to see if it fits the constraints
*
*
* @param string $other String to examine
* @param null|string Assertion type
* @return bool
@ -126,11 +146,11 @@ class Zend_Test_PHPUnit_Constraint_Redirect extends PHPUnit_Framework_Constraint
/**
* Report Failure
*
*
* @see PHPUnit_Framework_Constraint for implementation details
* @param mixed $other
* @param mixed $other
* @param string $description Additional message to display
* @param bool $not
* @param bool $not
* @return void
* @throws PHPUnit_Framework_ExpectationFailedException
*/
@ -170,7 +190,7 @@ class Zend_Test_PHPUnit_Constraint_Redirect extends PHPUnit_Framework_Constraint
/**
* Complete implementation
*
*
* @return string
*/
public function toString()
@ -180,7 +200,7 @@ class Zend_Test_PHPUnit_Constraint_Redirect extends PHPUnit_Framework_Constraint
/**
* Check to see if content is matched in selected nodes
*
*
* @param Zend_Controller_Response_HttpTestCase $response
* @param string $match Content to match
* @return bool
@ -200,9 +220,9 @@ class Zend_Test_PHPUnit_Constraint_Redirect extends PHPUnit_Framework_Constraint
/**
* Check to see if content is NOT matched in selected nodes
*
*
* @param Zend_Controller_Response_HttpTestCase $response
* @param string $match
* @param string $match
* @return bool
*/
protected function _notMatch($response, $match)
@ -220,7 +240,7 @@ class Zend_Test_PHPUnit_Constraint_Redirect extends PHPUnit_Framework_Constraint
/**
* Check to see if content is matched by regex in selected nodes
*
*
* @param Zend_Controller_Response_HttpTestCase $response
* @param string $pattern
* @return bool
@ -240,7 +260,7 @@ class Zend_Test_PHPUnit_Constraint_Redirect extends PHPUnit_Framework_Constraint
/**
* Check to see if content is NOT matched by regex in selected nodes
*
*
* @param Zend_Controller_Response_HttpTestCase $response
* @param string $pattern
* @return bool

View File

@ -1,15 +1,35 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* 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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Test
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: ResponseHeader.php 16874 2009-07-20 12:46:00Z mikaelkael $
*/
/** PHPUnit_Framework_Constraint */
require_once 'PHPUnit/Framework/Constraint.php';
/**
* Response header PHPUnit Constraint
*
*
* @uses PHPUnit_Framework_Constraint
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (C) 2008 - Present, Zend Technologies, Inc.
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Test_PHPUnit_Constraint_ResponseHeader extends PHPUnit_Framework_Constraint
{
@ -62,7 +82,7 @@ class Zend_Test_PHPUnit_Constraint_ResponseHeader extends PHPUnit_Framework_Cons
/**
* Constructor; setup constraint state
*
*
* @return void
*/
public function __construct()
@ -71,8 +91,8 @@ class Zend_Test_PHPUnit_Constraint_ResponseHeader extends PHPUnit_Framework_Cons
/**
* Indicate negative match
*
* @param bool $flag
*
* @param bool $flag
* @return void
*/
public function setNegate($flag = true)
@ -82,7 +102,7 @@ class Zend_Test_PHPUnit_Constraint_ResponseHeader extends PHPUnit_Framework_Cons
/**
* Evaluate an object to see if it fits the constraints
*
*
* @param Zend_Controller_Response_Abstract $other String to examine
* @param null|string Assertion type
* @return bool
@ -157,11 +177,11 @@ class Zend_Test_PHPUnit_Constraint_ResponseHeader extends PHPUnit_Framework_Cons
/**
* Report Failure
*
*
* @see PHPUnit_Framework_Constraint for implementation details
* @param mixed $other
* @param mixed $other
* @param string $description Additional message to display
* @param bool $not
* @param bool $not
* @return void
* @throws PHPUnit_Framework_ExpectationFailedException
*/
@ -210,7 +230,7 @@ class Zend_Test_PHPUnit_Constraint_ResponseHeader extends PHPUnit_Framework_Cons
/**
* Complete implementation
*
*
* @return string
*/
public function toString()
@ -220,9 +240,9 @@ class Zend_Test_PHPUnit_Constraint_ResponseHeader extends PHPUnit_Framework_Cons
/**
* Compare response code for positive match
*
* @param Zend_Controller_Response_Abstract $response
* @param int $code
*
* @param Zend_Controller_Response_Abstract $response
* @param int $code
* @return bool
*/
protected function _code(Zend_Controller_Response_Abstract $response, $code)
@ -233,9 +253,9 @@ class Zend_Test_PHPUnit_Constraint_ResponseHeader extends PHPUnit_Framework_Cons
/**
* Compare response code for negative match
*
* @param Zend_Controller_Response_Abstract $response
* @param int $code
*
* @param Zend_Controller_Response_Abstract $response
* @param int $code
* @return bool
*/
protected function _notCode(Zend_Controller_Response_Abstract $response, $code)
@ -246,8 +266,8 @@ class Zend_Test_PHPUnit_Constraint_ResponseHeader extends PHPUnit_Framework_Cons
/**
* Retrieve response code
*
* @param Zend_Controller_Response_Abstract $response
*
* @param Zend_Controller_Response_Abstract $response
* @return int
*/
protected function _getCode(Zend_Controller_Response_Abstract $response)
@ -261,9 +281,9 @@ class Zend_Test_PHPUnit_Constraint_ResponseHeader extends PHPUnit_Framework_Cons
/**
* Positive check for response header presence
*
* @param Zend_Controller_Response_Abstract $response
* @param string $header
*
* @param Zend_Controller_Response_Abstract $response
* @param string $header
* @return bool
*/
protected function _header(Zend_Controller_Response_Abstract $response, $header)
@ -273,9 +293,9 @@ class Zend_Test_PHPUnit_Constraint_ResponseHeader extends PHPUnit_Framework_Cons
/**
* Negative check for response header presence
*
* @param Zend_Controller_Response_Abstract $response
* @param string $header
*
* @param Zend_Controller_Response_Abstract $response
* @param string $header
* @return bool
*/
protected function _notHeader(Zend_Controller_Response_Abstract $response, $header)
@ -285,9 +305,9 @@ class Zend_Test_PHPUnit_Constraint_ResponseHeader extends PHPUnit_Framework_Cons
/**
* Retrieve response header
*
* @param Zend_Controller_Response_Abstract $response
* @param string $header
*
* @param Zend_Controller_Response_Abstract $response
* @param string $header
* @return string|null
*/
protected function _getHeader(Zend_Controller_Response_Abstract $response, $header)
@ -302,10 +322,10 @@ class Zend_Test_PHPUnit_Constraint_ResponseHeader extends PHPUnit_Framework_Cons
/**
* Positive check for header contents matching pattern
*
* @param Zend_Controller_Response_Abstract $response
* @param string $header
* @param string $match
*
* @param Zend_Controller_Response_Abstract $response
* @param string $header
* @param string $match
* @return bool
*/
protected function _headerContains(Zend_Controller_Response_Abstract $response, $header, $match)
@ -321,10 +341,10 @@ class Zend_Test_PHPUnit_Constraint_ResponseHeader extends PHPUnit_Framework_Cons
/**
* Negative check for header contents matching pattern
*
* @param Zend_Controller_Response_Abstract $response
* @param string $header
* @param string $match
*
* @param Zend_Controller_Response_Abstract $response
* @param string $header
* @param string $match
* @return bool
*/
protected function _notHeaderContains(Zend_Controller_Response_Abstract $response, $header, $match)
@ -340,10 +360,10 @@ class Zend_Test_PHPUnit_Constraint_ResponseHeader extends PHPUnit_Framework_Cons
/**
* Positive check for header contents matching regex
*
* @param Zend_Controller_Response_Abstract $response
* @param string $header
* @param string $pattern
*
* @param Zend_Controller_Response_Abstract $response
* @param string $header
* @param string $pattern
* @return bool
*/
protected function _headerRegex(Zend_Controller_Response_Abstract $response, $header, $pattern)
@ -359,10 +379,10 @@ class Zend_Test_PHPUnit_Constraint_ResponseHeader extends PHPUnit_Framework_Cons
/**
* Negative check for header contents matching regex
*
* @param Zend_Controller_Response_Abstract $response
* @param string $header
* @param string $pattern
*
* @param Zend_Controller_Response_Abstract $response
* @param string $header
* @param string $pattern
* @return bool
*/
protected function _notHeaderRegex(Zend_Controller_Response_Abstract $response, $header, $pattern)

View File

@ -1,4 +1,23 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* 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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Test
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: ControllerTestCase.php 16874 2009-07-20 12:46:00Z mikaelkael $
*/
/** PHPUnit_Framework_TestCase */
require_once 'PHPUnit/Framework/TestCase.php';
@ -23,12 +42,12 @@ require_once 'Zend/Registry.php';
/**
* Functional testing scaffold for MVC applications
*
*
* @uses PHPUnit_Framework_TestCase
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (C) 2008 - Present, Zend Technologies, Inc.
* @license New BSD {@link http://framework.zend.com/license/new-bsd}
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_TestCase
{
@ -51,7 +70,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
* @var Zend_Controller_Request_Abstract
*/
protected $_request;
/**
* @var Zend_Controller_Response_Abstract
*/
@ -59,9 +78,9 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Overloading: prevent overloading to special properties
*
* @param string $name
* @param mixed $value
*
* @param string $name
* @param mixed $value
* @return void
*/
public function __set($name, $value)
@ -77,8 +96,8 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
* Overloading for common properties
*
* Provides overloading for request, response, and frontController objects.
*
* @param mixed $name
*
* @param mixed $name
* @return void
*/
public function __get($name)
@ -99,7 +118,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
* Set up MVC app
*
* Calls {@link bootstrap()} by default
*
*
* @return void
*/
protected function setUp()
@ -112,10 +131,10 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
*
* Resets the front controller, and then bootstraps it.
*
* If {@link $bootstrap} is a callback, executes it; if it is a file, it include's
* it. When done, sets the test case request and response objects into the
* If {@link $bootstrap} is a callback, executes it; if it is a file, it include's
* it. When done, sets the test case request and response objects into the
* front controller.
*
*
* @return void
*/
final public function bootstrap()
@ -139,12 +158,12 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Dispatch the MVC
*
* If a URL is provided, sets it as the request URI in the request object.
* Then sets test case request and response objects in front controller,
* If a URL is provided, sets it as the request URI in the request object.
* Then sets test case request and response objects in front controller,
* disables throwing exceptions, and disables returning the response.
* Finally, dispatches the front controller.
*
* @param string|null $url
*
* @param string|null $url
* @return void
*/
public function dispatch($url = null)
@ -173,8 +192,8 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Reset MVC state
*
* Creates new request/response objects, resets the front controller
*
* Creates new request/response objects, resets the front controller
* instance, and resets the action helper broker.
*
* @todo Need to update Zend_Layout to add a resetInstance() method
@ -196,7 +215,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Rest all view placeholders
*
*
* @return void
*/
protected function _resetPlaceholders()
@ -218,7 +237,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
* Reset the request object
*
* Useful for test cases that need to test multiple trips to the server.
*
*
* @return Zend_Test_PHPUnit_ControllerTestCase
*/
public function resetRequest()
@ -231,7 +250,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
* Reset the response object
*
* Useful for test cases that need to test multiple trips to the server.
*
*
* @return Zend_Test_PHPUnit_ControllerTestCase
*/
public function resetResponse()
@ -243,7 +262,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert against DOM selection
*
*
* @param string $path CSS selector path
* @param string $message
* @return void
@ -261,7 +280,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert against DOM selection
*
*
* @param string $path CSS selector path
* @param string $message
* @return void
@ -279,7 +298,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert against DOM selection; node should contain content
*
*
* @param string $path CSS selector path
* @param string $match content that should be contained in matched nodes
* @param string $message
@ -298,7 +317,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert against DOM selection; node should NOT contain content
*
*
* @param string $path CSS selector path
* @param string $match content that should NOT be contained in matched nodes
* @param string $message
@ -317,7 +336,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert against DOM selection; node should match content
*
*
* @param string $path CSS selector path
* @param string $pattern Pattern that should be contained in matched nodes
* @param string $message
@ -336,7 +355,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert against DOM selection; node should NOT match content
*
*
* @param string $path CSS selector path
* @param string $pattern pattern that should NOT be contained in matched nodes
* @param string $message
@ -355,7 +374,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert against DOM selection; should contain exact number of nodes
*
*
* @param string $path CSS selector path
* @param string $count Number of nodes that should match
* @param string $message
@ -374,7 +393,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert against DOM selection; should NOT contain exact number of nodes
*
*
* @param string $path CSS selector path
* @param string $count Number of nodes that should NOT match
* @param string $message
@ -393,7 +412,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert against DOM selection; should contain at least this number of nodes
*
*
* @param string $path CSS selector path
* @param string $count Minimum number of nodes that should match
* @param string $message
@ -412,7 +431,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert against DOM selection; should contain no more than this number of nodes
*
*
* @param string $path CSS selector path
* @param string $count Maximum number of nodes that should match
* @param string $message
@ -431,7 +450,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert against XPath selection
*
*
* @param string $path XPath path
* @param string $message
* @return void
@ -449,7 +468,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert against XPath selection
*
*
* @param string $path XPath path
* @param string $message
* @return void
@ -467,7 +486,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert against XPath selection; node should contain content
*
*
* @param string $path XPath path
* @param string $match content that should be contained in matched nodes
* @param string $message
@ -486,7 +505,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert against XPath selection; node should NOT contain content
*
*
* @param string $path XPath path
* @param string $match content that should NOT be contained in matched nodes
* @param string $message
@ -505,7 +524,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert against XPath selection; node should match content
*
*
* @param string $path XPath path
* @param string $pattern Pattern that should be contained in matched nodes
* @param string $message
@ -524,7 +543,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert against XPath selection; node should NOT match content
*
*
* @param string $path XPath path
* @param string $pattern pattern that should NOT be contained in matched nodes
* @param string $message
@ -543,7 +562,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert against XPath selection; should contain exact number of nodes
*
*
* @param string $path XPath path
* @param string $count Number of nodes that should match
* @param string $message
@ -562,7 +581,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert against XPath selection; should NOT contain exact number of nodes
*
*
* @param string $path XPath path
* @param string $count Number of nodes that should NOT match
* @param string $message
@ -581,7 +600,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert against XPath selection; should contain at least this number of nodes
*
*
* @param string $path XPath path
* @param string $count Minimum number of nodes that should match
* @param string $message
@ -600,7 +619,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert against XPath selection; should contain no more than this number of nodes
*
*
* @param string $path XPath path
* @param string $count Maximum number of nodes that should match
* @param string $message
@ -619,8 +638,8 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert that response is a redirect
*
* @param string $message
*
* @param string $message
* @return void
*/
public function assertRedirect($message = '')
@ -636,8 +655,8 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert that response is NOT a redirect
*
* @param string $message
*
* @param string $message
* @return void
*/
public function assertNotRedirect($message = '')
@ -653,9 +672,9 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert that response redirects to given URL
*
* @param string $url
* @param string $message
*
* @param string $url
* @param string $message
* @return void
*/
public function assertRedirectTo($url, $message = '')
@ -671,9 +690,9 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert that response does not redirect to given URL
*
* @param string $url
* @param string $message
*
* @param string $url
* @param string $message
* @return void
*/
public function assertNotRedirectTo($url, $message = '')
@ -689,9 +708,9 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert that redirect location matches pattern
*
* @param string $pattern
* @param string $message
*
* @param string $pattern
* @param string $message
* @return void
*/
public function assertRedirectRegex($pattern, $message = '')
@ -707,9 +726,9 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert that redirect location does not match pattern
*
* @param string $pattern
* @param string $message
*
* @param string $pattern
* @param string $message
* @return void
*/
public function assertNotRedirectRegex($pattern, $message = '')
@ -725,9 +744,9 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert response code
*
* @param int $code
* @param string $message
*
* @param int $code
* @param string $message
* @return void
*/
public function assertResponseCode($code, $message = '')
@ -743,9 +762,9 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert response code
*
* @param int $code
* @param string $message
*
* @param int $code
* @param string $message
* @return void
*/
public function assertNotResponseCode($code, $message = '')
@ -762,9 +781,9 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert response header exists
*
* @param string $header
* @param string $message
*
* @param string $header
* @param string $message
* @return void
*/
public function assertHeader($header, $message = '')
@ -780,9 +799,9 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert response header does not exist
*
* @param string $header
* @param string $message
*
* @param string $header
* @param string $message
* @return void
*/
public function assertNotHeader($header, $message = '')
@ -799,10 +818,10 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert response header exists and contains the given string
*
* @param string $header
* @param string $match
* @param string $message
*
* @param string $header
* @param string $match
* @param string $message
* @return void
*/
public function assertHeaderContains($header, $match, $message = '')
@ -818,10 +837,10 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert response header does not exist and/or does not contain the given string
*
* @param string $header
*
* @param string $header
* @param string $match
* @param string $message
* @param string $message
* @return void
*/
public function assertNotHeaderContains($header, $match, $message = '')
@ -838,10 +857,10 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert response header exists and matches the given pattern
*
* @param string $header
* @param string $pattern
* @param string $message
*
* @param string $header
* @param string $pattern
* @param string $message
* @return void
*/
public function assertHeaderRegex($header, $pattern, $message = '')
@ -857,10 +876,10 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert response header does not exist and/or does not match the given regex
*
* @param string $header
*
* @param string $header
* @param string $pattern
* @param string $message
* @param string $message
* @return void
*/
public function assertNotHeaderRegex($header, $pattern, $message = '')
@ -877,9 +896,9 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert that the last handled request used the given module
*
* @param string $module
* @param string $message
*
* @param string $module
* @param string $message
* @return void
*/
public function assertModule($module, $message = '')
@ -896,9 +915,9 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert that the last handled request did NOT use the given module
*
* @param string $module
* @param string $message
*
* @param string $module
* @param string $message
* @return void
*/
public function assertNotModule($module, $message = '')
@ -915,9 +934,9 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert that the last handled request used the given controller
*
* @param string $controller
* @param string $message
*
* @param string $controller
* @param string $message
* @return void
*/
public function assertController($controller, $message = '')
@ -934,9 +953,9 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert that the last handled request did NOT use the given controller
*
* @param string $controller
* @param string $message
*
* @param string $controller
* @param string $message
* @return void
*/
public function assertNotController($controller, $message = '')
@ -953,9 +972,9 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert that the last handled request used the given action
*
* @param string $action
* @param string $message
*
* @param string $action
* @param string $message
* @return void
*/
public function assertAction($action, $message = '')
@ -972,9 +991,9 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert that the last handled request did NOT use the given action
*
* @param string $action
* @param string $message
*
* @param string $action
* @param string $message
* @return void
*/
public function assertNotAction($action, $message = '')
@ -991,9 +1010,9 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert that the specified route was used
*
* @param string $route
* @param string $message
*
* @param string $route
* @param string $message
* @return void
*/
public function assertRoute($route, $message = '')
@ -1011,9 +1030,9 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Assert that the route matched is NOT as specified
*
* @param string $route
* @param string $message
*
* @param string $route
* @param string $message
* @return void
*/
public function assertNotRoute($route, $message = '')
@ -1031,7 +1050,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Retrieve front controller instance
*
*
* @return Zend_Controller_Front
*/
public function getFrontController()
@ -1044,7 +1063,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Retrieve test case request object
*
*
* @return Zend_Controller_Request_Abstract
*/
public function getRequest()
@ -1057,8 +1076,8 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
}
/**
* Retrieve test case response object
*
* Retrieve test case response object
*
* @return Zend_Controller_Response_Abstract
*/
public function getResponse()
@ -1072,7 +1091,7 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Retrieve DOM query object
*
*
* @return Zend_Dom_Query
*/
public function getQuery()
@ -1086,14 +1105,14 @@ abstract class Zend_Test_PHPUnit_ControllerTestCase extends PHPUnit_Framework_Te
/**
* Increment assertion count
*
*
* @return void
*/
protected function _incrementAssertionCount()
{
$stack = debug_backtrace();
foreach (debug_backtrace() as $step) {
if (isset($step['object'])
if (isset($step['object'])
&& $step['object'] instanceof PHPUnit_Framework_TestCase
) {
if (version_compare(PHPUnit_Runner_Version::id(), '3.3.3', 'lt')) {

View File

@ -0,0 +1,151 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* 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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: DatabaseTestCase.php 16911 2009-07-21 11:54:03Z matthew $
*/
/**
* @see PHPUnit_Extensions_Database_TestCase
*/
require_once "PHPUnit/Extensions/Database/TestCase.php";
/**
* @see Zend_Test_PHPUnit_Db_Operation_Truncate
*/
require_once "Zend/Test/PHPUnit/Db/Operation/Truncate.php";
/**
* @see Zend_Test_PHPUnit_Db_Operation_Insert
*/
require_once "Zend/Test/PHPUnit/Db/Operation/Insert.php";
/**
* @see Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet
*/
require_once "Zend/Test/PHPUnit/Db/DataSet/DbTableDataSet.php";
/**
* @see Zend_Test_PHPUnit_Db_DataSet_DbTable
*/
require_once "Zend/Test/PHPUnit/Db/DataSet/DbTable.php";
/**
* @see Zend_Test_PHPUnit_Db_DataSet_DbRowset
*/
require_once "Zend/Test/PHPUnit/Db/DataSet/DbRowset.php";
/**
* Generic Testcase for Zend Framework related DbUnit Testing with PHPUnit
*
* @uses PHPUnit_Extensions_Database_TestCase
* @category Zend
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Test_PHPUnit_DatabaseTestCase extends PHPUnit_Extensions_Database_TestCase
{
/**
* Creates a new Zend Database Connection using the given Adapter and database schema name.
*
* @param Zend_Db_Adapter_Abstract $connection
* @param string $schema
* @return Zend_Test_PHPUnit_Db_Connection
*/
protected function createZendDbConnection(Zend_Db_Adapter_Abstract $connection, $schema)
{
return new Zend_Test_PHPUnit_Db_Connection($connection, $schema);
}
/**
* Convenience function to get access to the database connection.
*
* @return Zend_Db_Adapter_Abstract
*/
protected function getAdapter()
{
return $this->getConnection()->getConnection();
}
/**
* Returns the database operation executed in test setup.
*
* @return PHPUnit_Extensions_Database_Operation_DatabaseOperation
*/
protected function getSetUpOperation()
{
return new PHPUnit_Extensions_Database_Operation_Composite(array(
new Zend_Test_PHPUnit_Db_Operation_Truncate(),
new Zend_Test_PHPUnit_Db_Operation_Insert(),
));
}
/**
* Returns the database operation executed in test cleanup.
*
* @return PHPUnit_Extensions_Database_Operation_DatabaseOperation
*/
protected function getTearDownOperation()
{
return PHPUnit_Extensions_Database_Operation_Factory::NONE();
}
/**
* Create a dataset based on multiple Zend_Db_Table instances
*
* @param array $tables
* @return Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet
*/
protected function createDbTableDataSet(array $tables=array())
{
$dataSet = new Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet();
foreach($tables AS $table) {
$dataSet->addTable($table);
}
return $dataSet;
}
/**
* Create a table based on one Zend_Db_Table instance
*
* @param Zend_Db_Table_Abstract $table
* @param string $where
* @param string $order
* @param string $count
* @param string $offset
* @return Zend_Test_PHPUnit_Db_DataSet_DbTable
*/
protected function createDbTable(Zend_Db_Table_Abstract $table, $where=null, $order=null, $count=null, $offset=null)
{
return new Zend_Test_PHPUnit_Db_DataSet_DbTable($table, $where, $order, $count, $offset);
}
/**
* Create a data table based on a Zend_Db_Table_Rowset instance
*
* @param Zend_Db_Table_Rowset_Abstract $rowset
* @param string
* @return Zend_Test_PHPUnit_Db_DataSet_DbRowset
*/
protected function createDbRowset(Zend_Db_Table_Rowset_Abstract $rowset, $tableName = null)
{
return new Zend_Test_PHPUnit_Db_DataSet_DbRowset($rowset, $tableName);
}
}

View File

@ -0,0 +1,149 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* 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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Connection.php 16607 2009-07-09 21:51:46Z beberlei $
*/
/**
* @see PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection
*/
require_once "PHPUnit/Extensions/Database/DB/DefaultDatabaseConnection.php";
/**
* @see Zend_Test_PHPUnit_Db_DataSet_QueryTable
*/
require_once "Zend/Test/PHPUnit/Db/DataSet/QueryTable.php";
/**
* @see Zend_Test_PHPUnit_Db_Metadata_Generic
*/
require_once "Zend/Test/PHPUnit/Db/Metadata/Generic.php";
/**
* Generic Abstraction of Zend_Db Connections in the PHPUnit Database Extension context.
*
* @uses Zend_Db_Adapter_Abstract
* @uses PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection
* @category Zend
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Test_PHPUnit_Db_Connection extends PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection
{
/**
* Zend_Db_Adapter_Abstract
*
* @var Zend_Db_Adapter_Abstract
*/
protected $_connection;
/**
* Database Schema
*
* @var string $db
*/
protected $_schema;
/**
* Metadata
*
* @param PHPUnit_Extensions_Database_DB_IMetaData $db
*/
protected $_metaData;
/**
* Construct Connection based on Zend_Db_Adapter_Abstract
*
* @param Zend_Db_Adapter_Abstract $db
* @param string $schema
*/
public function __construct(Zend_Db_Adapter_Abstract $db, $schema)
{
$this->_connection = $db;
$this->_schema = $schema;
}
/**
* Close this connection.
*
* @return void
*/
public function close()
{
$this->_connection->closeConnection();
}
/**
* Creates a table with the result of the specified SQL statement.
*
* @param string $resultName
* @param string $sql
* @return PHPUnit_Extensions_Database_DataSet_ITable
*/
public function createQueryTable($resultName, $sql)
{
return new Zend_Test_PHPUnit_Db_DataSet_QueryTable($resultName, $sql, $this);
}
/**
* Returns a Zend_Db Connection
*
* @return Zend_Db_Adapter_Abstract
*/
public function getConnection()
{
return $this->_connection;
}
/**
* Returns a database metadata object that can be used to retrieve table
* meta data from the database.
*
* @return PHPUnit_Extensions_Database_DB_IMetaData
*/
public function getMetaData()
{
if($this->_metaData === null) {
$this->_metaData = new Zend_Test_PHPUnit_Db_Metadata_Generic($this->getConnection(), $this->getSchema());
}
return $this->_metaData;
}
/**
* Returns the schema for the connection.
*
* @return string
*/
public function getSchema()
{
return $this->_schema;
}
/**
* Returns the command used to truncate a table.
*
* @return string
*/
public function getTruncateCommand()
{
return "DELETE";
}
}

View File

@ -0,0 +1,75 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* 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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: DbRowset.php 16607 2009-07-09 21:51:46Z beberlei $
*/
/**
* @see Zend_Db_Table_Rowset_Abstract
*/
require_once "Zend/Db/Table/Rowset/Abstract.php";
require_once "PHPUnit/Extensions/Database/DataSet/AbstractTable.php";
/**
* Use a Zend_Db Rowset as a datatable for assertions with other PHPUnit Database extension tables.
*
* @uses PHPUnit_Extensions_Database_DataSet_AbstractTable
* @category Zend
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Test_PHPUnit_Db_DataSet_DbRowset extends PHPUnit_Extensions_Database_DataSet_AbstractTable
{
/**
* Construct Table object from a Zend_Db_Table_Rowset
*
* @param Zend_Db_Table_Rowset_Abstract $rowset
* @param string $tableName
*/
public function __construct(Zend_Db_Table_Rowset_Abstract $rowset, $tableName = null)
{
if($tableName == null) {
$table = $rowset->getTable();
if($table !== null) {
$tableName = $table->info('name');
} else {
require_once "Zend/Test/PHPUnit/Db/Exception.php";
throw new Zend_Test_PHPUnit_Db_Exception(
'No table name was given to Rowset Table and table name cannot be infered from the table, '.
'because the rowset is disconnected from database.'
);
}
}
$this->data = $rowset->toArray();
$columns = array();
if(isset($this->data[0]) > 0) {
$columns = array_keys($this->data[0]);
} else if($rowset->getTable() != null) {
$columns = $rowset->getTable()->info('cols');
}
$this->tableName = $tableName;
$this->tableMetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($this->tableName, $columns);
}
}

View File

@ -0,0 +1,123 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* 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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: DbTable.php 16670 2009-07-12 13:35:45Z beberlei $
*/
require_once "PHPUnit/Extensions/Database/DataSet/QueryTable.php";
/**
* @see Zend_Db_Table_Abstract
*/
require_once "Zend/Db/Table/Abstract.php";
/**
* Use a Zend_Db_Table for assertions with other PHPUnit Database Extension table types.
*
* @uses PHPUnit_Extensions_Database_DataSet_QueryTable
* @category Zend
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Test_PHPUnit_Db_DataSet_DbTable extends PHPUnit_Extensions_Database_DataSet_QueryTable
{
/**
* Zend_Db_Table object
*
* @var Zend_Db_Table_Abstract
*/
protected $_table = null;
/**
* @var array
*/
protected $_columns = array();
/**
* @var string
*/
protected $_where = null;
/**
* @var string
*/
protected $_orderBy = null;
/**
* @var string
*/
protected $_count = null;
/**
* @var int
*/
protected $_offset = null;
/**
* Construct Dataset Table from Zend_Db_Table object
*
* @param Zend_Db_Table_Abstract $table
* @param string|Zend_Db_Select|null $where
* @param string|null $order
* @param int $count
* @param int $offset
*/
public function __construct(Zend_Db_Table_Abstract $table, $where=null, $order=null, $count=null, $offset=null)
{
$this->tableName = $table->info('name');
$this->_columns = $table->info('cols');
$this->_table = $table;
$this->_where = $where;
$this->_order = $order;
$this->_count = $count;
$this->_offset = $offset;
}
/**
* Lazy load data via table fetchAll() method.
*
* @return void
*/
protected function loadData()
{
if ($this->data === null) {
$this->data = $this->_table->fetchAll(
$this->_where, $this->_order, $this->_count, $this->_offset
);
if($this->data instanceof Zend_Db_Table_Rowset_Abstract) {
$this->data = $this->data->toArray();
}
}
}
/**
* Create Table Metadata object
*/
protected function createTableMetaData()
{
if ($this->tableMetaData === NULL) {
$this->loadData();
$this->tableMetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($this->tableName, $this->_columns);
}
}
}

View File

@ -0,0 +1,103 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* 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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: DbTableDataSet.php 16607 2009-07-09 21:51:46Z beberlei $
*/
require_once "PHPUnit/Extensions/Database/DataSet/QueryDataSet.php";
require_once "PHPUnit/Extensions/Database/DB/IDatabaseConnection.php";
/**
* @see Zend_Test_PHPUnit_Db_DataSet_DbTable
*/
require_once "Zend/Test/PHPUnit/Db/DataSet/DbTable.php";
/**
* Aggregate several Zend_Db_Table instances into a dataset.
*
* @uses Zend_Db_Table
* @category Zend
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet extends PHPUnit_Extensions_Database_DataSet_AbstractDataSet
{
/**
* @var array
*/
protected $tables = array();
/**
* Add a Table dataset representation by specifiying an arbitrary select query.
*
* By default a select * will be done on the given tablename.
*
* @param Zend_Db_Table_Abstract $table
* @param string|Zend_Db_Select $query
* @param string $where
* @param string $order
* @param string $count
* @param string $offset
*/
public function addTable(Zend_Db_Table_Abstract $table, $where = null, $order = null, $count = null, $offset = null)
{
$tableName = $table->info('name');
$this->tables[$tableName] = new Zend_Test_PHPUnit_Db_DataSet_DbTable($table, $where, $order, $count, $offset);
}
/**
* Creates an iterator over the tables in the data set. If $reverse is
* true a reverse iterator will be returned.
*
* @param bool $reverse
* @return PHPUnit_Extensions_Database_DB_TableIterator
*/
protected function createIterator($reverse = FALSE)
{
return new PHPUnit_Extensions_Database_DataSet_DefaultTableIterator($this->tables, $reverse);
}
/**
* Returns a table object for the given table.
*
* @param string $tableName
* @return PHPUnit_Extensions_Database_DB_Table
*/
public function getTable($tableName)
{
if (!isset($this->tables[$tableName])) {
throw new InvalidArgumentException("$tableName is not a table in the current database.");
}
return $this->tables[$tableName];
}
/**
* Returns a list of table names for the database
*
* @return Array
*/
public function getTableNames()
{
return array_keys($this->tables);
}
}

View File

@ -0,0 +1,86 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* 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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: QueryDataSet.php 16607 2009-07-09 21:51:46Z beberlei $
*/
require_once "PHPUnit/Extensions/Database/DataSet/QueryDataSet.php";
require_once "PHPUnit/Extensions/Database/DB/IDatabaseConnection.php";
/**
* @see Zend_Test_PHPUnit_Db_DataSet_QueryTable
*/
require_once "Zend/Test/PHPUnit/Db/DataSet/QueryTable.php";
/**
* @see Zend_Db_Select
*/
require_once "Zend/Db/Select.php";
/**
* Uses several query strings or Zend_Db_Select objects to form a dataset of tables for assertion with other datasets.
*
* @uses PHPUnit_Extensions_Database_DataSet_QueryDataSet
* @category Zend
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Test_PHPUnit_Db_DataSet_QueryDataSet extends PHPUnit_Extensions_Database_DataSet_QueryDataSet
{
/**
* Creates a new dataset using the given database connection.
*
* @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $databaseConnection
*/
public function __construct(PHPUnit_Extensions_Database_DB_IDatabaseConnection $databaseConnection)
{
if( !($databaseConnection instanceof Zend_Test_PHPUnit_Db_Connection) ) {
require_once "Zend/Test/PHPUnit/Db/Exception.php";
throw new Zend_Test_PHPUnit_Db_Exception("Zend_Test_PHPUnit_Db_DataSet_QueryDataSet only works with Zend_Test_PHPUnit_Db_Connection connections-");
}
$this->databaseConnection = $databaseConnection;
}
/**
* Add a Table dataset representation by specifiying an arbitrary select query.
*
* By default a select * will be done on the given tablename.
*
* @param string $tableName
* @param string|Zend_Db_Select $query
*/
public function addTable($tableName, $query = NULL)
{
if ($query === NULL) {
$query = $this->databaseConnection->getConnection()->select();
$query->from($tableName, Zend_Db_Select::SQL_WILDCARD);
}
if($query instanceof Zend_Db_Select) {
$query = $query->__toString();
}
$this->tables[$tableName] = new Zend_Test_PHPUnit_Db_DataSet_QueryTable($tableName, $query, $this->databaseConnection);
}
}

View File

@ -0,0 +1,86 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* 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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: QueryTable.php 17117 2009-07-26 09:41:26Z beberlei $
*/
require_once "PHPUnit/Extensions/Database/DataSet/QueryTable.php";
require_once "PHPUnit/Extensions/Database/DB/IDatabaseConnection.php";
/**
* Represent a PHPUnit Database Extension table with Queries using a Zend_Db adapter for assertion against other tables.
*
* @uses PHPUnit_Extensions_Database_DataSet_QueryTable
* @category Zend
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Test_PHPUnit_Db_DataSet_QueryTable extends PHPUnit_Extensions_Database_DataSet_QueryTable
{
/**
* Creates a new database query table object.
*
* @param string $table_name
* @param string $query
* @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $databaseConnection
*/
public function __construct($tableName, $query, PHPUnit_Extensions_Database_DB_IDatabaseConnection $databaseConnection)
{
if( !($databaseConnection instanceof Zend_Test_PHPUnit_Db_Connection) ) {
require_once "Zend/Test/PHPUnit/Db/Exception.php";
throw new Zend_Test_PHPUnit_Db_Exception("Zend_Test_PHPUnit_Db_DataSet_QueryTable only works with Zend_Test_PHPUnit_Db_Connection connections-");
}
parent::__construct($tableName, $query, $databaseConnection);
}
/**
* Load data from the database.
*
* @return void
*/
protected function loadData()
{
if($this->data === null) {
$stmt = $this->databaseConnection->getConnection()->query($this->query);
$this->data = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
}
}
/**
* Create Table Metadata
*/
protected function createTableMetaData()
{
if ($this->tableMetaData === NULL)
{
$this->loadData();
$keys = array();
if(count($this->data) > 0) {
$keys = array_keys($this->data[0]);
}
$this->tableMetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData(
$this->tableName, $keys
);
}
}
}

View File

@ -0,0 +1,41 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* 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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 16607 2009-07-09 21:51:46Z beberlei $
*/
/**
* @see Zend_Exception
*/
require_once "Zend/Exception.php";
/**
* Exception for Zend_Test_PHPUnit_Database package
*
* @uses Zend_Exception
* @category Zend
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Test_PHPUnit_Db_Exception extends Zend_Exception
{
}

View File

@ -0,0 +1,164 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* 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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Generic.php 16607 2009-07-09 21:51:46Z beberlei $
*/
/**
* @see Zend_Db_Adapter_Abstract
*/
require_once "Zend/Db/Adapter/Abstract.php";
require_once "PHPUnit/Extensions/Database/DB/IMetaData.php";
/**
* Generic Metadata accessor for the Zend_Db adapters
*
* @uses PHPUnit_Extensions_Database_DB_IMetaData
* @category Zend
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Test_PHPUnit_Db_Metadata_Generic implements PHPUnit_Extensions_Database_DB_IMetaData
{
/**
* Zend_Db Connection
*
* @var Zend_Db_Adapter_Abstract
*/
protected $_connection;
/**
* Schemaname
*
* @var string
*/
protected $_schema;
/**
* Cached Table metadata
*
* @var array
*/
protected $_tableMetadata = array();
/**
* Creates a new database meta data object using the given pdo connection
* and schema name.
*
* @param PDO $pdo
* @param string $schema
*/
public final function __construct(Zend_Db_Adapter_Abstract $db, $schema)
{
$this->_connection = $db;
$this->_schema = $schema;
}
/**
* List Tables
*
* @return array
*/
public function getTableNames()
{
return $this->_connection->listTables();
}
/**
* Get Table information
*
* @param string $tableName
* @return array
*/
protected function getTableDescription($tableName)
{
if(!isset($this->_tableMetadata[$tableName])) {
$this->_tableMetadata[$tableName] = $this->_connection->describeTable($tableName);
}
return $this->_tableMetadata[$tableName];
}
/**
* Returns an array containing the names of all the columns in the
* $tableName table,
*
* @param string $tableName
* @return array
*/
public function getTableColumns($tableName)
{
$tableMeta = $this->getTableDescription($tableName);
$columns = array_keys($tableMeta);
return $columns;
}
/**
* Returns an array containing the names of all the primary key columns in
* the $tableName table.
*
* @param string $tableName
* @return array
*/
public function getTablePrimaryKeys($tableName)
{
$tableMeta = $this->getTableDescription($tableName);
$primaryColumnNames = array();
foreach($tableMeta AS $column) {
if($column['PRIMARY'] == true) {
$primaryColumnNames[] = $column['COLUMN_NAME'];
}
}
return $primaryColumnNames;
}
/**
* Returns the name of the default schema.
*
* @return string
*/
public function getSchema()
{
return $this->_schema;
}
/**
* Returns a quoted schema object. (table name, column name, etc)
*
* @param string $object
* @return string
*/
public function quoteSchemaObject($object)
{
return $this->_connection->quoteIdentifier($object);
}
/**
* Returns true if the rdbms allows cascading
*
* @return bool
*/
public function allowsCascading()
{
return false;
}
}

View File

@ -0,0 +1,69 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* 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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: DeleteAll.php 16607 2009-07-09 21:51:46Z beberlei $
*/
require_once "PHPUnit/Extensions/Database/Operation/IDatabaseOperation.php";
require_once "PHPUnit/Extensions/Database/DB/IDatabaseConnection.php";
require_once "PHPUnit/Extensions/Database/DataSet/IDataSet.php";
require_once "PHPUnit/Extensions/Database/Operation/Exception.php";
/**
* @see Zend_Test_PHPUnit_Db_Connection
*/
require_once "Zend/Test/PHPUnit/Db/Connection.php";
/**
* Delete All Operation that can be executed on set up or tear down of a database tester.
*
* @uses PHPUnit_Extensions_Database_Operation_IDatabaseOperation
* @category Zend
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Test_PHPUnit_Db_Operation_DeleteAll implements PHPUnit_Extensions_Database_Operation_IDatabaseOperation
{
/**
* @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection
* @param PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet
*/
public function execute(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet)
{
if(!($connection instanceof Zend_Test_PHPUnit_Db_Connection)) {
require_once "Zend/Test/PHPUnit/Db/Exception.php";
throw new Zend_Test_PHPUnit_Db_Exception("Not a valid Zend_Test_PHPUnit_Db_Connection instance, ".get_class($connection)." given!");
}
foreach ($dataSet as $table) {
try {
$tableName = $table->getTableMetaData()->getTableName();
$connection->getConnection()->delete($tableName);
} catch (Exception $e) {
require_once "PHPUnit/Extensions/Database/Operation/Exception.php";
throw new PHPUnit_Extensions_Database_Operation_Exception('DELETEALL', 'DELETE FROM '.$tableName.'', array(), $table, $e->getMessage());
}
}
}
}

View File

@ -0,0 +1,92 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* 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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Insert.php 16607 2009-07-09 21:51:46Z beberlei $
*/
require_once "PHPUnit/Extensions/Database/Operation/IDatabaseOperation.php";
require_once "PHPUnit/Extensions/Database/DB/IDatabaseConnection.php";
require_once "PHPUnit/Extensions/Database/DataSet/IDataSet.php";
require_once "PHPUnit/Extensions/Database/Operation/Exception.php";
/**
* @see Zend_Test_PHPUnit_Db_Connection
*/
require_once "Zend/Test/PHPUnit/Db/Connection.php";
/**
* Operation for Inserting on setup or teardown of a database tester.
*
* @uses PHPUnit_Extensions_Database_Operation_IDatabaseOperation
* @category Zend
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Test_PHPUnit_Db_Operation_Insert implements PHPUnit_Extensions_Database_Operation_IDatabaseOperation
{
/**
* @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection
* @param PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet
*/
public function execute(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet)
{
if(!($connection instanceof Zend_Test_PHPUnit_Db_Connection)) {
require_once "Zend/Test/PHPUnit/Db/Exception.php";
throw new Zend_Test_PHPUnit_Db_Exception("Not a valid Zend_Test_PHPUnit_Db_Connection instance, ".get_class($connection)." given!");
}
$databaseDataSet = $connection->createDataSet();
$dsIterator = $dataSet->getIterator();
foreach($dsIterator as $table) {
$tableName = $table->getTableMetaData()->getTableName();
$db = $connection->getConnection();
for($i = 0; $i < $table->getRowCount(); $i++) {
$values = $this->buildInsertValues($table, $i);
try {
$db->insert($tableName, $values);
} catch (Exception $e) {
throw new PHPUnit_Extensions_Database_Operation_Exception("INSERT", "INSERT INTO ".$tableName." [..]", $values, $table, $e->getMessage());
}
}
}
}
/**
*
* @param PHPUnit_Extensions_Database_DataSet_ITable $table
* @param int $rowNum
* @return array
*/
protected function buildInsertValues(PHPUnit_Extensions_Database_DataSet_ITable $table, $rowNum)
{
$values = array();
foreach($table->getTableMetaData()->getColumns() as $columnName) {
$values[$columnName] = $table->getValue($rowNum, $columnName);
}
return $values;
}
}

View File

@ -0,0 +1,98 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* 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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Truncate.php 16607 2009-07-09 21:51:46Z beberlei $
*/
require_once "PHPUnit/Extensions/Database/Operation/IDatabaseOperation.php";
require_once "PHPUnit/Extensions/Database/DB/IDatabaseConnection.php";
require_once "PHPUnit/Extensions/Database/DataSet/IDataSet.php";
require_once "PHPUnit/Extensions/Database/Operation/Exception.php";
/**
* @see Zend_Test_PHPUnit_Db_Connection
*/
require_once "Zend/Test/PHPUnit/Db/Connection.php";
/**
* Operation for Truncating on setup or teardown of a database tester.
*
* @uses PHPUnit_Extensions_Database_Operation_IDatabaseOperation
* @category Zend
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Test_PHPUnit_Db_Operation_Truncate implements PHPUnit_Extensions_Database_Operation_IDatabaseOperation
{
/**
*
* @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection
* @param PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet
* @return void
*/
public function execute(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet)
{
if(!($connection instanceof Zend_Test_PHPUnit_Db_Connection)) {
require_once "Zend/Test/PHPUnit/Db/Exception.php";
throw new Zend_Test_PHPUnit_Db_Exception("Not a valid Zend_Test_PHPUnit_Db_Connection instance, ".get_class($connection)." given!");
}
foreach ($dataSet as $table) {
try {
$tableName = $table->getTableMetaData()->getTableName();
$this->truncate($connection->getConnection(), $tableName);
} catch (Exception $e) {
throw new PHPUnit_Extensions_Database_Operation_Exception('TRUNCATE', 'TRUNCATE '.$tableName.'', array(), $table, $e->getMessage());
}
}
}
/**
* Truncate a given table.
*
* @param Zend_Db_Adapter_Abstract $db
* @param string $tableName
* @return void
*/
private function truncate(Zend_Db_Adapter_Abstract $db, $tableName)
{
$tableName = $db->quoteIdentifier($tableName);
if($db instanceof Zend_Db_Adapter_Pdo_Sqlite) {
$db->query('DELETE FROM '.$tableName);
} else if($db instanceof Zend_Db_Adapter_Db2) {
if(strstr(PHP_OS, "WIN")) {
$file = tempnam(sys_get_temp_dir(), "zendtestdbibm_");
file_put_contents($file, "");
$db->query('IMPORT FROM '.$file.' OF DEL REPLACE INTO '.$tableName);
unlink($file);
} else {
$db->query('IMPORT FROM /dev/null OF DEL REPLACE INTO '.$tableName);
}
} else if($db instanceof Zend_Db_Adapter_Pdo_Mssql) {
$db->query('TRUNCATE TABLE '.$tableName);
} else {
$db->query('TRUNCATE '.$tableName);
}
}
}

View File

@ -0,0 +1,95 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* 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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: SimpleTester.php 16607 2009-07-09 21:51:46Z beberlei $
*/
/**
* @see PHPUnit_Extensions_Database_DefaultTester
*/
require_once "PHPUnit/Extensions/Database/DefaultTester.php";
/**
* @see PHPUnit_Extensions_Database_DB_IDatabaseConnection
*/
require_once "PHPUnit/Extensions/Database/DB/IDatabaseConnection.php";
/**
* @see Zend_Test_PHPUnit_Db_Operation_Truncate
*/
require_once "Zend/Test/PHPUnit/Db/Operation/Truncate.php";
/**
* @see Zend_Test_PHPUnit_Db_Operation_Insert
*/
require_once "Zend/Test/PHPUnit/Db/Operation/Insert.php";
/**
* @see PHPUnit_Extensions_Database_Operation_Factory
*/
require_once "PHPUnit/Extensions/Database/Operation/Factory.php";
/**
* @see PHPUnit_Extensions_Database_DataSet_IDataSet
*/
require_once "PHPUnit/Extensions/Database/DataSet/IDataSet.php";
/**
* Simple Tester for Database Tests when the Abstract Test Case cannot be used.
*
* @uses PHPUnit_Extensions_Database_DefaultTester
* @category Zend
* @package Zend_Test
* @subpackage PHPUnit
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Test_PHPUnit_Db_SimpleTester extends PHPUnit_Extensions_Database_DefaultTester
{
/**
* Creates a new default database tester using the given connection.
*
* @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection
*/
public function __construct(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection)
{
if(!($connection instanceof Zend_Test_PHPUnit_Db_Connection)) {
require_once "Zend/Test/PHPUnit/Db/Exception.php";
throw new Zend_Test_PHPUnit_Db_Exception("Not a valid Zend_Test_PHPUnit_Db_Connection instance, ".get_class($connection)." given!");
}
$this->connection = $connection;
$this->setUpOperation = new PHPUnit_Extensions_Database_Operation_Composite(array(
new Zend_Test_PHPUnit_Db_Operation_Truncate(),
new Zend_Test_PHPUnit_Db_Operation_Insert(),
));
$this->tearDownOperation = PHPUnit_Extensions_Database_Operation_Factory::NONE();
}
/**
* Set Up the database using the given Dataset and the SetUp strategy "Truncate, then Insert"
*
* @param PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet
*/
public function setUpDatabase(PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet)
{
$this->setDataSet($dataSet);
$this->onSetUp();
}
}