Completed
Push — master ( 203e38...2cdd54 )
by Gerrit
13:04
created

FieldValueResolverTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 84
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
B shouldResolveValue() 0 24 1
A shouldRevertValue() 0 19 1
A shouldAssertValue() 0 15 1
1
<?php
2
/**
3
 * Copyright (C) 2017  Gerrit Addiks.
4
 * This package (including this file) was released under the terms of the GPL-3.0.
5
 * You should have received a copy of the GNU General Public License along with this program.
6
 * If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy.
7
 * @license GPL-3.0
8
 * @author Gerrit Addiks <[email protected]>
9
 */
10
11
namespace Addiks\RDMBundle\Tests\ValueResolver;
12
13
use PHPUnit\Framework\TestCase;
14
use Addiks\RDMBundle\ValueResolver\FieldValueResolver;
15
use Addiks\RDMBundle\Mapping\FieldMappingInterface;
16
use Addiks\RDMBundle\Tests\Hydration\EntityExample;
17
use Doctrine\DBAL\Schema\Column;
18
19
final class FieldValueResolverTest extends TestCase
20
{
21
22
    /**
23
     * @var FieldValueResolver
24
     */
25
    private $valueResolver;
26
27
    public function setUp()
28
    {
29
        $this->valueResolver = new FieldValueResolver();
30
    }
31
32
    /**
33
     * @test
34
     */
35
    public function shouldResolveValue()
36
    {
37
        /** @var FieldMappingInterface $fieldMapping */
38
        $fieldMapping = $this->createMock(FieldMappingInterface::class);
39
40
        /** @var EntityExample $entity */
41
        $entity = $this->createMock(EntityExample::class);
42
43
        /** @var Column $column */
44
        $column = $this->createMock(Column::class);
45
46
        /** @var string $expectedResult */
47
        $expectedResult = 'bar';
48
49
        $fieldMapping->method('getDBALColumn')->willReturn($column);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\RDMBundle\...\FieldMappingInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
50
        $column->method('getName')->willReturn('foo');
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Doctrine\DBAL\Schema\Column>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
51
52
        /** @var mixed $actualResult */
53
        $actualResult = $this->valueResolver->resolveValue($fieldMapping, $entity, [
54
            'foo' => $expectedResult
55
        ]);
56
57
        $this->assertSame($expectedResult, $actualResult);
58
    }
59
60
    /**
61
     * @test
62
     */
63
    public function shouldRevertValue()
64
    {
65
        /** @var FieldMappingInterface $fieldMapping */
66
        $fieldMapping = $this->createMock(FieldMappingInterface::class);
67
68
        /** @var EntityExample $entity */
69
        $entity = $this->createMock(EntityExample::class);
70
71
        /** @var Column $column */
72
        $column = $this->createMock(Column::class);
73
74
        $fieldMapping->method('getDBALColumn')->willReturn($column);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\RDMBundle\...\FieldMappingInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
75
        $column->method('getName')->willReturn('foo');
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Doctrine\DBAL\Schema\Column>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
76
77
        $this->assertEquals(
78
            ['foo' => "Lorem ipsum"],
79
            $this->valueResolver->revertValue($fieldMapping, $entity, "Lorem ipsum")
80
        );
81
    }
82
83
    /**
84
     * @test
85
     */
86
    public function shouldAssertValue()
87
    {
88
        /** @var FieldMappingInterface $fieldMapping */
89
        $fieldMapping = $this->createMock(FieldMappingInterface::class);
90
91
        /** @var EntityExample $entity */
92
        $entity = $this->createMock(EntityExample::class);
93
94
        $this->assertSame(null, $this->valueResolver->assertValue(
95
            $fieldMapping,
96
            $entity,
97
            [],
98
            "Foo"
99
        ));
100
    }
101
102
}
103