PHP code example of enzyme / parrot

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

    

enzyme / parrot example snippets


class Foo
{
    public function openConfig($file)
    {
        $contents = file_get_contents($file);
        return $contents;
    }
}

public function FooTest
{
    $file = __DIR__ . '/actual_file.txt';
    $expected = 'Contents of actual_file.txt';

    $foo = new Foo;
    $actual = $foo->openConfig($file);

    $this->assertEquals($actual, $expected);
}

use Enzyme\Parrot\File;

class Foo
{
    protected $fileDispatch;

    public function __construct(File $fileDispatch)
    {
        $this->fileDispatch = $fileDispatch;
    }

    public function openConfig($file)
    {
        $contents = $this->fileDispatch->getContents($file);
        return $contents;
    }
}

public function FooTest
{
    $file = __DIR__ . '/fake_file.txt';
    $expected = 'Contents of fake_file.txt';

    $fileDispatch = m::mock('Enzyme\Parrot\File[getContents]', function ($mock) use ($expected, $file) {
        $mock->shouldReceive('getContents')->withArgs([$file, []])->times(1)->andReturn($expected);
    });


    $foo = new Foo($fileDispatch);
    $actual = $foo->openConfig($file);

    $this->assertEquals($actual, $expected);
}