/
DecodingInputStreamTest.php
44 lines (35 loc) · 1.46 KB
/
DecodingInputStreamTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace Kelunik\StreamingBase64\Test;
use Amp\ByteStream\InMemoryStream;
use Amp\ByteStream\IteratorStream;
use Amp\ByteStream\Message;
use Amp\Loop;
use Amp\PHPUnit\TestCase;
use Kelunik\StreamingBase64\DecodingInputStream;
use function Amp\Iterator\fromIterable;
class DecodingInputStreamTest extends TestCase {
public function testInvalidType() {
$this->expectException(\Error::class);
new DecodingInputStream(new InMemoryStream(""), 2);
}
public function testBase64() {
Loop::run(function () {
$expected = "0d8de60626e522dc2c4bebb7e99b222b";
$array = ["M", "GQ4ZGU2MD", "YyNmU1MjJkYzJjNGJlYmI3ZTk5YjIyMmI", "="];
$stream = new IteratorStream(fromIterable($array, 10));
$decodingStream = new DecodingInputStream($stream, DecodingInputStream::TYPE_BASE64);
$result = yield new Message($decodingStream);
$this->assertSame($expected, $result);
});
}
public function testBase64Url() {
Loop::run(function () {
$expected = "0d8de60626e522dc2c4bebb7e99b222b";
$array = ["M", "GQ4ZGU2MD", "YyNmU1MjJkYzJjNGJlYmI3ZTk5YjIyMmI"];
$stream = new IteratorStream(fromIterable($array, 10));
$decodingStream = new DecodingInputStream($stream, DecodingInputStream::TYPE_BASE64URL);
$result = yield new Message($decodingStream);
$this->assertSame($expected, $result);
});
}
}