https://github.com/formapro/phpunitextensions
Some useful extensions for phpunit.
https://github.com/formapro/phpunitextensions
Last synced: 2 months ago
JSON representation
Some useful extensions for phpunit.
- Host: GitHub
- URL: https://github.com/formapro/phpunitextensions
- Owner: formapro
- License: mit
- Created: 2013-01-25T07:51:14.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2013-02-02T19:57:29.000Z (over 13 years ago)
- Last Synced: 2025-01-12T07:44:00.478Z (over 1 year ago)
- Language: PHP
- Size: 164 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
PhpunitExtensions
=================
Write attribute extension
-------------------------
It is simple extension which allows to access protected properties. It is like readAttribute shipped with phpunit.
```php
id;
}
}
class FooTest extends PHPUnit_Framework_TestCase
{
use \Fp\PhpunitExtension\WriteAttributeTrait;
public function testReturnExpectedId()
{
$foo = new Foo;
$this->writeAttribute($foo, 'id', 10);
$this->assertEquals(10, $foo->getId());
//or
$this->writeIdAttribute($foo, 20);
$this->assertEquals(20, $foo->getId());
}
}
```
Stub extension
--------------
```php
getStub('Foo', array(
'bar' => 'barResult',
'baz' => $this->returnValueMap(array(
array('theArg', 'bazResult')
))
));
$this->assertEquals('barResult', $fooStub->bar());
$this->assertEquals('bazResult', $fooStub->baz('theArg'));
}
}
```
As you can see the constructor is **overwritten**.
You can define returned values or pass instance of `PHPUnit_Framework_MockObject_Stub`.
There is an [issue](https://github.com/sebastianbergmann/phpunit/issues/550) at phpunit.
Fumocker extension
------------------
This extension could be used to mock function. For that you have to install [fp\fumocker](https://github.com/formapro/Fumocker) lib first.
```php
setUpExtensions();
}
public function tearDown()
{
$this->tearDownExtensions();
}
public function testFoo()
{
$expectedEmailTo = 'admin@example.com';
/**
* @var $mock \PHPUnit_Framework_MockObject_MockObject
*/
$mock = $this->getFunctionMock('Namespace/Where/Tested/Class/Is', 'mail');
$mock
->expects($this->once())
->method('mail')
->with($expectedEmailTo)
;
//test your Namespace/Where/Tested/Class/Is/Foo class
}
}