IvanChepurnyi/EcomDev_PHPUnit — pull request #39 by marcinrogacki (2012-07-25 07:32:46+00:00)
Title: Marcinrogacki/tinymock

A little faster way of creating mocks. I implement it for my project to make code more tight and clean, but I thought to share it.
First version. It doesn't supports some features like Mock Builders, block the constructors, clones etc.

showcase:

```PHP
/**
* @test
*/
public function tinyMultipleMockTest()
{
$methodsExpectsWills = array(
'getUserId' => array($this->once(), $this->returnValue(1)),
'login' => array($this->exactly(1), $this->returnSelf()),
'setUsername' => array($this->any(), $this->returnCallback(array($this, 'aBitNested')))
);
$this->tinyMultipleMockMaker('model', 'admin/user', $methodsExpectsWills);

// lets test tinyMock!
$model = Mage::getModel('admin/user');
// 1
$this->assertEquals(1, $model->getUserId());
// 2
$this->assertSame(
$model,
$model->login('fake', 'fake')
);
// 3
try {
$model->setUsername('admin');
} catch (Exception $e) {
return;
}
$this->fail('Exception was not rised');
}

/**
* @test
*/
public function tinySingleMockTest()
{
$this->tinySingleMockMaker(
'model', 'admin/session', 'isAllowed', $this->any(),
$this->returnCallback(array($this, 'aBitNested'))
);

try {
Mage::getModel('admin/session')->isAllowed("admin");
} catch (Exception $e) {
return;
}
$this->fail("Callback fail");
}

public function aBitNested($name)
{
if ($name === 'admin') {
throw new Exception('in ur dreams');
}
}
```