An open API service indexing awesome lists of open source software.

https://github.com/lstrojny/phpunit-function-mocker

Allow mocking otherwise unmockable functions with PHPUnit
https://github.com/lstrojny/phpunit-function-mocker

Last synced: 6 months ago
JSON representation

Allow mocking otherwise unmockable functions with PHPUnit

Awesome Lists containing this project

README

        

# PHPUnit function mocker extension

Allows mocking otherwise untestable PHP functions through the use of namespaces.

[![Build Status](https://secure.travis-ci.org/lstrojny/phpunit-function-mocker.svg)](http://travis-ci.org/lstrojny/phpunit-function-mocker)

```php
0 && ctype_alpha($string);
}
}
```

```php
php = PHPUnit_Extension_FunctionMocker::start($this, 'MyNamespace')
->mockFunction('strlen')
->mockFunction('ctype_alpha')
->getMock();
}

/** @runInSeparateProcess */
public function testIsStringUsesStrlenAndCtypeAlpha()
{
$this->php
->expects($this->once())
->method('strlen')
->with('foo')
->will($this->returnValue(3))
;
$this->php
->expects($this->once())
->method('ctype_alpha')
->with('foo')
->will($this->returnValue(false))
;

$tool = new MyNamespace\Tool();
$this->assertFalse($tool->isString('foo'));
}
}
```
### NOTE
Use `@runInSeparateProcess` annotation to make sure that the mocking is reliably working in PHP >=5.4