ExceptionExtractorTraitTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 13
dl 0
loc 60
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getException() 0 5 1
A provideDataWithoutException() 0 6 1
A getNull() 0 3 1
A provideDataWithException() 0 5 1
1
<?php
2
3
namespace SubjectivePHPTest\Psr\Log;
4
5
use SubjectivePHP\Psr\Log\ExceptionExtractorTrait;
6
7
/**
8
 * @coversDefaultClass \SubjectivePHP\Psr\Log\ExceptionExtractorTrait
9
 */
10
final class ExceptionExtractorTraitTest extends \PHPUnit\Framework\TestCase
11
{
12
    use ExceptionExtractorTrait;
13
14
    /**
15
     * @param array  $context         The array containing the exception.
16
     * @param string $expectedType    The expected exception class.
17
     * @param string $expectedMessage The expected exception message.
18
     *
19
     * @test
20
     * @covers ::getExceptionFromContext
21
     * @dataProvider provideDataWithException
22
     *
23
     * @return void
24
     */
25
    public function getException(array $context, string $expectedType, string $expectedMessage)
26
    {
27
        $exception = $this->getExceptionFromContext($context);
28
        $this->assertInstanceOf($expectedType, $exception);
29
        $this->assertSame($expectedMessage, $exception->getMessage());
30
    }
31
32
    /**
33
     * @param array $context The array which does not contain a valid exception
34
     *
35
     * @test
36
     * @covers ::getExceptionFromContext
37
     * @dataProvider provideDataWithoutException
38
     *
39
     * @return void
40
     */
41
    public function getNull(array $context)
42
    {
43
        $this->assertNull($this->getExceptionFromContext($context));
44
    }
45
46
    /**
47
     * Provides valid data containing exception values and expected results.
48
     *
49
     * @return array
50
     */
51
    public function provideDataWithException() : array
52
    {
53
        return [
54
            [['exception' => new \RuntimeException('a message')], '\\RuntimeException', 'a message'],
55
            [['exception' => new \TypeError('an error')], '\\ErrorException', 'an error'],
56
        ];
57
    }
58
59
    /**
60
     * Provides valid data containing invalid exception or no exception values and expected results.
61
     *
62
     * @return array
63
     */
64
    public function provideDataWithoutException()
65
    {
66
        return [
67
            'null' => [['exception' => null]],
68
            'string' => [['exception' => 'a message']],
69
            'no exepting' => [[]],
70
        ];
71
    }
72
}
73