forked from sebastianbergmann/phpunit-mock-objects
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Mocking nonexistent classes in a namespace is now possible.
- Loading branch information
1 parent
4173460
commit 32a8ec6
Showing
5 changed files
with
247 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,4 +43,4 @@ | |
self::$staticInvocationMocker = NULL; | ||
$this->invocationMocker = NULL; | ||
} | ||
} | ||
}{epilogue} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--TEST-- | ||
PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', TRUE, TRUE) | ||
--FILE-- | ||
<?php | ||
require_once 'PHPUnit/Autoload.php'; | ||
|
||
$mock = PHPUnit_Framework_MockObject_Generator::generate( | ||
'Foo', | ||
array(), | ||
'MockFoo', | ||
TRUE, | ||
TRUE | ||
); | ||
|
||
print $mock['code']; | ||
?> | ||
--EXPECTF-- | ||
class Foo | ||
{ | ||
} | ||
|
||
class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject | ||
{ | ||
protected static $staticInvocationMocker; | ||
protected $invocationMocker; | ||
|
||
public function __clone() | ||
{ | ||
$this->invocationMocker = clone $this->__phpunit_getInvocationMocker(); | ||
} | ||
|
||
public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) | ||
{ | ||
return $this->__phpunit_getInvocationMocker()->expects($matcher); | ||
} | ||
|
||
public static function staticExpects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) | ||
{ | ||
return self::__phpunit_getStaticInvocationMocker()->expects($matcher); | ||
} | ||
|
||
public function __phpunit_getInvocationMocker() | ||
{ | ||
if ($this->invocationMocker === NULL) { | ||
$this->invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker; | ||
} | ||
|
||
return $this->invocationMocker; | ||
} | ||
|
||
public static function __phpunit_getStaticInvocationMocker() | ||
{ | ||
if (self::$staticInvocationMocker === NULL) { | ||
self::$staticInvocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker; | ||
} | ||
|
||
return self::$staticInvocationMocker; | ||
} | ||
|
||
public function __phpunit_verify() | ||
{ | ||
self::__phpunit_getStaticInvocationMocker()->verify(); | ||
$this->__phpunit_getInvocationMocker()->verify(); | ||
} | ||
|
||
public function __phpunit_cleanup() | ||
{ | ||
self::$staticInvocationMocker = NULL; | ||
$this->invocationMocker = NULL; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
--TEST-- | ||
PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', TRUE, TRUE) | ||
--SKIPIF-- | ||
<?php | ||
if (!version_compare(PHP_VERSION, '5.3.0', '>=')) echo 'skip: PHP 5.3 only'; | ||
?> | ||
--FILE-- | ||
<?php | ||
require_once 'PHPUnit/Autoload.php'; | ||
|
||
$mock = PHPUnit_Framework_MockObject_Generator::generate( | ||
'NS\Foo', | ||
array(), | ||
'MockFoo', | ||
TRUE, | ||
TRUE | ||
); | ||
|
||
print $mock['code']; | ||
?> | ||
--EXPECTF-- | ||
namespace NS { | ||
|
||
class Foo | ||
{ | ||
} | ||
|
||
} | ||
|
||
namespace { | ||
|
||
class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject | ||
{ | ||
protected static $staticInvocationMocker; | ||
protected $invocationMocker; | ||
|
||
public function __clone() | ||
{ | ||
$this->invocationMocker = clone $this->__phpunit_getInvocationMocker(); | ||
} | ||
|
||
public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) | ||
{ | ||
return $this->__phpunit_getInvocationMocker()->expects($matcher); | ||
} | ||
|
||
public static function staticExpects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) | ||
{ | ||
return self::__phpunit_getStaticInvocationMocker()->expects($matcher); | ||
} | ||
|
||
public function __phpunit_getInvocationMocker() | ||
{ | ||
if ($this->invocationMocker === NULL) { | ||
$this->invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker; | ||
} | ||
|
||
return $this->invocationMocker; | ||
} | ||
|
||
public static function __phpunit_getStaticInvocationMocker() | ||
{ | ||
if (self::$staticInvocationMocker === NULL) { | ||
self::$staticInvocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker; | ||
} | ||
|
||
return self::$staticInvocationMocker; | ||
} | ||
|
||
public function __phpunit_verify() | ||
{ | ||
self::__phpunit_getStaticInvocationMocker()->verify(); | ||
$this->__phpunit_getInvocationMocker()->verify(); | ||
} | ||
|
||
public function __phpunit_cleanup() | ||
{ | ||
self::$staticInvocationMocker = NULL; | ||
$this->invocationMocker = NULL; | ||
} | ||
} | ||
|
||
} |
83 changes: 83 additions & 0 deletions
83
Tests/MockObject/nonexistent_class_with_namespace_starting_with_separator.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
--TEST-- | ||
PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', TRUE, TRUE) | ||
--SKIPIF-- | ||
<?php | ||
if (!version_compare(PHP_VERSION, '5.3.0', '>=')) echo 'skip: PHP 5.3 only'; | ||
?> | ||
--FILE-- | ||
<?php | ||
require_once 'PHPUnit/Autoload.php'; | ||
|
||
$mock = PHPUnit_Framework_MockObject_Generator::generate( | ||
'\NS\Foo', | ||
array(), | ||
'MockFoo', | ||
TRUE, | ||
TRUE | ||
); | ||
|
||
print $mock['code']; | ||
?> | ||
--EXPECTF-- | ||
namespace NS { | ||
|
||
class Foo | ||
{ | ||
} | ||
|
||
} | ||
|
||
namespace { | ||
|
||
class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject | ||
{ | ||
protected static $staticInvocationMocker; | ||
protected $invocationMocker; | ||
|
||
public function __clone() | ||
{ | ||
$this->invocationMocker = clone $this->__phpunit_getInvocationMocker(); | ||
} | ||
|
||
public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) | ||
{ | ||
return $this->__phpunit_getInvocationMocker()->expects($matcher); | ||
} | ||
|
||
public static function staticExpects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) | ||
{ | ||
return self::__phpunit_getStaticInvocationMocker()->expects($matcher); | ||
} | ||
|
||
public function __phpunit_getInvocationMocker() | ||
{ | ||
if ($this->invocationMocker === NULL) { | ||
$this->invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker; | ||
} | ||
|
||
return $this->invocationMocker; | ||
} | ||
|
||
public static function __phpunit_getStaticInvocationMocker() | ||
{ | ||
if (self::$staticInvocationMocker === NULL) { | ||
self::$staticInvocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker; | ||
} | ||
|
||
return self::$staticInvocationMocker; | ||
} | ||
|
||
public function __phpunit_verify() | ||
{ | ||
self::__phpunit_getStaticInvocationMocker()->verify(); | ||
$this->__phpunit_getInvocationMocker()->verify(); | ||
} | ||
|
||
public function __phpunit_cleanup() | ||
{ | ||
self::$staticInvocationMocker = NULL; | ||
$this->invocationMocker = NULL; | ||
} | ||
} | ||
|
||
} |