This repository has been archived by the owner on Jan 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a90d638
commit 9a425a1
Showing
9 changed files
with
157 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dotfile\Model\Case; | ||
|
||
/** | ||
* Response when a tag has been added to a case. | ||
* | ||
* @see https://docs.dotfile.com/reference/case-tag-create-case-tags | ||
*/ | ||
class CaseTags | ||
{ | ||
/** | ||
* @var array<string, string> | ||
*/ | ||
public array $tags = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dotfile\Model\Case; | ||
|
||
/** | ||
* Input used to add a tag for a case. | ||
* | ||
* @see https://docs.dotfile.com/reference/case-tag-create-case-tags | ||
*/ | ||
class CaseTagsInput | ||
{ | ||
/** | ||
* Case id where the case is created. | ||
*/ | ||
public string $caseId; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
public ?array $tags; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dotfile\Service; | ||
|
||
use Dotfile\Model\Case\CaseTags; | ||
use Dotfile\Model\Case\CaseTagsInput; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer; | ||
|
||
class TagsCaseService extends AbstractService | ||
{ | ||
public function create(CaseTagsInput $input, string $caseId): CaseTags | ||
{ | ||
$body = $this->serializer->serialize($input, 'json', [AbstractObjectNormalizer::SKIP_NULL_VALUES => true]); | ||
|
||
$response = $this->client->request(Request::METHOD_POST, 'cases/'.$caseId.'/tags', [ | ||
'headers' => [ | ||
'Content-Type' => 'application/json', | ||
], | ||
'body' => $body, | ||
]); | ||
|
||
return $this->serializer->deserialize($this->getContent($response), CaseTags::class, 'json'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dotfile\Tests\FunctionalTests; | ||
|
||
use Dotfile\DotfileClient; | ||
use Dotfile\Model\Case\CaseTags; | ||
use Dotfile\Model\Case\CaseTagsInput; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\HttpClient\MockHttpClient; | ||
use Symfony\Component\HttpClient\Response\MockResponse; | ||
|
||
class CaseAddTagsTest extends TestCase | ||
{ | ||
public function testCaseCreateWithMinimumValidData(): void | ||
{ | ||
$client = new DotfileClient(new MockHttpClient([ | ||
new MockResponse((string) file_get_contents(__DIR__.'/../fixtures/case_add_tags_with_minimal_data_response.json')), | ||
])); | ||
|
||
$input = new CaseTagsInput(); | ||
$input->caseId = '39cbd6d5-4da5-4d94-ae71-84895c5e552a'; | ||
$input->tags = ['A faire']; | ||
|
||
$caseAddTags = $client->case->addTags($input, $input->caseId); | ||
|
||
$this->assertInstanceOf(CaseTags::class, $caseAddTags); | ||
$this->assertSame([ | ||
'id' => 'ea5c5935-2ec8-4519-a526-7ab25c71ac4e', | ||
'label' => 'A faire', | ||
], current($caseAddTags->tags)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"tags": [ | ||
{ | ||
"id": "ea5c5935-2ec8-4519-a526-7ab25c71ac4e", | ||
"label": "A faire" | ||
} | ||
] | ||
} |