PHP code example of phuedx / pinkerton

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

    

phuedx / pinkerton example snippets


function legacy_function($parameter)
{
    // Do all of the things.
}

$spy = spyOn('legacy_function')->andCallThrough();
$legacyParameter = 1;
legacy_function($legacyParameter);
var_dump($spy->mostRecentCall); // [‘args’ => [1]]

$spy = spyOn('legacy_function')->andCallFake(function() {
    return false;
});
var_dump(legacy_function($legacyParameter)); // false

class FooTest extends PHPUnit_Framework_TestCase
{
    public function test_bar_should_call_the_callable()
    {
        $spy = createSpy();
        $foo = new Foo();
        $foo->bar($spy);
        $this->assertEquals($spy->callCount, 1);
    }
}

/**
 * Spies on the function or method.
 *
 * The function or method is replaced with a handler that will invoke a spy
 * that wraps the original function or method.
 *
 * Note that when spying on a method, the method is replaced with the handler
 * for all instances of the class.
 *
 * @param callable $function
 * @return \Phuedx\Pinkerton\Spy The spy that will be invoked instead of the
 *  function or method
 */
function spyOn($function) {}

/**
 * Stops spying on the function or method.
 *
 * The original function or method is restored but the spy is unaffected.
 *
 * @param callable $function
 * @throws \InvalidArgumentException When the function or method isn't being
 *  spied on
 */
function stopSpyingOn($function) {}

/**
 * Creates a spy that doesn't wrap a function or method.
 *
 * @return \Phuedx\Pinkerton\Spy
 */
function createSpy() {}