Passed
Push — master ( 4efb65...8ee2ab )
by Mr
01:53
created

FromToNativeTest::testInferredFromNative()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 20
rs 9.8333
ccs 14
cts 14
cp 1
cc 1
nc 1
nop 0
crap 1
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/interop project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Daikon\Tests\Interop;
10
11
use Daikon\Interop\AssertionFailedException;
12
use Daikon\Tests\Interop\Fixture\AnnotatedValue;
13
use Daikon\Tests\Interop\Fixture\MockValue;
14
use PHPUnit\Framework\TestCase;
15
use TypeError;
16
17
class FromToNativeTest extends TestCase
18
{
19 1
    public function testMakeEmpty(): void
20
    {
21 1
        $mock = MockValue::makeEmpty();
22 1
        $this->assertNull($mock->getValue());
23
24 1
        $mock = AnnotatedValue::makeEmpty();
25 1
        $this->assertInstanceOf(MockValue::class, $mock->getMockValue());
26 1
        $this->assertNull($mock->getMockValue()->getValue());
27 1
    }
28
29 1
    public function testFromNativeWithNull(): void
30
    {
31 1
        $this->expectException(AssertionFailedException::class);
32 1
        $this->expectExceptionMessage('This trait only works with array state.');
33 1
        MockValue::fromNative(null);
34
    }
35
36 1
    public function testInferredFromNativeWithNull(): void
37
    {
38 1
        $this->expectException(AssertionFailedException::class);
39 1
        $this->expectExceptionMessage('This trait only works with array state.');
40 1
        AnnotatedValue::fromNative(null);
41
    }
42
43 1
    public function testFromNativeWithScalar(): void
44
    {
45 1
        $this->expectException(AssertionFailedException::class);
46 1
        $this->expectExceptionMessage('This trait only works with array state.');
47 1
        MockValue::fromNative('test');
48
    }
49
50 1
    public function testInferredFromNativeWithScalar(): void
51
    {
52 1
        $this->expectException(AssertionFailedException::class);
53 1
        $this->expectExceptionMessage('This trait only works with array state.');
54 1
        AnnotatedValue::fromNative('test');
55
    }
56
57 1
    public function testFromNativeWithUnknownKey(): void
58
    {
59 1
        $mock = MockValue::fromNative(['what' => 'no']);
60 1
        $this->assertNull($mock->getValue());
61 1
    }
62
63 1
    public function testInferredFromNativeWithUnknownKey(): void
64
    {
65 1
        $mock = AnnotatedValue::fromNative(['what' => 'no']);
66 1
        $this->assertInstanceOf(MockValue::class, $mock->getMockValue());
67 1
        $this->assertNull($mock->getMockValue()->getValue());
68 1
    }
69
70 1
    public function testFromNativeWithInvalidType(): void
71
    {
72 1
        $this->expectException(TypeError::class);
73 1
        MockValue::fromNative(['value' => 123]);
74
    }
75
76 1
    public function testInferredFromNativeWithInvalidType(): void
77
    {
78 1
        $this->expectException(AssertionFailedException::class);
79 1
        $this->expectExceptionMessage('This trait only works with array state.');
80 1
        AnnotatedValue::fromNative(['mockValue' => 123]);
81
    }
82
83 1
    public function testInferredFromNativeWithNullValueState(): void
84
    {
85 1
        $this->expectException(AssertionFailedException::class);
86 1
        $this->expectExceptionMessage('This trait only works with array state.');
87 1
        AnnotatedValue::fromNative(['mockValue' => null]);
88
    }
89
90 1
    public function testFromNative(): void
91
    {
92 1
        $mock = MockValue::fromNative([]);
93 1
        $this->assertNull($mock->getValue());
94
95 1
        $mock = MockValue::fromNative(['value' => null]);
96 1
        $this->assertNull($mock->getValue());
97
98 1
        $mock = MockValue::fromNative(['value' => 'yo']);
99 1
        $this->assertEquals('yo', $mock->getValue());
100 1
    }
101
102 1
    public function testInferredFromNative(): void
103
    {
104 1
        $mock = AnnotatedValue::fromNative(['mockValue' => []]);
105 1
        $this->assertInstanceOf(MockValue::class, $mock->getMockValue());
106 1
        $this->assertNull($mock->getMockValue()->getValue());
107
108 1
        $mock = AnnotatedValue::fromNative(['mockValue' => ['valuex' => '']]);
109 1
        $this->assertNull($mock->getMockValue()->getValue());
110
111 1
        $mock = AnnotatedValue::fromNative(['mockValue' => ['value' => '']]);
112 1
        $this->assertEmpty($mock->getMockValue()->getValue());
113
114 1
        $mock = AnnotatedValue::fromNative(['mockValue' => ['value' => '123']]);
115 1
        $this->assertEquals('123', $mock->getMockValue()->getValue());
116
117 1
        $mock = AnnotatedValue::fromNative(['otherMockValue' => ['custom' => 'ABC']]);
118 1
        $this->assertEquals('ABC', $mock->getOtherMockValue()->getValue());
119
120 1
        $this->expectException(TypeError::class);
121 1
        AnnotatedValue::fromNative(['otherMockValue' => 'ABC']);
122
    }
123
}
124