Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-mabe authored and Ocramius committed Nov 14, 2014
1 parent 75d4a25 commit 305fa3d
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions test/Storage/Adapter/AbstractAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,20 +385,45 @@ public function testGetItemReturnsNullIfFailed()
public function simpleEventHandlingMethodDefinitions()
{
return array(
array(
'name' => 'getItem',
'args' => array('key'),
'internalName' => 'internalGetItem',
'internalArgs' => array('key'),
'retVal' => 'value',
)
// name, internalName, args, internalName, returnValue
array('hasItem', 'internalGetItem', array('k'), 'v'),
array('hasItems', 'internalHasItems', array(array('k1', 'k2')), array('v1', 'v2')),

array('getItem', 'internalGetItem', array('k'), 'v'),
array('getItems', 'internalGetItems', array(array('k1', 'k2')), array('k1' => 'v1', 'k2' => 'v2')),

array('getMetadata', 'internalGetMetadata', array('k'), array()),
array('getMetadatas', 'internalGetMetadatas', array(array('k1', 'k2')), array('k1' => array(), 'k2' => array())),

array('setItem', 'internalSetItem', array('k', 'v'), true),
array('setItems', 'internalSetItems', array(array('k1' => 'v1', 'k2' => 'v2')), array()),

array('replaceItem', 'internalReplaceItem', array('k', 'v'), true),
array('replaceItems', 'internalReplaceItems', array(array('k1' => 'v1', 'k2' => 'v2')), array()),

array('addItem', 'internalAddItem', array('k', 'v'), true),
array('addItems', 'internalAddItems', array(array('k1' => 'v1', 'k2' => 'v2')), array()),

array('checkAndSetItem', 'internalCheckAndSetItem', array(123, 'k', 'v'), true),

array('touchItem', 'internalTouchItem', array('k'), true),
array('touchItems', 'internalTouchItems', array(array('k1', 'k2')), array()),

array('removeItem', 'internalRemoveItem', array('k'), true),
array('removeItems', 'internalRemoveItems', array(array('k1', 'k2')), array()),

array('incrementItem', 'internalIncrementItem', array('k', 1), true),
array('incrementItems', 'internalIncrementItems', array(array('k1' => 1, 'k2' => 2)), array()),

array('decrementItem', 'internalDecrementItem', array('k', 1), true),
array('decrementItems', 'internalDecrementItems', array(array('k1' => 1, 'k2' => 2)), array()),
);
}

/**
* @dataProvider simpleEventHandlingMethodDefinitions
*/
public function testEventHandlingSimple($methodName, $methodArgs, $internalMethodName, $internalMethodArgs, $retVal)
public function testEventHandlingSimple($methodName, $internalMethodName, $methodArgs, $retVal)
{
$this->_storage = $this->getMockForAbstractAdapter(array($internalMethodName));

Expand All @@ -413,7 +438,7 @@ public function testEventHandlingSimple($methodName, $methodArgs, $internalMetho
$mock = $this->_storage
->expects($this->once())
->method($internalMethodName);
$mock = call_user_func_array(array($mock, 'with'), array_map(array($this, 'equalTo'), $internalMethodArgs));
$mock = call_user_func_array(array($mock, 'with'), array_map(array($this, 'equalTo'), $methodArgs));
$mock->will($this->returnValue($retVal));

call_user_func_array(array($this->_storage, $methodName), $methodArgs);
Expand All @@ -428,7 +453,7 @@ public function testEventHandlingSimple($methodName, $methodArgs, $internalMetho
/**
* @dataProvider simpleEventHandlingMethodDefinitions
*/
public function testEventHandlingStopInPre($methodName, $methodArgs, $internalMethodName, $internalMethodArgs, $retVal)
public function testEventHandlingStopInPre($methodName, $internalMethodName, $methodArgs, $retVal)
{
$this->_storage = $this->getMockForAbstractAdapter(array($internalMethodName));

Expand Down

0 comments on commit 305fa3d

Please sign in to comment.