Commit f4397a13 authored by Ivan Chepurnyi's avatar Ivan Chepurnyi

Add shortcut for replaceByMock method into mock proxy, so less code needs to be written

parent 460f4a42
...@@ -24,6 +24,7 @@ use EcomDev_PHPUnit_Helper as TestHelper; ...@@ -24,6 +24,7 @@ use EcomDev_PHPUnit_Helper as TestHelper;
* *
* @method EcomDev_PHPUnit_Mock_Proxy mockClassAlias(string $type, $classAlias, array $methods = array(), array $constructorArgs = array()) * @method EcomDev_PHPUnit_Mock_Proxy mockClassAlias(string $type, $classAlias, array $methods = array(), array $constructorArgs = array())
* @method EcomDev_PHPUnit_Mock_Proxy mockModel($classAlias, array $methods = array(), array $constructorArgs = array()) * @method EcomDev_PHPUnit_Mock_Proxy mockModel($classAlias, array $methods = array(), array $constructorArgs = array())
* @method EcomDev_PHPUnit_Mock_Proxy mockResourceModel($classAlias, array $methods = array(), array $constructorArgs = array())
* @method EcomDev_PHPUnit_Mock_Proxy mockBlock($classAlias, array $methods = array(), array $constructorArgs = array()) * @method EcomDev_PHPUnit_Mock_Proxy mockBlock($classAlias, array $methods = array(), array $constructorArgs = array())
* @method EcomDev_PHPUnit_Mock_Proxy mockHelper($classAlias, array $methods = array(), array $constructorArgs = array()) * @method EcomDev_PHPUnit_Mock_Proxy mockHelper($classAlias, array $methods = array(), array $constructorArgs = array())
* @method EcomDev_PHPUnit_Mock_Proxy mockSession($classAlias, array $methods = array()) * @method EcomDev_PHPUnit_Mock_Proxy mockSession($classAlias, array $methods = array())
......
...@@ -55,6 +55,21 @@ class EcomDev_PHPUnit_Test_Case_Helper_Mock extends EcomDev_PHPUnit_AbstractHelp ...@@ -55,6 +55,21 @@ class EcomDev_PHPUnit_Test_Case_Helper_Mock extends EcomDev_PHPUnit_AbstractHelp
return $this->helperMockClassAlias('model', $classAlias, $methods, $constructorArgs); return $this->helperMockClassAlias('model', $classAlias, $methods, $constructorArgs);
} }
/**
* Creates a mock for a resource model by its class alias
*
* @param string $classAlias
* @param array $methods
* @param array $constructorArgs
*
* @return EcomDev_PHPUnit_Mock_Proxy
*/
public function helperMockResourceModel($classAlias, array $methods = array(), array $constructorArgs = array())
{
return $this->helperMockClassAlias('resource_model', $classAlias, $methods, $constructorArgs);
}
/** /**
* Creates a mock for a block by its class alias * Creates a mock for a block by its class alias
* *
......
...@@ -501,7 +501,7 @@ class EcomDev_PHPUnit_Test_Case_Util ...@@ -501,7 +501,7 @@ class EcomDev_PHPUnit_Test_Case_Util
public static function getGroupedClassMockBuilder(PHPUnit_Framework_TestCase $testCase, $type, $classAlias) public static function getGroupedClassMockBuilder(PHPUnit_Framework_TestCase $testCase, $type, $classAlias)
{ {
$className = self::getGroupedClassName($type, $classAlias); $className = self::getGroupedClassName($type, $classAlias);
return new EcomDev_PHPUnit_Mock_Proxy($testCase, $className); return new EcomDev_PHPUnit_Mock_Proxy($testCase, $className, $classAlias);
} }
/** /**
......
...@@ -29,6 +29,26 @@ class EcomDev_PHPUnit_Mock_Proxy ...@@ -29,6 +29,26 @@ class EcomDev_PHPUnit_Mock_Proxy
{ {
protected $mockInstance; protected $mockInstance;
/**
* Original mocked class alias
*
* @var string
*/
protected $classAlias;
/**
* Added class alias as property
*
* @param PHPUnit_Framework_TestCase $testCase
* @param array|string $type
* @param null $classAlias
*/
public function __construct(PHPUnit_Framework_TestCase $testCase, $type, $classAlias = null)
{
parent::__construct($testCase, $type);
$this->classAlias = $classAlias;
}
/** /**
* Adds method name to a mock builder * Adds method name to a mock builder
* *
...@@ -113,6 +133,18 @@ class EcomDev_PHPUnit_Mock_Proxy ...@@ -113,6 +133,18 @@ class EcomDev_PHPUnit_Mock_Proxy
return $this->getMockInstance()->expects($matcher); return $this->getMockInstance()->expects($matcher);
} }
/**
* Invokes replaceByMock test util method with current mock object proxy instance
*
* @param $type
* @return $this
*/
public function replaceByMock($type)
{
EcomDev_PHPUnit_Test_Case_Util::replaceByMock($type, $this->classAlias, $this);
return $this;
}
/** /**
* Returns invocation mocker for * Returns invocation mocker for
* *
......
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