Passed
Pull Request — master (#97)
by Maximilian
03:49
created

testJsonSerializeWithAllProperties()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 13
rs 9.9666
c 1
b 0
f 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Test\Response\Directives\APL\StandardCommand;
6
7
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\LogLevel;
8
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\LogCommand;
9
use PHPUnit\Framework\TestCase;
10
11
class LogCommandTest extends TestCase
12
{
13
    public function testConstructorWithAllParameters(): void
14
    {
15
        $level = LogLevel::ERROR;
16
        $message = 'Test error message';
17
        $arguments = ['key1' => 'value1', 'key2' => 'value2'];
18
19
        $command = new LogCommand($level, $message, $arguments);
20
21
        $this->assertSame($level, $command->level);
22
        $this->assertSame($message, $command->message);
23
        $this->assertSame($arguments, $command->arguments);
24
    }
25
26
    public function testConstructorWithDefaultParameters(): void
27
    {
28
        $command = new LogCommand();
29
30
        $this->assertSame(LogLevel::INFO, $command->level);
31
        $this->assertNull($command->message);
32
        $this->assertNull($command->arguments);
33
    }
34
35
    public function testJsonSerializeWithAllProperties(): void
36
    {
37
        $level = LogLevel::WARN;
38
        $message = 'Warning message';
39
        $arguments = ['userId' => '123', 'action' => 'test'];
40
41
        $command = new LogCommand($level, $message, $arguments);
42
        $result = $command->jsonSerialize();
43
44
        $this->assertSame(LogCommand::TYPE, $result['type']);
45
        $this->assertSame($level->value, $result['level']);
46
        $this->assertSame($message, $result['message']);
47
        $this->assertSame($arguments, $result['arguments']);
48
    }
49
50
    public function testJsonSerializeWithDefaultLevel(): void
51
    {
52
        $command = new LogCommand();
53
        $result = $command->jsonSerialize();
54
55
        $this->assertSame(LogCommand::TYPE, $result['type']);
56
        $this->assertSame(LogLevel::INFO->value, $result['level']);
57
        $this->assertArrayNotHasKey('message', $result);
58
        $this->assertArrayNotHasKey('arguments', $result);
59
    }
60
61
    public function testJsonSerializeWithEmptyArguments(): void
62
    {
63
        $command = new LogCommand(LogLevel::DEBUG, 'Debug message', []);
64
        $result = $command->jsonSerialize();
65
66
        $this->assertSame(LogLevel::DEBUG->value, $result['level']);
67
        $this->assertSame('Debug message', $result['message']);
68
        $this->assertArrayNotHasKey('arguments', $result);
69
    }
70
71
    public function testJsonSerializeWithDifferentLogLevels(): void
72
    {
73
        $levels = [LogLevel::DEBUG, LogLevel::INFO, LogLevel::WARN, LogLevel::ERROR];
74
75
        foreach ($levels as $level) {
76
            $command = new LogCommand($level, 'Test message');
77
            $result = $command->jsonSerialize();
78
79
            $this->assertSame($level->value, $result['level']);
80
        }
81
    }
82
}
83