Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Cleanup.
  • Loading branch information
sebastianbergmann committed Aug 19, 2010
1 parent b1cd884 commit 79f8047
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 52 deletions.
123 changes: 83 additions & 40 deletions PHPUnit/Framework/MockObject/MockBuilder.php
Expand Up @@ -33,6 +33,15 @@
* 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.
*
* @package PHPUnit
* @subpackage Framework_MockObject
* @author Giorgio Sironi <piccoloprincipeazzurro@gmail.com>
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link http://github.com/sebastianbergmann/phpunit-mock-objects
* @since File available since Release 1.0.0
*/

/**
Expand All @@ -41,120 +50,154 @@
* @package PHPUnit
* @subpackage Framework_MockObject
* @author Giorgio Sironi <piccoloprincipeazzurro@gmail.com>
* @copyright 2010 Giorgio Sironi <piccoloprincipeazzurro@gmail.com>
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link http://github.com/sebastianbergmann/phpunit-mock-objects
* @since File available since Release 3.5
* @since File available since Release 1.0.0
*/
class PHPUnit_Framework_MockObject_MockBuilder
{
/**
* @var PHPUnit_Framework_TestCase
*/
protected $testCase;

/**
* @var string
*/
protected $className;

/**
* @var array
*/
protected $methods = array();

/**
* @var string
*/
protected $mockClassName = '';

/**
* @var array
*/
protected $constructorArgs = array();
protected $originalConstructor = true;
protected $originalClone = true;
protected $autoload = true;

/**
* @var boolean
*/
protected $originalConstructor = TRUE;

/**
* @var boolean
*/
protected $originalClone = TRUE;

/**
* @var boolean
*/
protected $autoload = TRUE;

/**
* @param PHPUnit_Framework_TestCase
* @param string
*/
public function __construct(PHPUnit_Framework_TestCase $testCase,
$className)
public function __construct(PHPUnit_Framework_TestCase $testCase, $className)
{
$this->testCase = $testCase;
$this->testCase = $testCase;
$this->className = $className;
}

/**
* Creates the mock object according to the specifications
* set up via the other methods.
* Creates a mock object using a fluent interface.
*
* @return object a Mock of the class $this->className
* @return PHPUnit_Framework_MockObject_MockObject
*/
public function getMock()
{
return $this->testCase->getMock($this->className,
$this->methods,
$this->constructorArgs,
$this->mockClassName,
$this->originalConstructor,
$this->originalClone,
$this->autoload);
return $this->testCase->getMock(
$this->className,
$this->methods,
$this->constructorArgs,
$this->mockClassName,
$this->originalConstructor,
$this->originalClone,
$this->autoload
);
}

/**
* Specifies a subset of methods to mock. Default is to mock all of them.
* Specifies the subset of methods to mock. Default is to mock all of them.
*
* @param array $method methods to mock
* @return PHPUnit_Framework_MockSpecification provides a fluent interface
* @param array $methods
* @return PHPUnit_Framework_MockObject_MockBuilder
*/
public function setMethods(array $methods)
{
$this->methods = $methods;

return $this;
}

/**
* Specifies arguments to pass to the constructor during instantiation.
* Default is to pass nothing.
* Specifies the arguments for the constructor.
*
* @return PHPUnit_Framework_MockSpecification provides a fluent interface
* @param array $args
* @return PHPUnit_Framework_MockObject_MockBuilder
*/
public function setConstructorArgs(array $args)
{
$this->constructorArgs = $args;

return $this;
}

/**
* Defines class name of the generated subclass.
* Default is a generated name.
* Specifies the name for the mock class.
*
* @param string
* @return PHPUnit_Framework_MockSpecification provides a fluent interface
* @param string $name
* @return PHPUnit_Framework_MockObject_MockBuilder
*/
public function setMockClassName($name)
{
$this->mockClassName = $name;

return $this;
}

/**
* Disables the call to the original constructor.
* Default is to call it.
* Suppresses the invocation of the original constructor.
*
* @return PHPUnit_Framework_MockSpecification provides a fluent interface
* @return PHPUnit_Framework_MockObject_MockBuilder
*/
public function disableOriginalConstructor()
{
$this->originalConstructor = false;
$this->originalConstructor = FALSE;

return $this;
}

/**
* Disables the original __clone() method.
* Default is to leave it intact.
* Suppresses the invocation of the original clone constructor.
*
* @return PHPUnit_Framework_MockSpecification provides a fluent interface
* @return PHPUnit_Framework_MockObject_MockBuilder
*/
public function disableOriginalClone()
{
$this->originalClone = false;
$this->originalClone = FALSE;

return $this;
}

/**
* Disables autoload calls during creation of the Mock.
* Default is to leave it active.
* Suppresses the use of class autoloading while creating the mock object.
*
* @return PHPUnit_Framework_MockSpecification provides a fluent interface
* @return PHPUnit_Framework_MockObject_MockBuilder
*/
public function disableAutoload()
{
$this->autoload = false;
$this->autoload = FALSE;

return $this;
}
}
1 change: 0 additions & 1 deletion TODO.txt

This file was deleted.

23 changes: 12 additions & 11 deletions Tests/MockBuilderTest.php
Expand Up @@ -2,7 +2,7 @@
/**
* PHPUnit
*
* Copyright (c) 2002-2010, Sebastian Bergmann <sebastian@phpunit.de>.
* Copyright (c) 2010, Sebastian Bergmann <sb@sebastian-bergmann.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -34,28 +34,29 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @category Testing
* @package PHPUnit
* @author Sebastian Bergmann <sebastian@phpunit.de>
* @copyright 2002-2010 Sebastian Bergmann <sebastian@phpunit.de>
* @subpackage Framework_MockObject
* @author Giorgio Sironi <piccoloprincipeazzurro@gmail.com>
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link http://www.phpunit.de/
* @since File available since Release 3.5
* @link http://github.com/sebastianbergmann/phpunit-mock-objects
* @since File available since Release 1.0.0
*/

require_once 'PHPUnit/Framework/TestCase.php';

require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'Mockable.php';

/**
* @category Testing
* @package PHPUnit
* @subpackage Framework_MockObject
* @author Giorgio Sironi <piccoloprincipeazzurro@gmail.com>
* @copyright 2010 Giorgio Sironi <piccoloprincipeazzurro@gmail.com>
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: @package_version@
* @link http://www.phpunit.de/
* @since Class available since Release 3.5
* @link http://github.com/sebastianbergmann/phpunit-mock-objects
* @since File available since Release 1.0.0
*/
class Framework_MockBuilderTest extends PHPUnit_Framework_TestCase
{
Expand Down
3 changes: 3 additions & 0 deletions package.xml
Expand Up @@ -140,6 +140,9 @@
<file baseinstalldir="/" name="Matcher.php" role="php">
<tasks:replace from="@package_version@" to="version" type="package-info" />
</file>
<file baseinstalldir="/" name="MockBuilder.php" role="php">
<tasks:replace from="@package_version@" to="version" type="package-info" />
</file>
<file baseinstalldir="/" name="MockObject.php" role="php">
<tasks:replace from="@package_version@" to="version" type="package-info" />
</file>
Expand Down

0 comments on commit 79f8047

Please sign in to comment.