PHP code example of hjerichen / prophecy-php

1. Go to this page and download the library: Download hjerichen/prophecy-php 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/ */

    

hjerichen / prophecy-php example snippets




namespace Some\Space;

use PHPUnit\Framework\TestCase;
use HJerichen\ProphecyPHP\PHPProphetTrait;
use HJerichen\ProphecyPHP\NamespaceProphecy;

class SomeTest extends TestCase
{
    use PHPProphetTrait;

    /** @var NamespaceProphecy */
    private $php;

    public function setUp(): void
    {
        parent::setUp();

        $this->php = $this->prophesizePHP(__NAMESPACE__);
    }

    public function testSomething(): void
    {
        $this->php->time()->willReturn(2);
        $this->php->reveal();

        self::assertEquals(2, time());
    }
}



$this->php->time()->willReturn(1234, 1235, 1236);

$this->php->date('Y', 1234)->willReturn('1970');
$this->php->date('Y', 1234000)->willReturn('1971');

$this->php->file_put_contents('/to/foo.txt', 'some content')->shouldBeCalledOnce();
$this->php->file_put_contents('/to/foo.txt2', 'some content')->shouldBeCalledOnce();

$this->php->file_put_contents('/to/foo.txt', \Prophecy\Argument::any())->shouldNotBeCalled();

$this->php->reveal(); //Only with this call the above functions will be mocked.



$this->php->prepare('time', 'date'); //If you have problems with the time and date functions.