1. Go to this page and download the library: Download php-mock/php-mock-phpunit library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
php-mock / php-mock-phpunit example snippets
namespace foo;
class BuiltinTest extends \PHPUnit\Framework\TestCase
{
use \phpmock\phpunit\PHPMock;
public function testTime()
{
$time = $this->getFunctionMock(__NAMESPACE__, "time");
$time->expects($this->once())->willReturn(3);
$this->assertEquals(3, time());
}
public function testExec()
{
$exec = $this->getFunctionMock(__NAMESPACE__, "exec");
$exec->expects($this->once())->willReturnCallback(
function ($command, &$output, &$return_var) {
$this->assertEquals("foo", $command);
$output = ["failure"];
$return_var = 1;
}
);
exec("foo", $output, $return_var);
$this->assertEquals(["failure"], $output);
$this->assertEquals(1, $return_var);
}
}
sh
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.