GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

testImpossibleExceptionCallbackNotCallable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 13
rs 9.9666
1
<?php
2
declare(strict_types=1);
3
namespace Thunder\Platenum\Tests;
4
5
use Thunder\Platenum\Enum\CallbackEnumTrait;
6
use Thunder\Platenum\Exception\PlatenumException;
7
8
/**
9
 * @author Tomasz Kowalczyk <[email protected]>
10
 */
11
final class CallbackEnumTest extends AbstractTestCase
12
{
13
    public function testMembers(): void
14
    {
15
        $members = ['FIRST' => 1, 'SECOND' => 2];
16
        $trait = $this->makeCallbackTraitEnum($members);
17
        $trait::initialize(function() use($members) { return $members; });
18
        $extends = $this->makeCallbackExtendsEnum($members);
19
        $extends::initialize(function() use($members) { return $members; });
20
21
        $expected = ['FIRST' => 1, 'SECOND' => 2];
22
        $this->assertSame($expected, $trait::getMembersAndValues());
23
        $this->assertSame($expected, $extends::getMembersAndValues());
24
    }
25
26
    public function testExceptionNoInitialize(): void
27
    {
28
        $members = ['FIRST' => 1, 'SECOND' => 2];
29
        $class = $this->makeCallbackTraitEnum($members);
30
31
        $this->expectException(PlatenumException::class);
32
        $this->expectExceptionMessage('Enum '.$class.' requires static property $callback to be a valid callable returning members and values mapping.');
33
        $class::FIRST();
34
    }
35
36
    public function testExceptionAlreadyInitialized(): void
37
    {
38
        $members = ['FIRST' => 1, 'SECOND' => 2];
39
        $class = $this->makeCallbackTraitEnum($members);
40
        $class::initialize(function() use($members) { return $members; });
41
42
        $this->expectException(PlatenumException::class);
43
        $this->expectExceptionMessage('Enum '.$class.' callback was already initialized.');
44
        $class::initialize(function() use($members) { return $members; });
45
    }
46
47
    public function testImpossibleExceptionCallbackNotCallable(): void
48
    {
49
        $class = $this->computeUniqueClassName('CallbackTrait');
50
        eval('final class '.$class.' implements \JsonSerializable { use '.CallbackEnumTrait::class.'; }');
0 ignored issues
show
introduced by
The use of eval() is discouraged.
Loading history...
51
52
        $ref = new \ReflectionClass($class);
53
        $callbacks = $ref->getProperty('callbacks');
54
        $callbacks->setAccessible(true);
55
        $callbacks->setValue($class, [$class => 'invalid']);
56
57
        $this->expectException(PlatenumException::class);
58
        $this->expectExceptionMessage('Enum '.$class.' requires static property $callback to be a valid callable returning members and values mapping.');
59
        $class::FIRST();
60
    }
61
}
62