PHP code example of mcustiel / phiremock-codeception-module

1. Go to this page and download the library: Download mcustiel/phiremock-codeception-module 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/ */

    

mcustiel / phiremock-codeception-module example snippets



$I->takeConnection('secure-host')->reset();

$I->takeConnection('default')->reset();


namespace My\Namespace;

use Mcustiel\Phiremock\Client\Factory;
use GuzzleHttp;
use Psr\Http\Client\ClientInterface;

class FactoryWithGuzzle7 extends Factory
{
    public function createRemoteConnection(): ClientInterface
    {
        return new GuzzleHttp\Client(['allow_redirects' => false]);
    }
}

    $I->expectARequestToRemoteServiceWithAResponse(
        on(getRequest()->andUrl(isEqualTo('/some/url')))
            ->then(respond(203)->andBody('I am a response'))
    );

    $I->haveACleanSetupInRemoteService();

    $I->dontExpectRequestsInRemoteService();

    $I->haveCleanScenariosInRemoteService();

    $I->seeRemoteServiceReceived(1, getRequest()->andUrl(isEqualTo('/some/url')));

    $I->didNotReceiveRequestsInRemoteService();

    $I->grabRequestsMadeToRemoteService(getRequest()->andUrl(isEqualTo('/some/url')));

    $I->setScenarioState('scenarioName', 'newScenarioState');

    $I->takeConnection('connectionName');

    /**
     * @expectation("get_client_timeout")
     */
    public function test(FunctionalTester $I)
    {
        ...
    }

    /**
     * @expectation("edge_cases/get_client_timeout")
     */
    public function test(FunctionalTester $I)
    {
        ...
    }