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.

CallbackEnumTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 29
c 1
b 0
f 0
dl 0
loc 49
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testExceptionNoInitialize() 0 8 1
A testMembers() 0 11 1
A testImpossibleExceptionCallbackNotCallable() 0 13 1
A testExceptionAlreadyInitialized() 0 9 1
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