JsonEncoderTest::testUnicodeEncode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 12
rs 10
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())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Gelf\MessageInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
            ->/** @scrutinizer ignore-call */ 
37
              expects($this->once())

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.

Loading history...
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