-
-
Notifications
You must be signed in to change notification settings - Fork 522
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
18c9eea
commit 728a944
Showing
9 changed files
with
197 additions
and
0 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
61 changes: 61 additions & 0 deletions
61
src/Responses/Threads/Messages/ThreadMessageDeleteResponse.php
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,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenAI\Responses\Threads\Messages; | ||
|
||
use OpenAI\Contracts\ResponseContract; | ||
use OpenAI\Contracts\ResponseHasMetaInformationContract; | ||
use OpenAI\Responses\Concerns\ArrayAccessible; | ||
use OpenAI\Responses\Concerns\HasMetaInformation; | ||
use OpenAI\Responses\Meta\MetaInformation; | ||
use OpenAI\Testing\Responses\Concerns\Fakeable; | ||
|
||
/** | ||
* @implements ResponseContract<array{id: string, object: string, deleted: bool}> | ||
*/ | ||
final class ThreadMessageDeleteResponse implements ResponseContract, ResponseHasMetaInformationContract | ||
{ | ||
/** | ||
* @use ArrayAccessible<array{id: string, object: string, deleted: bool}> | ||
*/ | ||
use ArrayAccessible; | ||
|
||
use Fakeable; | ||
use HasMetaInformation; | ||
|
||
private function __construct( | ||
public readonly string $id, | ||
public readonly string $object, | ||
public readonly bool $deleted, | ||
private readonly MetaInformation $meta, | ||
) { | ||
} | ||
|
||
/** | ||
* Acts as static factory, and returns a new Response instance. | ||
* | ||
* @param array{id: string, object: string, deleted: bool} $attributes | ||
*/ | ||
public static function from(array $attributes, MetaInformation $meta): self | ||
{ | ||
return new self( | ||
$attributes['id'], | ||
$attributes['object'], | ||
$attributes['deleted'], | ||
$meta, | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function toArray(): array | ||
{ | ||
return [ | ||
'id' => $this->id, | ||
'object' => $this->object, | ||
'deleted' => $this->deleted, | ||
]; | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
tests/Responses/Threads/Messages/ThreadMessageDeleteResponse.php
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,47 @@ | ||
<?php | ||
|
||
use OpenAI\Responses\Meta\MetaInformation; | ||
use OpenAI\Responses\Threads\Messages\ThreadMessageDeleteResponse; | ||
|
||
test('from', function () { | ||
$result = ThreadMessageDeleteResponse::from(threadMessageDeleteResource(), meta()); | ||
|
||
expect($result) | ||
->id->toBe('msg_KNsDDwE41BUAHhcPNpDkdHWZ') | ||
->object->toBe('thread.message.deleted') | ||
->deleted->toBe(true) | ||
->meta()->toBeInstanceOf(MetaInformation::class); | ||
}); | ||
|
||
test('as array accessible', function () { | ||
$result = ThreadMessageDeleteResponse::from(threadMessageDeleteResource(), meta()); | ||
|
||
expect($result['id']) | ||
->toBe('msg_KNsDDwE41BUAHhcPNpDkdHWZ'); | ||
}); | ||
|
||
test('to array', function () { | ||
$result = ThreadMessageDeleteResponse::from(threadMessageDeleteResource(), meta()); | ||
|
||
expect($result->toArray()) | ||
->toBe(threadMessageDeleteResource()); | ||
}); | ||
|
||
test('fake', function () { | ||
$response = ThreadMessageDeleteResponse::fake(); | ||
|
||
expect($response) | ||
->id->toBe('msg_KNsDDwE41BUAHhcPNpDkdHWZ') | ||
->deleted->toBe(true); | ||
}); | ||
|
||
test('fake with override', function () { | ||
$response = ThreadMessageDeleteResponse::fake([ | ||
'id' => 'msg_1234', | ||
'deleted' => false, | ||
]); | ||
|
||
expect($response) | ||
->id->toBe('msg_1234') | ||
->deleted->toBe(false); | ||
}); |
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