library mockery-helper
a simple trait for convenient implementation of mockery mocks and spies in PHPUnit tests
unit-testing/mockery-helper
a simple trait for convenient implementation of mockery mocks and spies in PHPUnit tests
- Saturday, February 28, 2015
- by awei01
- Repository
- 1 Watchers
- 0 Stars
- 59 Installations
- PHP
- 2 Dependents
- 0 Suggesters
- 0 Forks
- 0 Open issues
- 2 Versions
- 0 % Grown
UnitTesting\MockeryHelper
Simple module to help with creating mocks using mockery. You won't have to continually reference Mockery\Mockery
and keep your tests a little DRY'er., (*1)
Installation
composer require --dev unit-testing/mockery-helper:dev-master
- or in
require-dev
block of composer.json
, add "unit-testing/mockery-helper": "dev-master"
and then run composer update
- don't forget to
require-dev
mockery/mockery
Usage
- In your phpunit test,
use UnitTesting\MockeryHelper\MockeryTrait
.
- in your
tearDown()
method call $this->closeMocks()
- When you want to mock something, use
$this->mock()
as an alias for Mockery::mock()
- You can also use
$this->spy()
as an alias for Mockery::spy()
- Use the result of one of the above function calls as you normally would for your assertions.
-
mockery
method simply forwards any call to the Mockery static. The first argument is the method, and subsequent arguments are params for the Mockery method.
Example
<?php
use UnitTesting\MockeryHelper\MockeryTrait;
class SomeTest extends \PHPUnit_Framework_Testcase {
use MockeryTrait;
protected function tearDown()
{
$this->cleanUpSomeStuffBeforeEachTest();
$this->closeMocks();
}
function testSomeMethodWithAMock()
{
$mock = $this->mock('Child');
$parent = new ParentThatDependsChild($mock);
$mock->shouldReceive('doSomething')->once()->with($this->mockery('type', 'string'))->andReturn('result');
$result = $parent->someMethodWhichCallsDoSomethingOfChild('foo');
$this->assertEquals('result', $result);
}
}
dev-master
9999999-dev
a simple trait for convenient implementation of mockery mocks and spies in PHPUnit tests
Sources
Download
MIT
The Requires
The Development Requires
mockery
phpunit
testing
trait
v1.0.0
1.0.0.0
a simple trait for convenient implementation of mockery mocks and spies in PHPUnit tests
Sources
Download
MIT
The Requires
The Development Requires
mockery
phpunit
testing
trait