PHP code example of phrity / net-mock

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

    

phrity / net-mock example snippets


use Phrity\Net\StreamFactory as RealStreamFactory;
use Phrity\Net\Mock\StreamFactory as MockStreamFactory;

// Your code should allow setting stream classes
$my_stream_user = new StreamUsingClass();
$my_stream_user->setStreamfactory($mock ? new MockStreamFactory() : new RealStreamFactory());
$my_stream_user->run();

use Phrity\Net\Mock\EchoLogger;
use Phrity\Net\Mock\Mock;
use Phrity\Net\Mock\StreamFactory;

Mock::setLogger(new EchoLogger());

$my_stream_user = new StreamUsingClass();
$my_stream_user->setStreamfactory(new StreamFactory());
$my_stream_user->run();

use Phrity\Net\Mock\Mock;
use Phrity\Net\Mock\StreamFactory;

Mock::setCallback(function (int $counter, string $method, array $params, callable $default) {
    // Assert call and parameters
    // The returned value will be passed back to calling code.
    // If you want to return the result of original code, use the $default callable
    return $default();
});

$my_stream_user = new StreamUsingClass();
$my_stream_user->setStreamfactory(new StreamFactory());
$my_stream_user->run();