PHP code example of leeshan87 / module-fake-api

1. Go to this page and download the library: Download leeshan87/module-fake-api 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/ */

    

leeshan87 / module-fake-api example snippets



$I = new ServiceGuy($scenario);
$I->wantTo('Save some api calls for testing');
$I->setUpstreamUrl('https://example.com');
$I->initFakeServer();
$I->assertEmpty($I->grabRecordedRequests());
$I->assertEmpty($I->grabRecordedResponses());
$I->sendRequest('GET', '/');
$I->waitTillNextRequestResolves();
$I->assertNotEmpty($I->grabRecordedRequests());
$I->assertNotEmpty($I->grabRecordedResponses());
// Record all uncovered API call for 30 sec
//$I->recordRequestsForSeconds(30);
//$I->waitTillFakeApiRecordingEnds();
$I->stopFakeApi();
// Save Requests if needed
//$I->saveRecordedInformation(codecept_output_dir(date('Y_m_d_H_i_s') . ".json"));


 // find vendor dir if possible
$dir = __DIR__;
$ds = DIRECTORY_SEPARATOR;
for ($i = 0; $i < 3; $i++) {
    $projectRootDir = dirname($dir);
    if (!is_dir("$projectRootDir{$ds}vendor")) {
        $dir = $projectRootDir;
        continue;
    }
    );
$api->initFakeServer();
$api->addMessage(200, [], 'hello');
$api->addMessage(200, [], 'hello w');
$api->addMessage(200, [], 'hello wor');
$api->addMessage(200, [], 'hello world');
$api->run();