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
- Host: GitHub
- URL: https://github.com/lstrojny/phpunit-function-mocker
- Owner: lstrojny
- Created: 2012-06-18T16:25:08.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2020-11-18T16:24:32.000Z (over 4 years ago)
- Last Synced: 2024-12-10T03:40:39.879Z (6 months ago)
- Language: PHP
- Homepage:
- Size: 26.4 KB
- Stars: 53
- Watchers: 6
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PHPUnit function mocker extension
Allows mocking otherwise untestable PHP functions through the use of namespaces.
[](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