Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix AbstractTestApi::mockRequest assertions #150

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/CrowdinApiClient/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,13 @@ protected function _create(string $path, string $modelName, array $data)
*/
protected function _delete(string $path, array $params = [])
{
return $this->client->apiRequest('delete', $path, null, $params);
$options = [];

if (!empty($params)) {
$options['params'] = $params;
}

return $this->client->apiRequest('delete', $path, null, $options);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/CrowdinApiClient/Api/AbstractTestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ public function mockRequest(array $params)
}

if (isset($params['body'])) {
$this->assertEquals($params['body'], $params['body']);
$this->assertEquals($params['body'], $options['body']);
}
if (isset($params['header'])) {
$this->assertEquals($params['header'], $params['header']);
$this->assertEquals($params['header'], $options['header']);
}
return $params['response'] ?? null;
return $params['response'] ?? '';
}));
}

Expand Down
2 changes: 1 addition & 1 deletion tests/CrowdinApiClient/Api/BranchApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function testCreate()
$this->mockRequest([
'path' => '/projects/2/branches',
'method' => 'post',
'body' => $params,
'body' => json_encode($params),
'response' => '{
"data": {
"id": 34,
Expand Down
4 changes: 2 additions & 2 deletions tests/CrowdinApiClient/Api/BundleApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function testCreate()
$this->mockRequest([
'path' => '/projects/2/bundles',
'method' => 'post',
'body' => $params,
'body' => json_encode($params),
'response' => '{
"data": {
"id": 34,
Expand Down Expand Up @@ -247,7 +247,7 @@ public function testExport()
$this->mockRequest([
'path' => '/projects/1/bundles/2/exports',
'method' => 'post',
'body' => $params,
'body' => json_encode($params),
'response' => '{
"data": {
"identifier": "50fb3506-4127-4ba8-8296-f97dc7e3e0c3",
Expand Down
2 changes: 1 addition & 1 deletion tests/CrowdinApiClient/Api/DirectoryApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function testCreate()
$this->mockRequest([
'path' => '/projects/2/directories',
'method' => 'post',
'body' => $params,
'body' => json_encode($params),
'response' => '{
"data": {
"id": 34,
Expand Down
2 changes: 1 addition & 1 deletion tests/CrowdinApiClient/Api/DistributionApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function testCreate()
$this->mockRequest([
'path' => '/projects/2/distributions',
'method' => 'post',
'body' => $params,
'body' => json_encode($params),
'response' => '{
"data": {
"hash": "e-4326c06be14321dd967b161a",
Expand Down
6 changes: 3 additions & 3 deletions tests/CrowdinApiClient/Api/Enterprise/AbstractTestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public function mockRequest(array $params)
}

if (isset($params['body'])) {
$this->assertEquals($params['body'], $params['body']);
$this->assertEquals($params['body'], $options['body']);
}
if (isset($params['header'])) {
$this->assertEquals($params['header'], $params['header']);
$this->assertEquals($params['header'], $options['header']);
}
return $params['response'] ?? null;
return $params['response'] ?? '';
}));
}

Expand Down
2 changes: 1 addition & 1 deletion tests/CrowdinApiClient/Api/Enterprise/FileApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function testBuildReviewedSourceFiles()
$this->mockRequest([
'path' => '/projects/2/strings/reviewed-builds',
'method' => 'post',
'body' => $params,
'body' => json_encode($params),
'response' => '{
"data": {
"id": 44,
Expand Down
12 changes: 7 additions & 5 deletions tests/CrowdinApiClient/Api/Enterprise/GlossaryApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function testCreate()
$this->mockRequest([
'path' => '/glossaries',
'method' => 'post',
'body' => $params,
'body' => json_encode($params),
'response' => '{
"data": {
"id": 2,
Expand Down Expand Up @@ -140,13 +140,15 @@ public function testDelete()

public function testExport()
{
$params = [
'format' => 'tbx',
'exportFields' => ['term', 'description', 'partOfSpeech'],
];

$this->mockRequest([
'path' => '/glossaries/2/exports',
'method' => 'post',
'body' => [
'format' => 'tbx',
'exportFields' => [ 'term', 'description', 'partOfSpeech' ],
],
'body' => json_encode($params),
'response' => '{
"data": {
"identifier": "5ed2ce93-6d47-4402-9e66-516ca835cb20",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function testCreate()
$this->mockRequest([
'path' => '/mts',
'method' => 'post',
'body' => $params,
'body' => json_encode($params),
'response' => '{
"data": {
"id": 2,
Expand Down
2 changes: 1 addition & 1 deletion tests/CrowdinApiClient/Api/Enterprise/ProjectApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function testCreate()
$this->mockRequest([
'path' => '/projects',
'method' => 'post',
'body' => $params,
'body' => json_encode($params),
'response' => '{
"data": {
"id": 8,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function testCreate()
$this->mockRequest([
'path' => '/projects/2/translations',
'method' => 'post',
'body' => $params,
'body' => json_encode($params),
'response' => '{
"data": {
"id": 190695,
Expand Down Expand Up @@ -204,7 +204,7 @@ public function testCreateApproval()

$this->mockRequest([
'path' => '/projects/2/approvals',
'body' => $params,
'body' => json_encode($params),
'method' => 'post',
'response' => '{
"data": {
Expand Down Expand Up @@ -301,7 +301,7 @@ public function testCreateVote()
$this->mockRequest([
'path' => '/projects/2/votes',
'method' => 'post',
'body' => $params,
'body' => json_encode($params),
'response' => '{
"data": {
"id": 6643,
Expand Down
2 changes: 1 addition & 1 deletion tests/CrowdinApiClient/Api/Enterprise/TaskApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function testCreate()
$this->mockRequest([
'path' => '/projects/2/tasks',
'method' => 'post',
'body' => $params,
'body' => json_encode($params),
'response' => '{
"data": {
"id": 2,
Expand Down
4 changes: 2 additions & 2 deletions tests/CrowdinApiClient/Api/Enterprise/TeamApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function testCreate()
$this->mockRequest([
'path' => '/teams',
'method' => 'post',
'body' => $params,
'body' => json_encode($params),
'response' => '{
"data": {
"id": 2,
Expand Down Expand Up @@ -120,7 +120,7 @@ public function testAddTeamToProject()
$this->mockRequest([
'path' => '/projects/2/teams',
'method' => 'post',
'body' => $params,
'body' => json_encode($params),
'response' => '
{
"data": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function testApplyPreTranslation()
$this->mockRequest([
'path' => '/projects/2/pre-translations',
'method' => 'post',
'body' => $params,
'body' => json_encode($params),
'response' => '{
"data": {
"identifier": "9e7de270-4f83-41cb-b606-2f90631f26e2",
Expand Down
4 changes: 2 additions & 2 deletions tests/CrowdinApiClient/Api/Enterprise/UserApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function testAddProjectTeamMember()
$this->mockRequest([
'path' => '/projects/1/members',
'method' => 'post',
'body' => $params,
'body' => json_encode($params),
'response' => '{
"skipped": [],
"added": [
Expand Down Expand Up @@ -133,7 +133,7 @@ public function testReplaceProjectMemberPermissions()
$this->mockRequest([
'path' => '/projects/1/members/1',
'method' => 'put',
'body' => $params,
'body' => json_encode($params),
'response' => '{
"data": {
"id": 1,
Expand Down
2 changes: 1 addition & 1 deletion tests/CrowdinApiClient/Api/FileApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public function testCreate()
$this->mockRequest([
'path' => '/projects/2/files',
'method' => 'post',
'body' => $params,
'body' => json_encode($params),
'response' => '{
"data": {
"id": 44,
Expand Down
19 changes: 11 additions & 8 deletions tests/CrowdinApiClient/Api/GlossaryApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function testCreate()
$this->mockRequest([
'path' => '/glossaries',
'method' => 'post',
'body' => $params,
'body' => json_encode($params),
'response' => '{
"data": {
"id": 2,
Expand All @@ -80,7 +80,7 @@ public function testCreate()
}'
]);

$glossary = $this->crowdin->glossary->create(['name', 'Be My Eyes iOS\'s Glossary']);
$glossary = $this->crowdin->glossary->create(['name' => 'Be My Eyes iOS\'s Glossary']);
$this->assertInstanceOf(Glossary::class, $glossary);
$this->assertEquals(2, $glossary->getId());
}
Expand Down Expand Up @@ -141,13 +141,15 @@ public function testDelete()

public function testExport()
{
$params = [
'format' => 'tbx',
'exportFields' => ['term', 'description', 'partOfSpeech'],
];

$this->mockRequest([
'path' => '/glossaries/2/exports',
'method' => 'post',
'body' => [
'format' => 'tbx',
'exportFields' => [ 'term', 'description', 'partOfSpeech' ],
],
'body' => json_encode($params),
'response' => '{
"data": {
"identifier": "5ed2ce93-6d47-4402-9e66-516ca835cb20",
Expand Down Expand Up @@ -190,10 +192,11 @@ public function testImport()
$params = [
'storageId' => 2
];

$this->mockRequest([
'path' => '/glossaries/2/imports',
'method' => 'post',
'body' => $params,
'body' => json_encode($params),
'response' => '{
"data": {
"identifier": "c050fba2-200e-4ce1-8de4-f7ba8eb58732",
Expand Down Expand Up @@ -308,7 +311,7 @@ public function testCreateTerm()
$this->mockRequest([
'path' => '/glossaries/2/terms',
'method' => 'post',
'body' => $data,
'body' => json_encode($data),
'response' => '{
"data": {
"id": 2,
Expand Down
2 changes: 1 addition & 1 deletion tests/CrowdinApiClient/Api/LabelApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function testCreate()
$this->mockRequest([
'path' => '/projects/2/labels',
'method' => 'post',
'body' => $params,
'body' => json_encode($params),
'response' => '{
"data": {
"id": 34,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function testTranslateViaMT()
$this->mockRequest([
'path' => '/mts/2/translations',
'method' => 'post',
'body' => $params,
'body' => json_encode($params),
'response' => '{
"data": {
"sourceLanguageId": "en",
Expand Down
2 changes: 1 addition & 1 deletion tests/CrowdinApiClient/Api/ProjectApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function testCreate()
$this->mockRequest([
'path' => '/projects',
'method' => 'post',
'body' => $params,
'body' => json_encode($params),
'response' => '{
"data": {
"id": 8,
Expand Down
8 changes: 4 additions & 4 deletions tests/CrowdinApiClient/Api/ScreenshotApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function testCreate()
$this->mockRequest([
'path' => '/projects/2/screenshots',
'method' => 'post',
'body' => $params,
'body' => json_encode($params),
'response' => '{
"data": {
"id": 2,
Expand Down Expand Up @@ -193,7 +193,7 @@ public function testReplace()
$this->mockRequest([
'path' => '/projects/2/screenshots/2',
'method' => 'put',
'body' => $params,
'body' => json_encode($params),
'response' => '{
"data": {
"id": 2,
Expand Down Expand Up @@ -255,7 +255,7 @@ public function testCreateTag()
$this->mockRequest([
'path' => '/projects/2/screenshots/2/tags',
'method' => 'post',
'body' => $params,
'body' => json_encode($params),
'response' => '{
"data": {
"id": 98,
Expand Down Expand Up @@ -401,7 +401,7 @@ public function testReplaceTags()
$this->mockRequest([
'path' => '/projects/2/screenshots/2/tags',
'method' => 'put',
'body' => $params
'body' => json_encode($params)
]);

$this->crowdin->screenshot->replaceTags(2, 2, $params);
Expand Down
2 changes: 1 addition & 1 deletion tests/CrowdinApiClient/Api/SourceStringApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function testCreate()
"updatedAt": "2019-09-20T13:24:01+00:00"
}
}',
'body' => $params
'body' => json_encode($params)
]);

$sourceString = $this->crowdin->sourceString->create(2, $params);
Expand Down
2 changes: 1 addition & 1 deletion tests/CrowdinApiClient/Api/StringCommentApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function testCreate()
$this->mockRequest([
'path' => '/projects/1/comments',
'method' => 'post',
'body' => $params,
'body' => json_encode($params),
'response' => '{
"data": {
"id": 2,
Expand Down
Loading
Loading