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
);
$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(array('entity_id' => 1), 'constructorArgs', $mock);
}
......@@ -39,7 +39,7 @@ class EcomDev_PHPUnitTest_Test_Helper_Mock extends EcomDev_PHPUnit_Test_Case
);
$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(array('entity_id' => 1), 'constructorArgs', $mock);
}
......@@ -52,7 +52,7 @@ class EcomDev_PHPUnitTest_Test_Helper_Mock extends EcomDev_PHPUnit_Test_Case
);
$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(array('product_id' => 1), 'constructorArgs', $mock);
}
......@@ -65,7 +65,7 @@ class EcomDev_PHPUnitTest_Test_Helper_Mock extends EcomDev_PHPUnit_Test_Case
);
$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('some_value', 'constructorArgs', $mock);
}
......
......@@ -102,22 +102,6 @@ class EcomDev_PHPUnitTest_Test_Lib_Mock_Proxy extends PHPUnit_Framework_TestCase
$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()
{
$this->assertAttributeEmpty('mockInstance', $this->mockProxy);
......
......@@ -16,6 +16,8 @@
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
use EcomDev_Utils_Reflection as ReflectionUtil;
/**
* PHPUnit Mock Object Proxy
*
......@@ -35,7 +37,9 @@ class EcomDev_PHPUnit_Mock_Proxy
*/
public function addMethod($methodName)
{
$this->methods[] = $methodName;
$methods = ReflectionUtil::getRestrictedPropertyValue($this, 'methods');
$methods[] = $methodName;
ReflectionUtil::setRestrictedPropertyValue($this, 'methods', $methods);
return $this;
}
......@@ -48,10 +52,12 @@ class EcomDev_PHPUnit_Mock_Proxy
*/
public function removeMethod($methodName)
{
$methodIndex = array_search($methodName, $this->methods);
$methods = ReflectionUtil::getRestrictedPropertyValue($this, 'methods');
$methodIndex = array_search($methodName, $methods);
if ($methodIndex !== false) {
array_splice($this->methods, $methodIndex, 1);
array_splice($methods, $methodIndex, 1);
}
ReflectionUtil::setRestrictedPropertyValue($this, 'methods', $methods);
return $this;
}
......@@ -74,7 +80,9 @@ class EcomDev_PHPUnit_Mock_Proxy
public function getMockInstance()
{
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->getMockForAbstractClass() : $this->getMock();
}
......@@ -106,57 +114,43 @@ class EcomDev_PHPUnit_Mock_Proxy
}
/**
* Registers a new static expectation in the mock object and returns the
* match object which can be infused with further details.
* Returns invocation mocker for
*
* @param PHPUnit_Framework_MockObject_Matcher_Invocation $matcher
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
* @throws RuntimeException in case if you call it
* @throws RuntimeException
* @return PHPUnit_Framework_MockObject_InvocationMocker
*/
public static function staticExpects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher)
public function __phpunit_getInvocationMocker()
{
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
* 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
* Returns static invocation mocker
*
* @throws RuntimeException
* @return PHPUnit_Framework_MockObject_InvocationMocker
*/
public function __phpunit_getInvocationMocker()
public static function __phpunit_getStaticInvocationMocker()
{
throw new RuntimeException(
'Mock object proxy cannot be used for retrieving invocation mockers, '
. 'use getMockInstance method for real mock object'
. 'use getMockInstance method for real mock object'
);
}
/**
* Returns static invocation mocker
*
* @throws RuntimeException
* @param $originalObject
* @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(
'Mock object proxy cannot be used for retrieving invocation mockers, '
. 'use getMockInstance method for real mock object'
. 'use getMockInstance method for real mock object'
);
}
......@@ -170,7 +164,7 @@ class EcomDev_PHPUnit_Mock_Proxy
{
throw new RuntimeException(
'Mock object proxy cannot be used for verifying mock'
. 'use getMockInstance method for real mock object'
. 'use getMockInstance method for real mock object'
);
}
......@@ -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