Completed
Push — master ( 0e4bc5...7f10cd )
by Ivannis Suárez
02:27
created

EnumTests::newDefaultTestedInstance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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\Core\Enum\Tests\Units;
12
13
use Cubiche\Core\Enum\Tests\Fixtures\EnumFixture;
14
use Cubiche\Core\Enum\Tests\Fixtures\DefaultEnumFixture;
15
use Cubiche\Core\Enum\Tests\Fixtures\BadDefaultEnumFixture;
16
17
/**
18
 * Enum Tests Class.
19
 *
20
 * @author Ivannis Suárez Jerez <[email protected]>
21
 */
22
class EnumTests extends EnumTestCase
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function newDefaultTestedInstance()
28
    {
29
        return new EnumFixture(EnumFixture::FOO);
30
    }
31
32
    /**
33
     * Test is method.
34
     */
35
    public function testIs()
36
    {
37
        $this
38
            ->given($enum = $this->newDefaultTestedInstance())
39
            ->then()
40
                ->boolean($enum->is(EnumFixture::FOO))
41
                    ->isTrue()
42
                ->boolean($enum->is(EnumFixture::BAR))
43
                    ->isFalse()
44
        ;
45
    }
46
47
    /**
48
     * Test __DEFAULT method.
49
     */
50
    public function testDefault()
51
    {
52
        $this
53
            ->when($default = EnumFixture::__DEFAULT())
54
            ->then()
55
                ->object($default)
56
                    ->isEqualTo(EnumFixture::FOO())
57
        ;
58
59
        $this
60
            ->when($default = DefaultEnumFixture::__DEFAULT())
61
                ->then()
62
                    ->object($default)
63
                        ->isEqualTo(DefaultEnumFixture::BAR())
64
        ;
65
66
        $this
67
            ->exception(function () {
68
                BadDefaultEnumFixture::__DEFAULT();
69
            })
70
                ->isInstanceof(\UnexpectedValueException::class)
71
        ;
72
73
        $this
74
            ->exception(function () {
75
                BadDefaultEnumFixture::BAZ();
76
            })
77
                ->isInstanceof(\BadMethodCallException::class)
78
        ;
79
    }
80
}
81