Commit 2a12b679 authored by Ivan Chepurnyi's avatar Ivan Chepurnyi

PHPUnit 4.0 compatibility

parent 5e093a87
...@@ -26,7 +26,7 @@ class EcomDev_PHPUnitTest_Test_Helper_Mock extends EcomDev_PHPUnit_Test_Case ...@@ -26,7 +26,7 @@ class EcomDev_PHPUnitTest_Test_Helper_Mock extends EcomDev_PHPUnit_Test_Case
); );
$this->assertInstanceOf('EcomDev_PHPUnit_Mock_Proxy', $mock); $this->assertInstanceOf('EcomDev_PHPUnit_Mock_Proxy', $mock);
$this->assertAttributeEquals($this->getGroupedClassName('model', 'catalog/product'), 'className', $mock); $this->assertAttributeEquals($this->getGroupedClassName('model', 'catalog/product'), 'type', $mock);
$this->assertAttributeContains('getId', 'methods', $mock); $this->assertAttributeContains('getId', 'methods', $mock);
$this->assertAttributeContains(array('entity_id' => 1), 'constructorArgs', $mock); $this->assertAttributeContains(array('entity_id' => 1), 'constructorArgs', $mock);
} }
...@@ -39,7 +39,7 @@ class EcomDev_PHPUnitTest_Test_Helper_Mock extends EcomDev_PHPUnit_Test_Case ...@@ -39,7 +39,7 @@ class EcomDev_PHPUnitTest_Test_Helper_Mock extends EcomDev_PHPUnit_Test_Case
); );
$this->assertInstanceOf('EcomDev_PHPUnit_Mock_Proxy', $mock); $this->assertInstanceOf('EcomDev_PHPUnit_Mock_Proxy', $mock);
$this->assertAttributeEquals($this->getGroupedClassName('model', 'catalog/product'), 'className', $mock); $this->assertAttributeEquals($this->getGroupedClassName('model', 'catalog/product'), 'type', $mock);
$this->assertAttributeContains('getId', 'methods', $mock); $this->assertAttributeContains('getId', 'methods', $mock);
$this->assertAttributeContains(array('entity_id' => 1), 'constructorArgs', $mock); $this->assertAttributeContains(array('entity_id' => 1), 'constructorArgs', $mock);
} }
...@@ -52,7 +52,7 @@ class EcomDev_PHPUnitTest_Test_Helper_Mock extends EcomDev_PHPUnit_Test_Case ...@@ -52,7 +52,7 @@ class EcomDev_PHPUnitTest_Test_Helper_Mock extends EcomDev_PHPUnit_Test_Case
); );
$this->assertInstanceOf('EcomDev_PHPUnit_Mock_Proxy', $mock); $this->assertInstanceOf('EcomDev_PHPUnit_Mock_Proxy', $mock);
$this->assertAttributeEquals($this->getGroupedClassName('block', 'catalog/product_view'), 'className', $mock); $this->assertAttributeEquals($this->getGroupedClassName('block', 'catalog/product_view'), 'type', $mock);
$this->assertAttributeContains('getTemplate', 'methods', $mock); $this->assertAttributeContains('getTemplate', 'methods', $mock);
$this->assertAttributeContains(array('product_id' => 1), 'constructorArgs', $mock); $this->assertAttributeContains(array('product_id' => 1), 'constructorArgs', $mock);
} }
...@@ -65,7 +65,7 @@ class EcomDev_PHPUnitTest_Test_Helper_Mock extends EcomDev_PHPUnit_Test_Case ...@@ -65,7 +65,7 @@ class EcomDev_PHPUnitTest_Test_Helper_Mock extends EcomDev_PHPUnit_Test_Case
); );
$this->assertInstanceOf('EcomDev_PHPUnit_Mock_Proxy', $mock); $this->assertInstanceOf('EcomDev_PHPUnit_Mock_Proxy', $mock);
$this->assertAttributeEquals($this->getGroupedClassName('block', 'catalog/category'), 'className', $mock); $this->assertAttributeEquals($this->getGroupedClassName('block', 'catalog/category'), 'type', $mock);
$this->assertAttributeContains('getStoreCategories', 'methods', $mock); $this->assertAttributeContains('getStoreCategories', 'methods', $mock);
$this->assertAttributeContains('some_value', 'constructorArgs', $mock); $this->assertAttributeContains('some_value', 'constructorArgs', $mock);
} }
......
...@@ -102,22 +102,6 @@ class EcomDev_PHPUnitTest_Test_Lib_Mock_Proxy extends PHPUnit_Framework_TestCase ...@@ -102,22 +102,6 @@ class EcomDev_PHPUnitTest_Test_Lib_Mock_Proxy extends PHPUnit_Framework_TestCase
$this->assertAttributeInstanceOf('EcomDev_PHPUnit_AbstractConstraint', 'mockInstance', $this->mockProxy); $this->assertAttributeInstanceOf('EcomDev_PHPUnit_AbstractConstraint', 'mockInstance', $this->mockProxy);
} }
public function testStaticExpects()
{
$this->setExpectedException('RuntimeException', 'staticExpectsProxy');
$this->mockProxy->staticExpects($this->any());
}
public function testStaticExpectsProxy()
{
$this->assertAttributeEmpty('mockInstance', $this->mockProxy);
$this->assertInstanceOf(
'PHPUnit_Framework_MockObject_Builder_InvocationMocker',
$this->mockProxy->staticExpectsProxy($this->any())->method('compareValues')
);
$this->assertAttributeInstanceOf('EcomDev_PHPUnit_AbstractConstraint', 'mockInstance', $this->mockProxy);
}
public function testGetInvocationMocker() public function testGetInvocationMocker()
{ {
$this->assertAttributeEmpty('mockInstance', $this->mockProxy); $this->assertAttributeEmpty('mockInstance', $this->mockProxy);
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org> * @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/ */
use EcomDev_Utils_Reflection as ReflectionUtil;
/** /**
* PHPUnit Mock Object Proxy * PHPUnit Mock Object Proxy
* *
...@@ -35,7 +37,9 @@ class EcomDev_PHPUnit_Mock_Proxy ...@@ -35,7 +37,9 @@ class EcomDev_PHPUnit_Mock_Proxy
*/ */
public function addMethod($methodName) public function addMethod($methodName)
{ {
$this->methods[] = $methodName; $methods = ReflectionUtil::getRestrictedPropertyValue($this, 'methods');
$methods[] = $methodName;
ReflectionUtil::setRestrictedPropertyValue($this, 'methods', $methods);
return $this; return $this;
} }
...@@ -48,10 +52,12 @@ class EcomDev_PHPUnit_Mock_Proxy ...@@ -48,10 +52,12 @@ class EcomDev_PHPUnit_Mock_Proxy
*/ */
public function removeMethod($methodName) public function removeMethod($methodName)
{ {
$methodIndex = array_search($methodName, $this->methods); $methods = ReflectionUtil::getRestrictedPropertyValue($this, 'methods');
$methodIndex = array_search($methodName, $methods);
if ($methodIndex !== false) { if ($methodIndex !== false) {
array_splice($this->methods, $methodIndex, 1); array_splice($methods, $methodIndex, 1);
} }
ReflectionUtil::setRestrictedPropertyValue($this, 'methods', $methods);
return $this; return $this;
} }
...@@ -74,7 +80,9 @@ class EcomDev_PHPUnit_Mock_Proxy ...@@ -74,7 +80,9 @@ class EcomDev_PHPUnit_Mock_Proxy
public function getMockInstance() public function getMockInstance()
{ {
if ($this->mockInstance === null) { if ($this->mockInstance === null) {
$reflection = EcomDev_Utils_Reflection::getReflection($this->className); $reflection = ReflectionUtil::getReflection(
ReflectionUtil::getRestrictedPropertyValue($this, 'type')
);
$this->mockInstance = ($reflection->isAbstract() || $reflection->isInterface()) $this->mockInstance = ($reflection->isAbstract() || $reflection->isInterface())
? $this->getMockForAbstractClass() : $this->getMock(); ? $this->getMockForAbstractClass() : $this->getMock();
} }
...@@ -106,39 +114,26 @@ class EcomDev_PHPUnit_Mock_Proxy ...@@ -106,39 +114,26 @@ class EcomDev_PHPUnit_Mock_Proxy
} }
/** /**
* Registers a new static expectation in the mock object and returns the * Returns invocation mocker for
* match object which can be infused with further details.
* *
* @param PHPUnit_Framework_MockObject_Matcher_Invocation $matcher * @throws RuntimeException
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker * @return PHPUnit_Framework_MockObject_InvocationMocker
* @throws RuntimeException in case if you call it
*/ */
public static function staticExpects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) public function __phpunit_getInvocationMocker()
{ {
throw new RuntimeException( throw new RuntimeException(
'This method cannot be called on mock proxy, use staticExpectsProxy instead' 'Mock object proxy cannot be used for retrieving invocation mockers, '
. 'use getMockInstance method for real mock object'
); );
} }
/** /**
* Registers a new static expectation in the mock object and returns the * Returns static invocation mocker
* match object which can be infused with further details.
*
* @param PHPUnit_Framework_MockObject_Matcher_Invocation $matcher
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
*/
public function staticExpectsProxy(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher)
{
return $this->getMockInstance()->staticExpects($matcher);
}
/**
* Returns invocation mocker for
* *
* @throws RuntimeException * @throws RuntimeException
* @return PHPUnit_Framework_MockObject_InvocationMocker * @return PHPUnit_Framework_MockObject_InvocationMocker
*/ */
public function __phpunit_getInvocationMocker() public static function __phpunit_getStaticInvocationMocker()
{ {
throw new RuntimeException( throw new RuntimeException(
'Mock object proxy cannot be used for retrieving invocation mockers, ' 'Mock object proxy cannot be used for retrieving invocation mockers, '
...@@ -147,12 +142,11 @@ class EcomDev_PHPUnit_Mock_Proxy ...@@ -147,12 +142,11 @@ class EcomDev_PHPUnit_Mock_Proxy
} }
/** /**
* Returns static invocation mocker * @param $originalObject
*
* @throws RuntimeException
* @return PHPUnit_Framework_MockObject_InvocationMocker * @return PHPUnit_Framework_MockObject_InvocationMocker
* @since Method available since Release 2.0.0
*/ */
public static function __phpunit_getStaticInvocationMocker() public function __phpunit_setOriginalObject($originalObject)
{ {
throw new RuntimeException( throw new RuntimeException(
'Mock object proxy cannot be used for retrieving invocation mockers, ' 'Mock object proxy cannot be used for retrieving invocation mockers, '
...@@ -189,4 +183,5 @@ class EcomDev_PHPUnit_Mock_Proxy ...@@ -189,4 +183,5 @@ class EcomDev_PHPUnit_Mock_Proxy
); );
} }
} }
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment