-
Notifications
You must be signed in to change notification settings - Fork 8
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
Showing
2 changed files
with
142 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
namespace Polidog\Chatwork\Api\Rooms; | ||
|
||
|
||
use Polidog\Chatwork\Collection\CollectionInterface; | ||
use Polidog\Chatwork\Entity\Message; | ||
|
||
/** | ||
* Class Messages | ||
* @package Polidog\Chatwork\Api\Rooms | ||
*/ | ||
class Messages extends AbstractRoomApi | ||
{ | ||
/** | ||
* @param bool $force | ||
* @return CollectionInterface | ||
*/ | ||
public function show($force = false) | ||
{ | ||
return $this->factory->collection( | ||
$this->client->get( | ||
['rooms/{roomId}/messages',['roomId' => $this->roomId]], | ||
[ | ||
'query' => [ | ||
'force' => (int)$force | ||
] | ||
] | ||
)->json() | ||
); | ||
} | ||
|
||
/** | ||
* @param $id | ||
* @param bool $force | ||
* @return Message | ||
*/ | ||
public function detail($id, $force = false) | ||
{ | ||
return $this->factory->entity( | ||
$this->client->get( | ||
['rooms/{roomId}/messages/{id}', | ||
[ | ||
'roomId' => $this->roomId, | ||
'id' => $id | ||
] | ||
], | ||
[ | ||
'query' => [ | ||
'force' => (int)$force | ||
] | ||
] | ||
)->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,87 @@ | ||
<?php | ||
namespace Polidog\Chatwork\Api\Rooms; | ||
|
||
|
||
use GuzzleHttp\ClientInterface; | ||
use GuzzleHttp\Message\ResponseInterface; | ||
|
||
use Phake; | ||
use Polidog\Chatwork\Entity\Factory\FactoryInterface; | ||
|
||
class MessagesTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function 一覧を取得する() | ||
{ | ||
$httpClient = Phake::mock(ClientInterface::class); | ||
$response = Phake::mock(ResponseInterface::class); | ||
$factory = Phake::mock(FactoryInterface::class); | ||
|
||
Phake::when($httpClient) | ||
->get($this->isType('array'), $this->isType('array')) | ||
->thenReturn($response); | ||
|
||
Phake::when($response) | ||
->json() | ||
->thenReturn([]); | ||
|
||
$messages = new Messages(1, $httpClient, $factory); | ||
$messages->show(); | ||
|
||
Phake::verify($httpClient,Phake::times(1)) | ||
->get( | ||
['rooms/{roomId}/messages',['roomId' => 1]], | ||
[ | ||
'query' => [ | ||
'force' => 0 | ||
] | ||
] | ||
); | ||
|
||
Phake::verify($response,Phake::times(1)) | ||
->json(); | ||
|
||
Phake::verify($factory,Phake::times(1)) | ||
->collection($this->isType('array')); | ||
|
||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function idを指定してメッセージを取得する() | ||
{ | ||
$httpClient = Phake::mock(ClientInterface::class); | ||
$response = Phake::mock(ResponseInterface::class); | ||
$factory = Phake::mock(FactoryInterface::class); | ||
|
||
Phake::when($httpClient) | ||
->get($this->isType('array'), $this->isType('array')) | ||
->thenReturn($response); | ||
|
||
Phake::when($response) | ||
->json() | ||
->thenReturn([]); | ||
|
||
$messages = new Messages(1, $httpClient, $factory); | ||
$messages->detail(1); | ||
|
||
Phake::verify($httpClient,Phake::times(1)) | ||
->get( | ||
['rooms/{roomId}/messages/{id}',['roomId' => 1,'id' => 1]], | ||
[ | ||
'query' => [ | ||
'force' => 0 | ||
] | ||
] | ||
); | ||
|
||
Phake::verify($response,Phake::times(1)) | ||
->json(); | ||
|
||
Phake::verify($factory,Phake::times(1)) | ||
->entity($this->isType('array')); | ||
} | ||
} |