Skip to content

Commit

Permalink
checker and tests improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ferishili committed Sep 20, 2024
1 parent cc40e50 commit 4912323
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
7 changes: 4 additions & 3 deletions src/OpencastApi/Rest/OcRestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,10 @@ public function hasVersion($version)
// We have to use an aux object, in order to prevent overwriting arguments of current object.
$aux = clone $this;
$aux->enableNoHeader();
$options = [
'auth' => [$this->username, $this->password]
];
$options = [];
if (!empty($this->username) && !empty($this->password)) {
$options['auth'] = [$this->username, $this->password];
}
$defaultVersion = $aux->performGet('/api/version/default', $options);
if (!empty($defaultVersion['body']) && isset($defaultVersion['body']->default)) {
$this->setVersion(str_replace(['application/', 'v', '+json'], ['', '', ''], $defaultVersion['body']->default));
Expand Down
20 changes: 14 additions & 6 deletions tests/DataProvider/SetupDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,23 @@ public static function getConfig($version = ''): array
return $config;
}

public static function getMockResponses($fileName): array
public static function getMockResponses($data): array
{
$responseNames = [];
if (!is_array($data)) {
$responseNames[] = $data;
} else {
$responseNames = $data;
}
$mockResponse = [];
$mockResponsesDir = __DIR__ . "/mock_responses";
$fileFullName = basename($fileName, ".json") . '.json';
$filePath = $mockResponsesDir . "/" . $fileFullName;
if (file_exists($filePath)) {
$responseStr = file_get_contents($filePath);
$mockResponse = json_decode($responseStr, true);
foreach ($responseNames as $fileName) {
$fileFullName = basename($fileName, ".json") . '.json';
$filePath = $mockResponsesDir . "/" . $fileFullName;
if (file_exists($filePath)) {
$responseStr = file_get_contents($filePath);
$mockResponse = array_merge($mockResponse, json_decode($responseStr, true));
}
}
return $mockResponse !== false ? $mockResponse : [];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/UnitMock/OcEventsApiTestMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class OcEventsApiTestMock extends TestCase
protected function setUp(): void
{
parent::setUp();
$mockResponse = \Tests\DataProvider\SetupDataProvider::getMockResponses('api_events');
$mockResponse = \Tests\DataProvider\SetupDataProvider::getMockResponses(['api_events', 'api_base']);
if (empty($mockResponse)) {
$this->markTestIncomplete('No mock responses for events api could be found!');
}
Expand Down

0 comments on commit 4912323

Please sign in to comment.