EnumTests   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 56
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A randomNativeValue() 0 6 1
A uniqueNativeValue() 0 6 1
A invalidNativeValue() 0 4 1
A fromNative() 0 4 1
A testIs() 0 14 1
1
<?php
2
3
/**
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Cubiche\Domain\System\Tests\Units;
12
13
use Cubiche\Domain\Model\Tests\Units\NativeValueObjectTestCase;
14
use Cubiche\Domain\System\Tests\Units\Fixtures\EnumFixture;
15
16
/**
17
 * EnumTests class.
18
 *
19
 * @author Ivannis Suárez Jerez <[email protected]>
20
 */
21
class EnumTests extends NativeValueObjectTestCase
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    protected function randomNativeValue()
27
    {
28
        $values = array_slice(array_values(EnumFixture::toArray()), 1);
29
30
        return $values[array_rand($values)];
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    protected function uniqueNativeValue()
37
    {
38
        $values = array_values(EnumFixture::toArray());
39
40
        return $values[0];
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    protected function invalidNativeValue()
47
    {
48
        return 3.14;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    protected function fromNative($value)
55
    {
56
        return EnumFixture::fromNative($value);
57
    }
58
59
    /**
60
     * Test is method.
61
     */
62
    public function testIs()
63
    {
64
        $this
65
            ->given(
66
                $enum = $this->fromNative($this->randomNativeValue()),
67
                $enum1 = $this->fromNative($this->randomNativeValue())
68
            )
69
            ->then
70
                ->boolean($enum->is($enum->toNative()))
71
                    ->isTrue()
72
                ->boolean($enum1->is($this->invalidNativeValue()))
73
                    ->isFalse()
74
        ;
75
    }
76
}
77