Repository navigation
Expand file tree
/
Copy pathMultiJsonStreamTest.php
More file actions
64 lines (55 loc) · 1.79 KB
/
Copy pathMultiJsonStreamTest.php
File metadata and controls
64 lines (55 loc) · 1.79 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
declare(strict_types=1);
namespace Docker\Tests\Stream;
use Docker\API\Model\BuildInfo;
use Docker\Stream\MultiJsonStream;
use Docker\Tests\TestCase;
use Nyholm\Psr7\Stream;
use Symfony\Component\Serializer\SerializerInterface;
class MultiJsonStreamTest extends TestCase
{
public static function jsonStreamDataProvider()
{
return [
[
'{}{"abc":"def"}',
['{}', '{"abc":"def"}'],
],
[
'{"test": "abc\"\""}',
['{"test":"abc\"\""}'],
],
[
'{"test": "abc\"{{-}"}',
['{"test":"abc\"{{-}"}'],
],
];
}
/**
* @dataProvider jsonStreamDataProvider
*/
public function testReadJsonEscapedDoubleQuote(string $jsonStream, array $jsonParts): void
{
$stream = Stream::create($jsonStream);
$stream->rewind();
$serializer = $this->getMockBuilder(SerializerInterface::class)
->getMock();
$callIndex = 0;
$serializer
->expects($this->exactly(\count($jsonParts)))
->method('deserialize')
->willReturnCallback(function ($data, $class, $format, $context) use ($jsonParts, &$callIndex) {
$this->assertEquals($jsonParts[$callIndex], $data);
$this->assertEquals(BuildInfo::class, $class);
$this->assertEquals('json', $format);
$this->assertEquals([], $context);
$callIndex++;
return null;
});
$stub = $this->getMockForAbstractClass(MultiJsonStream::class, [$stream, $serializer]);
$stub->expects($this->any())
->method('getDecodeClass')
->willReturn('BuildInfo');
$stub->wait();
}
}