CompressedJsonEncoderTest::testEncode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 22
rs 9.9332
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())
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

37
            ->/** @scrutinizer ignore-call */ 
38
              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...
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