1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/* |
5
|
|
|
* This file is part of the php-gelf package. |
6
|
|
|
* |
7
|
|
|
* (c) Benjamin Zikarsky <http://benjamin-zikarsky.de> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Gelf\Test\Encoder; |
14
|
|
|
|
15
|
|
|
use Gelf\Encoder\CompressedJsonEncoder; |
16
|
|
|
use Gelf\Encoder\JsonEncoder; |
17
|
|
|
use Gelf\MessageInterface; |
18
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
19
|
|
|
use PHPUnit\Framework\TestCase; |
20
|
|
|
|
21
|
|
|
class CompressedJsonEncoderTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
private MockObject|MessageInterface $message; |
24
|
|
|
private CompressedJsonEncoder $encoder; |
25
|
|
|
|
26
|
|
|
public function setUp(): void |
27
|
|
|
{ |
28
|
|
|
$this->message = $this->createMock(MessageInterface::class); |
29
|
|
|
$this->encoder = new CompressedJsonEncoder(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testEncode() |
33
|
|
|
{ |
34
|
|
|
$testData = ['foo' => 'bar']; |
35
|
|
|
|
36
|
|
|
$this->message |
37
|
|
|
->expects($this->once()) |
|
|
|
|
38
|
|
|
->method('toArray') |
39
|
|
|
->will($this->returnValue($testData)); |
40
|
|
|
|
41
|
|
|
$bytes = $this->encoder->encode($this->message); |
42
|
|
|
|
43
|
|
|
// check for valid zlib-compressed string |
44
|
|
|
$this->assertEquals("\x78\x9c", substr($bytes, 0, 2)); |
45
|
|
|
|
46
|
|
|
// check that it's uncompressable |
47
|
|
|
$json = gzuncompress($bytes); |
48
|
|
|
|
49
|
|
|
// check that there is JSON inside |
50
|
|
|
$data = json_decode($json, associative: true); |
51
|
|
|
|
52
|
|
|
// check that we have our data array |
53
|
|
|
$this->assertEquals($testData, $data); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.