Skip to content

Commit

Permalink
Recreate trunk.
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jun 29, 2006
1 parent 7a61fa8 commit 8b8c705
Show file tree
Hide file tree
Showing 188 changed files with 29,198 additions and 0 deletions.
129 changes: 129 additions & 0 deletions Extensions/ExceptionTestCase.php
@@ -0,0 +1,129 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
* PHPUnit
*
* Copyright (c) 2002-2006, Sebastian Bergmann <sb@sebastian-bergmann.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @category Testing
* @package PHPUnit2
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version SVN: $Id$
* @link http://pear.php.net/package/PHPUnit2
* @since File available since Release 2.0.0
*/

require_once 'PHPUnit2/Framework.php';
require_once 'PHPUnit2/Util/Filter.php';

PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');

/**
* A TestCase that expects a specified Exception to be thrown.
*
* @category Testing
* @package PHPUnit2
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: @package_version@
* @link http://pear.php.net/package/PHPUnit2
* @since Class available since Release 2.0.0
*/
class PHPUnit2_Extensions_ExceptionTestCase extends PHPUnit2_Framework_TestCase
{
/**
* The name of the expected Exception.
*
* @var mixed
* @access private
*/
private $expectedException = NULL;

/**
* @return string
* @access public
* @since Method available since Release 2.2.0
*/
public function getExpectedException()
{
return $this->expectedException;
}

/**
* @param mixed $exceptionName
* @access public
* @since Method available since Release 2.2.0
*/
public function setExpectedException($exceptionName)
{
if ((is_string($exceptionName) && class_exists($exceptionName)) || $exceptionName === NULL) {
$this->expectedException = $exceptionName;
}
}

/**
* @access protected
*/
protected function runTest()
{
try {
parent::runTest();
}

catch (Exception $e) {
if ($this->expectedException !== NULL &&
$e instanceof $this->expectedException) {
return;
} else {
throw $e;
}
}

if ($this->expectedException !== NULL) {
$this->fail('Expected exception ' . $this->expectedException);
}
}
}

/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* c-hanging-comment-ender-p: nil
* End:
*/
?>
90 changes: 90 additions & 0 deletions Extensions/MockObject/Builder/Identity.php
@@ -0,0 +1,90 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
* PHPUnit
*
* Copyright (c) 2002-2006, Sebastian Bergmann <sb@sebastian-bergmann.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @category Testing
* @package PHPUnit2
* @author Jan Borsodi <jb@ez.no>
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version SVN: $Id$
* @link http://pear.php.net/package/PHPUnit2
* @since File available since Release 3.0.0
*/

require_once 'PHPUnit2/Util/Filter.php';

PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');

/**
* Builder interface for unique identifiers.
*
* Defines the interface for recording unique identifiers. The identifiers
* can be used to define the invocation order of expectations. The expectation
* is recorded using id() and then defined in order using
* PHPUnit2_Extensions_MockObject_Builder_Match::after().
*
* @category Testing
* @package PHPUnit2
* @author Jan Borsodi <jb@ez.no>
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: @package_version@
* @link http://pear.php.net/package/PHPUnit2
* @since Interface available since Release 3.0.0
*/
interface PHPUnit2_Extensions_MockObject_Builder_Identity
{
/**
* Sets the identification of the expectation to $id.
*
* @note The identifier is unique per mock object.
* @param string $id Unique identifiation of expectation.
*/
public function id($id);
}

/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* c-hanging-comment-ender-p: nil
* End:
*/
?>
167 changes: 167 additions & 0 deletions Extensions/MockObject/Builder/InvocationMocker.php
@@ -0,0 +1,167 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
* PHPUnit
*
* Copyright (c) 2002-2006, Sebastian Bergmann <sb@sebastian-bergmann.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @category Testing
* @package PHPUnit2
* @author Jan Borsodi <jb@ez.no>
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version SVN: $Id$
* @link http://pear.php.net/package/PHPUnit2
* @since File available since Release 3.0.0
*/

require_once 'PHPUnit2/Util/Filter.php';
require_once 'PHPUnit2/Extensions/MockObject/Builder/MethodNameMatch.php';
require_once 'PHPUnit2/Extensions/MockObject/Matcher.php';
require_once 'PHPUnit2/Extensions/MockObject/Stub.php';

PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');

/**
* Builder for mocked or stubbed invocations.
*
* Provides methods for building expectations without having to resort to
* instantiating the various matchers manually. These methods also form a
* more natural way of reading the expectation. This class should be together
* with the test case PHPUnit2_Extensions_MockObject_TestCase.
*
* @category Testing
* @package PHPUnit2
* @author Jan Borsodi <jb@ez.no>
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: @package_version@
* @link http://pear.php.net/package/PHPUnit2
* @since Class available since Release 3.0.0
*/
class PHPUnit2_Extensions_MockObject_Builder_InvocationMocker implements PHPUnit2_Extensions_MockObject_Builder_MethodNameMatch
{
private $collection;

private $matcher;

public function __construct(PHPUnit2_Extensions_MockObject_Stub_MatcherCollection $collection, PHPUnit2_Extensions_MockObject_Matcher_Invocation $invocationMatcher)
{
$this->collection = $collection;
$this->matcher = new PHPUnit2_Extensions_MockObject_Matcher($invocationMatcher);

$this->collection->addMatcher($this->matcher);
}

public function getMatcher()
{
return $this->matcher;
}

public function id($id)
{
$this->collection->registerId($id, $this);

return $this;
}

public function will(PHPUnit2_Extensions_MockObject_Stub $stub)
{
$this->matcher->stub = $stub;

return $this;
}

public function after($id)
{
$this->matcher->afterMatchBuilderId = $id;

return $this;
}

public function with()
{
$args = func_get_args();

if ($this->matcher->methodNameMatcher === NULL) {
throw new RuntimeException('Method name matcher is not defined, cannot define parameter matcher without one');
}

if ( $this->matcher->parametersMatcher !== NULL) {
throw new RuntimeException('Parameter matcher is already defined, cannot redefine');
}

$this->matcher->parametersMatcher = new PHPUnit2_Extensions_MockObject_Matcher_Parameters($args);

return $this;
}

public function withAnyParameters()
{
if ($this->matcher->methodNameMatcher === NULL) {
throw new RuntimeException('Method name matcher is not defined, cannot define parameter matcher without one');
}

if ($this->matcher->parametersMatcher !== NULL) {
throw new RuntimeException('Parameter matcher is already defined, cannot redefine');
}

$this->matcher->parametersMatcher = new PHPUnit2_Extensions_MockObject_Matcher_AnyParameters();

return $this;
}

public function method($constraint)
{
if ($this->matcher->methodNameMatcher !== NULL) {
throw new RuntimeException('Method name matcher is already defined, cannot redefine');
}

$this->matcher->methodNameMatcher = new PHPUnit2_Extensions_MockObject_Matcher_MethodName($constraint);

return $this;
}

}

/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* c-hanging-comment-ender-p: nil
* End:
*/
?>

0 comments on commit 8b8c705

Please sign in to comment.