PHP code example of ivashkevitch / codeception-wiremock-extension
1. Go to this page and download the library: Download ivashkevitch/codeception-wiremock-extension 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/ */
ivashkevitch / codeception-wiremock-extension example snippets
// YourCest.php
class YourCest extends \Codeception\TestCase\Test
{
public function _after(\AcceptanceTester $I)
{
$I->cleanAllPreviousRequestsToWireMock();
}
// tests
public function tryToTest(\AcceptanceTester $I)
{
$I->expectRequestToWireMock(
WireMock::get(WireMock::urlEqualTo('/some/url'))
->willReturn(WireMock::aResponse()
->withHeader('Content-Type', 'text/plain')
->withBody('Hello world!'))
);
// Here you should execute your application in a way it requests wiremock. I do this directly to show it.
$response = file_get_contents('http://localhost:18080/some/url');
$I->assertEquals('Hello world!', $response);
$I->receivedRequestInWireMock(
WireMock::getRequestedFor(WireMock::urlEqualTo('/some/url'))
);
}
// Also, you can access wiremock-php library directly
public function moreComplexTest()
{
$wiremockPhp = Codeception\Extension\WiremockConnection::get();
// Now you can use wiremock-php library
}
}