2022-01-17 16:02:15 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-01-27 09:30:00 +01:00
|
|
|
namespace App\Test\TestCase\Api\Broods;
|
2022-01-17 16:02:15 +01:00
|
|
|
|
|
|
|
use Cake\TestSuite\TestCase;
|
|
|
|
use App\Test\Fixture\AuthKeysFixture;
|
|
|
|
use App\Test\Fixture\BroodsFixture;
|
|
|
|
use App\Test\Helper\ApiTestTrait;
|
|
|
|
use App\Test\Helper\WireMockTestTrait;
|
|
|
|
use \WireMock\Client\WireMock;
|
|
|
|
|
|
|
|
class TestBroodConnectionApiTest extends TestCase
|
|
|
|
{
|
|
|
|
use ApiTestTrait;
|
|
|
|
use WireMockTestTrait;
|
|
|
|
|
2022-01-19 16:22:44 +01:00
|
|
|
protected const ENDPOINT = '/broods/testConnection';
|
2022-01-17 16:02:15 +01:00
|
|
|
|
|
|
|
protected $fixtures = [
|
|
|
|
'app.Organisations',
|
|
|
|
'app.Individuals',
|
|
|
|
'app.Roles',
|
|
|
|
'app.Users',
|
|
|
|
'app.AuthKeys',
|
|
|
|
'app.Broods'
|
|
|
|
];
|
|
|
|
|
|
|
|
public function testTestBroodConnection(): void
|
|
|
|
{
|
|
|
|
$this->setAuthToken(AuthKeysFixture::ADMIN_API_KEY);
|
|
|
|
$this->initializeWireMock();
|
2022-01-27 15:43:33 +01:00
|
|
|
$stub = $this->mockCerebrateStatusResponse();
|
2022-01-17 16:02:15 +01:00
|
|
|
|
|
|
|
$url = sprintf('%s/%d', self::ENDPOINT, BroodsFixture::BROOD_WIREMOCK_ID);
|
|
|
|
$this->get($url);
|
|
|
|
|
2022-01-27 15:43:33 +01:00
|
|
|
$this->verifyStubCalled($stub);
|
2022-01-17 16:02:15 +01:00
|
|
|
$this->assertResponseOk();
|
|
|
|
$this->assertResponseContains('"user": "wiremock"');
|
|
|
|
}
|
|
|
|
|
|
|
|
private function mockCerebrateStatusResponse(): \WireMock\Stubbing\StubMapping
|
|
|
|
{
|
|
|
|
return $this->getWireMock()->stubFor(
|
|
|
|
WireMock::get(WireMock::urlEqualTo('/instance/status.json'))
|
|
|
|
->willReturn(WireMock::aResponse()
|
|
|
|
->withHeader('Content-Type', 'application/json')
|
2022-01-25 18:01:51 +01:00
|
|
|
->withBody((string)json_encode(
|
|
|
|
[
|
|
|
|
"version" => "0.1",
|
|
|
|
"application" => "Cerebrate",
|
|
|
|
"user" => [
|
|
|
|
"id" => 1,
|
|
|
|
"username" => "wiremock",
|
|
|
|
"role" => [
|
|
|
|
"id" => 1
|
|
|
|
]
|
2022-01-17 16:02:15 +01:00
|
|
|
]
|
|
|
|
]
|
2022-01-25 18:01:51 +01:00
|
|
|
)))
|
2022-01-17 16:02:15 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|