Passed
Push — master ( 23152a...a65783 )
by Povilas
02:36
created

AbstractMapperTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 18
dl 0
loc 45
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testRemove() 0 7 1
A testGetFields() 0 4 1
A testGetExists() 0 4 1
A testHas() 0 5 1
A testGetThrowsExceptionOnNonExist() 0 7 1
1
<?php
2
3
namespace Povs\ListerBundle\Mapper;
4
5
use PHPUnit\Framework\TestCase;
6
use Povs\ListerBundle\Exception\ListFieldException;
7
8
/**
9
 * @author Povilas Margaiatis <[email protected]>
10
 */
11
abstract class AbstractMapperTest extends TestCase
12
{
13
    public function testHas(): void
14
    {
15
        $mapper = $this->getMapper(['id']);
16
        $this->assertTrue($mapper->has('id'));
17
        $this->assertFalse($mapper->has('another_id'));
18
    }
19
20
    public function testGetExists(): void
21
    {
22
        $mapper = $this->getMapper(['id']);
23
        $this->assertEquals('id', $mapper->get('id')->getId());
24
    }
25
26
    public function testGetThrowsExceptionOnNonExist(): void
27
    {
28
        $this->expectException(ListFieldException::class);
29
        $this->expectExceptionCode(500);
30
        $this->expectExceptionMessage('Field "id" do not exists');
31
        $mapper = $this->getMapper(['another_id']);
32
        $mapper->get('id');
33
    }
34
35
    public function testRemove(): void
36
    {
37
        $mapper = $this->getMapper(['id']);
38
        $mapper->remove('other_id');
39
        $this->assertTrue($mapper->has('id'));
40
        $mapper->remove('id');
41
        $this->assertFalse($mapper->has('id'));
42
    }
43
44
    public function testGetFields(): void
45
    {
46
        $mapper = $this->getMapper(['id', 'id2', 'id3']);
47
        $this->assertCount(3, $mapper->getFields());
48
    }
49
50
    /**
51
     * @param string[] $ids
52
     *
53
     * @return AbstractMapper
54
     */
55
    abstract protected function getMapper(array $ids): AbstractMapper;
56
}
57