Skip to content

Commit 1e4ca1c

Browse files
committed
Fix dependencies
1 parent 3b5539d commit 1e4ca1c

File tree

7 files changed

+550
-441
lines changed

7 files changed

+550
-441
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
],
1818
"require": {
1919
"php": ">=5.4",
20-
"guzzlehttp/guzzle": "^6.2"
20+
"guzzlehttp/guzzle": "^5.3",
21+
"indigophp/hash-compat": "^1.1"
2122
},
2223
"require-dev": {
23-
"phpunit/phpunit": "^5.3.2",
24+
"phpunit/phpunit": "^4.8.24",
2425
"phpmd/phpmd": "~2.4",
2526
"squizlabs/php_codesniffer": "~2.6",
2627
"apigen/apigen": "~4.1"

src/LINEBot/HTTPClient/GuzzleHTTPClient.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
use GuzzleHttp\Client;
2020
use GuzzleHttp\Exception\BadResponseException;
21+
use GuzzleHttp\Stream\Stream;
2122
use LINE\LINEBot;
2223
use LINE\LINEBot\DownloadedContents;
2324
use LINE\LINEBot\Exception\ContentsDownloadingFailedException;
@@ -67,7 +68,7 @@ public function __construct(array $args)
6768
public function get($url)
6869
{
6970
try {
70-
$res = $this->guzzle->request('GET', $url, ['headers' => $this->credentials()]);
71+
$res = $this->guzzle->get($url, ['headers' => $this->credentials()]);
7172
} catch (BadResponseException $e) {
7273
$res = $e->getResponse();
7374
}
@@ -108,7 +109,7 @@ public function post($url, array $data)
108109
]);
109110

110111
try {
111-
$res = $this->guzzle->request('POST', $url, [
112+
$res = $this->guzzle->post($url, [
112113
'headers' => $headers,
113114
'body' => $json,
114115
]);
@@ -145,11 +146,11 @@ public function downloadContents($url, $fileHandler = null)
145146
if ($fileHandler === null) {
146147
$fileHandler = tmpfile();
147148
}
148-
$stream = \GuzzleHttp\Psr7\stream_for($fileHandler);
149+
$stream = Stream::factory($fileHandler);
149150

150151
try {
151-
$res = $this->guzzle->request('GET', $url, [
152-
'sink' => $stream,
152+
$res = $this->guzzle->get($url, [
153+
'save_to' => $stream,
153154
'headers' => $this->credentials(),
154155
]);
155156
} catch (BadResponseException $e) {

tests/LINEBot/GettingContentsTest.php

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,58 +16,66 @@
1616
*/
1717
namespace LINE\Tests\LINEBot;
1818

19-
use GuzzleHttp\Handler\MockHandler;
20-
use GuzzleHttp\HandlerStack;
21-
use GuzzleHttp\Psr7\Request;
22-
use GuzzleHttp\Psr7\Response;
19+
use GuzzleHttp\Event\Emitter;
20+
use GuzzleHttp\Message\Request;
21+
use GuzzleHttp\Message\Response;
22+
use GuzzleHttp\Stream\Stream;
23+
use GuzzleHttp\Subscriber\History;
24+
use GuzzleHttp\Subscriber\Mock;
2325
use LINE\LINEBot;
2426

2527
class GettingContentsTest extends \PHPUnit_Framework_TestCase
2628
{
2729
public function testGetUserProfile()
2830
{
29-
$mock = new MockHandler([
30-
function (Request $req) {
31-
$this->assertEquals($req->getMethod(), 'GET');
32-
$this->assertEquals(
33-
$req->getUri(),
34-
'https://trialbot-api.line.me/v1/profiles?mids=DUMMY_MID_GET_DISPLAY_NAME'
35-
);
36-
37-
38-
$channelIdHeader = $req->getHeader('X-Line-ChannelID');
39-
$this->assertEquals(sizeof($channelIdHeader), 1);
40-
$this->assertEquals($channelIdHeader[0], '1000000000');
41-
42-
$channelSecretHeader = $req->getHeader('X-Line-ChannelSecret');
43-
$this->assertEquals(sizeof($channelSecretHeader), 1);
44-
$this->assertEquals($channelSecretHeader[0], 'testsecret');
45-
46-
$channelMidHeader = $req->getHeader('X-Line-Trusted-User-With-ACL');
47-
$this->assertEquals(sizeof($channelMidHeader), 1);
48-
$this->assertEquals($channelMidHeader[0], 'TEST_MID');
49-
50-
return new Response(
51-
200,
52-
[],
53-
'{"start":1,"display":1,"total":1,"count":1,"contacts":[{"displayName":"BOT API","mid":"u0047556f2e40dba2456887320ba7c76d","pictureUrl":"http://example.com/abcdefghijklmn","statusMessage":"Hello, LINE!"}]}'
54-
);
55-
},
31+
$mock = new Mock([
32+
new Response(
33+
200,
34+
[],
35+
Stream::factory('{"start":1,"display":1,"total":1,"count":1,"contacts":[{"displayName":"BOT API","mid":"u0047556f2e40dba2456887320ba7c76d","pictureUrl":"http://example.com/abcdefghijklmn","statusMessage":"Hello, LINE!"}]}')
36+
),
5637
]);
57-
$mockHandler = HandlerStack::create($mock);
5838

5939
$config = [
6040
'channelId' => '1000000000',
6141
'channelSecret' => 'testsecret',
6242
'channelMid' => 'TEST_MID',
6343
];
44+
45+
$histories = new History();
46+
$emitter = new Emitter();
47+
$emitter->attach($mock);
48+
$emitter->attach($histories);
49+
6450
$sdk = new LINEBot(
6551
$config,
66-
new LINEBot\HTTPClient\GuzzleHTTPClient(array_merge($config, ['handler' => $mockHandler]))
52+
new LINEBot\HTTPClient\GuzzleHTTPClient(array_merge($config, ['emitter' => $emitter]))
6753
);
6854

6955
$res = $sdk->getUserProfile('DUMMY_MID_GET_DISPLAY_NAME');
7056
$this->assertEquals($res['count'], 1);
7157
$this->assertEquals($res['contacts'][0]['displayName'], 'BOT API');
58+
59+
$history = $histories->getIterator()[0];
60+
61+
/** @var Request $req */
62+
$req = $history['request'];
63+
$this->assertEquals($req->getMethod(), 'GET');
64+
$this->assertEquals(
65+
$req->getUrl(),
66+
'https://trialbot-api.line.me/v1/profiles?mids=DUMMY_MID_GET_DISPLAY_NAME'
67+
);
68+
69+
$channelIdHeader = $req->getHeaderAsArray('X-Line-ChannelID');
70+
$this->assertEquals(sizeof($channelIdHeader), 1);
71+
$this->assertEquals($channelIdHeader[0], '1000000000');
72+
73+
$channelSecretHeader = $req->getHeaderAsArray('X-Line-ChannelSecret');
74+
$this->assertEquals(sizeof($channelSecretHeader), 1);
75+
$this->assertEquals($channelSecretHeader[0], 'testsecret');
76+
77+
$channelMidHeader = $req->getHeaderAsArray('X-Line-Trusted-User-With-ACL');
78+
$this->assertEquals(sizeof($channelMidHeader), 1);
79+
$this->assertEquals($channelMidHeader[0], 'TEST_MID');
7280
}
7381
}

0 commit comments

Comments
 (0)