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
|
|
|
|