library phpunit-function-mocker
Allows mocking otherwise untestable PHP functions through the use of namespaces
lstrojny/phpunit-function-mocker
Allows mocking otherwise untestable PHP functions through the use of namespaces
- Sunday, February 19, 2017
- by lstrojny
- Repository
- 3 Watchers
- 51 Stars
- 189,813 Installations
- PHP
- 12 Dependents
- 0 Suggesters
- 2 Forks
- 0 Open issues
- 7 Versions
- 3 % Grown
PHPUnit function mocker extension
Allows mocking otherwise untestable PHP functions through the use of namespaces., (*1)
, (*2)
<?php
namespace MyNamespace;
class Tool
{
public function isString($string)
{
return strlen($string) > 0 && ctype_alpha($string);
}
}
<?php
require_once 'PHPUnit/Extension/FunctionMocker.php';
class MyTestCase extends PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->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, (*3)
dev-master
9999999-dev
Allows mocking otherwise untestable PHP functions through the use of namespaces
Sources
Download
MIT
The Requires
The Development Requires
1.0.1
1.0.1.0
Allows mocking otherwise untestable PHP functions through the use of namespaces
Sources
Download
MIT
The Requires
The Development Requires
1.0.0
1.0.0.0
Allows mocking otherwise untestable PHP functions through the use of namespaces
Sources
Download
MIT
The Requires
The Development Requires
0.4.1
0.4.1.0
Allows mocking otherwise untestable PHP functions through the use of namespaces
Sources
Download
MIT
The Requires
The Development Requires
0.4.0
0.4.0.0
Allows mocking otherwise untestable PHP functions through the use of namespaces
Sources
Download
MIT
The Requires
The Development Requires
0.3.0
0.3.0.0
Allows mocking otherwise untestable PHP functions through the use of namespaces
Sources
Download
MIT
The Requires
The Development Requires
0.2.0
0.2.0.0
Allows mocking otherwise untestable PHP functions through the use of namespaces
Sources
Download
MIT
The Requires
The Development Requires