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\JsonEncoder; |
16
|
|
|
use Gelf\MessageInterface; |
17
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
18
|
|
|
use PHPUnit\Framework\TestCase; |
19
|
|
|
|
20
|
|
|
class JsonEncoderTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
private MockObject|MessageInterface $message; |
23
|
|
|
private JsonEncoder $encoder; |
24
|
|
|
|
25
|
|
|
public function setUp(): void |
26
|
|
|
{ |
27
|
|
|
$this->message = $this->createMock(MessageInterface::class); |
28
|
|
|
$this->encoder = new JsonEncoder(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testEncode(): void |
32
|
|
|
{ |
33
|
|
|
$testData = ['foo' => 'bar']; |
34
|
|
|
|
35
|
|
|
$this->message |
36
|
|
|
->expects($this->once()) |
|
|
|
|
37
|
|
|
->method('toArray') |
38
|
|
|
->will($this->returnValue($testData)); |
39
|
|
|
|
40
|
|
|
$json = $this->encoder->encode($this->message); |
41
|
|
|
|
42
|
|
|
// check that there is JSON inside |
43
|
|
|
$data = json_decode($json, associative: true); |
44
|
|
|
|
45
|
|
|
// check that we have our data array |
46
|
|
|
self::assertEquals($testData, $data); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testUnicodeEncode(): void |
50
|
|
|
{ |
51
|
|
|
$testData = ['foo' => 'бар']; |
52
|
|
|
|
53
|
|
|
$this->message |
54
|
|
|
->expects($this->once()) |
55
|
|
|
->method('toArray') |
56
|
|
|
->will($this->returnValue($testData)); |
57
|
|
|
|
58
|
|
|
$json = $this->encoder->encode($this->message); |
59
|
|
|
|
60
|
|
|
self::assertEquals('{"foo":"бар"}', $json); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
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.