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

Commit

Permalink
Namespace mock object id with class name and assign new id when a moc…
Browse files Browse the repository at this point in the history
…k object is cloned.
  • Loading branch information
sebastianbergmann committed Aug 31, 2012
1 parent b9930bb commit 3a294a1
Show file tree
Hide file tree
Showing 27 changed files with 98 additions and 54 deletions.
7 changes: 1 addition & 6 deletions PHPUnit/Framework/MockObject/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,6 @@ class PHPUnit_Framework_MockObject_Generator
*/
protected static $soapLoaded = NULL;

/**
* @var integer
*/
protected static $mockObjectId = 0;

/**
* Returns a mock object for the specified class.
*
Expand Down Expand Up @@ -252,7 +247,7 @@ protected static function getObject($code, $className, $originalClassName = '',
);
}

$object->__phpunit_setId(self::$mockObjectId++);
$object->__phpunit_setId();

return $object;
}
Expand Down
5 changes: 3 additions & 2 deletions PHPUnit/Framework/MockObject/Generator/mocked_class.tpl.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
protected static $staticInvocationMocker;
protected $invocationMocker;
protected $id;
protected static $nextId = 0;

{clone}{mocked_methods}
public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher)
Expand Down Expand Up @@ -52,8 +53,8 @@
$this->id = NULL;
}

public function __phpunit_setId($id)
public function __phpunit_setId()
{
$this->id = $id;
$this->id = sprintf('%s#%s', get_class($this), self::$nextId++);
}
}{epilogue}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
public function __clone()
{
$this->invocationMocker = clone $this->__phpunit_getInvocationMocker();
$this->__phpunit_setId();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
public function __clone()
{
$this->invocationMocker = clone $this->__phpunit_getInvocationMocker();
$this->__phpunit_setId();
parent::__clone();
}
6 changes: 4 additions & 2 deletions Tests/MockObject/class.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
protected static $staticInvocationMocker;
protected $invocationMocker;
protected $id;
protected static $nextId = 0;

public function __clone()
{
$this->invocationMocker = clone $this->__phpunit_getInvocationMocker();
$this->__phpunit_setId();
}

public function bar(Foo $foo)
Expand Down Expand Up @@ -128,8 +130,8 @@ class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
$this->id = NULL;
}

public function __phpunit_setId($id)
public function __phpunit_setId()
{
$this->id = $id;
$this->id = sprintf('%s#%s', get_class($this), self::$nextId++);
}
}
6 changes: 4 additions & 2 deletions Tests/MockObject/class_call_parent_clone.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
protected static $staticInvocationMocker;
protected $invocationMocker;
protected $id;
protected static $nextId = 0;

public function __clone()
{
$this->invocationMocker = clone $this->__phpunit_getInvocationMocker();
$this->__phpunit_setId();
parent::__clone();
}

Expand Down Expand Up @@ -81,9 +83,9 @@ class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
$this->id = NULL;
}

public function __phpunit_setId($id)
public function __phpunit_setId()
{
$this->id = $id;
$this->id = sprintf('%s#%s', get_class($this), self::$nextId++);
}
}

6 changes: 4 additions & 2 deletions Tests/MockObject/class_call_parent_constructor.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
protected static $staticInvocationMocker;
protected $invocationMocker;
protected $id;
protected static $nextId = 0;

public function __clone()
{
$this->invocationMocker = clone $this->__phpunit_getInvocationMocker();
$this->__phpunit_setId();
}

public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher)
Expand Down Expand Up @@ -80,9 +82,9 @@ class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
$this->id = NULL;
}

public function __phpunit_setId($id)
public function __phpunit_setId()
{
$this->id = $id;
$this->id = sprintf('%s#%s', get_class($this), self::$nextId++);
}
}

6 changes: 4 additions & 2 deletions Tests/MockObject/class_dont_call_parent_clone.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
protected static $staticInvocationMocker;
protected $invocationMocker;
protected $id;
protected static $nextId = 0;

public function __clone()
{
$this->invocationMocker = clone $this->__phpunit_getInvocationMocker();
$this->__phpunit_setId();
}

public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher)
Expand Down Expand Up @@ -80,9 +82,9 @@ class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
$this->id = NULL;
}

public function __phpunit_setId($id)
public function __phpunit_setId()
{
$this->id = $id;
$this->id = sprintf('%s#%s', get_class($this), self::$nextId++);
}
}

6 changes: 4 additions & 2 deletions Tests/MockObject/class_dont_call_parent_constructor.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
protected static $staticInvocationMocker;
protected $invocationMocker;
protected $id;
protected static $nextId = 0;

public function __clone()
{
$this->invocationMocker = clone $this->__phpunit_getInvocationMocker();
$this->__phpunit_setId();
}

public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher)
Expand Down Expand Up @@ -80,9 +82,9 @@ class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
$this->id = NULL;
}

public function __phpunit_setId($id)
public function __phpunit_setId()
{
$this->id = $id;
$this->id = sprintf('%s#%s', get_class($this), self::$nextId++);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
protected static $staticInvocationMocker;
protected $invocationMocker;
protected $id;
protected static $nextId = 0;

public function __clone()
{
$this->invocationMocker = clone $this->__phpunit_getInvocationMocker();
$this->__phpunit_setId();
}

public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher)
Expand Down Expand Up @@ -85,9 +87,9 @@ class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
$this->id = NULL;
}

public function __phpunit_setId($id)
public function __phpunit_setId()
{
$this->id = $id;
$this->id = sprintf('%s#%s', get_class($this), self::$nextId++);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
protected static $staticInvocationMocker;
protected $invocationMocker;
protected $id;
protected static $nextId = 0;

public function __clone()
{
$this->invocationMocker = clone $this->__phpunit_getInvocationMocker();
$this->__phpunit_setId();
}

public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher)
Expand Down Expand Up @@ -85,9 +87,9 @@ class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
$this->id = NULL;
}

public function __phpunit_setId($id)
public function __phpunit_setId()
{
$this->id = $id;
$this->id = sprintf('%s#%s', get_class($this), self::$nextId++);
}
}

6 changes: 4 additions & 2 deletions Tests/MockObject/class_partial.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
protected static $staticInvocationMocker;
protected $invocationMocker;
protected $id;
protected static $nextId = 0;

public function __clone()
{
$this->invocationMocker = clone $this->__phpunit_getInvocationMocker();
$this->__phpunit_setId();
}

public function bar(Foo $foo)
Expand Down Expand Up @@ -107,8 +109,8 @@ class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
$this->id = NULL;
}

public function __phpunit_setId($id)
public function __phpunit_setId()
{
$this->id = $id;
$this->id = sprintf('%s#%s', get_class($this), self::$nextId++);
}
}
6 changes: 4 additions & 2 deletions Tests/MockObject/interface.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ class MockFoo implements PHPUnit_Framework_MockObject_MockObject, Foo
protected static $staticInvocationMocker;
protected $invocationMocker;
protected $id;
protected static $nextId = 0;

public function __clone()
{
$this->invocationMocker = clone $this->__phpunit_getInvocationMocker();
$this->__phpunit_setId();
}

public function bar(Foo $foo)
Expand Down Expand Up @@ -101,8 +103,8 @@ class MockFoo implements PHPUnit_Framework_MockObject_MockObject, Foo
$this->id = NULL;
}

public function __phpunit_setId($id)
public function __phpunit_setId()
{
$this->id = $id;
$this->id = sprintf('%s#%s', get_class($this), self::$nextId++);
}
}
6 changes: 4 additions & 2 deletions Tests/MockObject/invocation_object_clone_object.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
protected static $staticInvocationMocker;
protected $invocationMocker;
protected $id;
protected static $nextId = 0;

public function __clone()
{
$this->invocationMocker = clone $this->__phpunit_getInvocationMocker();
$this->__phpunit_setId();
}

public function bar(Foo $foo)
Expand Down Expand Up @@ -130,8 +132,8 @@ class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
$this->id = NULL;
}

public function __phpunit_setId($id)
public function __phpunit_setId()
{
$this->id = $id;
$this->id = sprintf('%s#%s', get_class($this), self::$nextId++);
}
}
6 changes: 4 additions & 2 deletions Tests/MockObject/invocation_static_clone_object.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
protected static $staticInvocationMocker;
protected $invocationMocker;
protected $id;
protected static $nextId = 0;

public function __clone()
{
$this->invocationMocker = clone $this->__phpunit_getInvocationMocker();
$this->__phpunit_setId();
}

public static function bar(Foo $foo)
Expand Down Expand Up @@ -130,8 +132,8 @@ class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
$this->id = NULL;
}

public function __phpunit_setId($id)
public function __phpunit_setId()
{
$this->id = $id;
$this->id = sprintf('%s#%s', get_class($this), self::$nextId++);
}
}
6 changes: 4 additions & 2 deletions Tests/MockObject/namespaced_class.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject
protected static $staticInvocationMocker;
protected $invocationMocker;
protected $id;
protected static $nextId = 0;

public function __clone()
{
$this->invocationMocker = clone $this->__phpunit_getInvocationMocker();
$this->__phpunit_setId();
}

public function bar(NS\Foo $foo)
Expand Down Expand Up @@ -131,8 +133,8 @@ class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject
$this->id = NULL;
}

public function __phpunit_setId($id)
public function __phpunit_setId()
{
$this->id = $id;
$this->id = sprintf('%s#%s', get_class($this), self::$nextId++);
}
}
6 changes: 4 additions & 2 deletions Tests/MockObject/namespaced_class_call_parent_clone.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject
protected static $staticInvocationMocker;
protected $invocationMocker;
protected $id;
protected static $nextId = 0;

public function __clone()
{
$this->invocationMocker = clone $this->__phpunit_getInvocationMocker();
$this->__phpunit_setId();
parent::__clone();
}

Expand Down Expand Up @@ -83,9 +85,9 @@ class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject
$this->id = NULL;
}

public function __phpunit_setId($id)
public function __phpunit_setId()
{
$this->id = $id;
$this->id = sprintf('%s#%s', get_class($this), self::$nextId++);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject
protected static $staticInvocationMocker;
protected $invocationMocker;
protected $id;
protected static $nextId = 0;

public function __clone()
{
$this->invocationMocker = clone $this->__phpunit_getInvocationMocker();
$this->__phpunit_setId();
}

public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher)
Expand Down Expand Up @@ -82,9 +84,9 @@ class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject
$this->id = NULL;
}

public function __phpunit_setId($id)
public function __phpunit_setId()
{
$this->id = $id;
$this->id = sprintf('%s#%s', get_class($this), self::$nextId++);
}
}

Loading

0 comments on commit 3a294a1

Please sign in to comment.