-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIdCodeObjectCollectionTest.php
More file actions
95 lines (68 loc) · 3.49 KB
/
Copy pathIdCodeObjectCollectionTest.php
File metadata and controls
95 lines (68 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
declare(strict_types=1);
class IdCodeObjectCollectionTest extends \PHPUnit\Framework\TestCase
{
public function testCreate()
{
$collection = new \Echron\DataTypes\IdCodeObjectCollection();
$this->assertCount(0, $collection);
}
public function testIdCodeObjectCollection_RemoveById()
{
$object1 = new \Echron\DataTypes\IdCodeObject(20, 'object_code');
$collection = new \Echron\DataTypes\IdCodeObjectCollection();
$collection->add($object1);
$this->assertEquals([20], $collection->getIds());
$this->assertEquals(['object_code'], $collection->getCodes());
$this->assertInstanceOf(\Echron\DataTypes\IdCodeObject::class, $collection->getById(20));
$this->assertInstanceOf(\Echron\DataTypes\IdCodeObject::class, $collection->getByCode('object_code'));
$this->assertCount(1, $collection);
$removed = $collection->removeById(20);
$this->assertEquals([], $collection->getIds());
$this->assertEquals([], $collection->getCodes());
$this->assertFalse($collection->hasId(20));
$this->assertFalse($collection->hasCode('object_code'));
$this->assertCount(0, $collection);
/**
* Add with same code again
*/
$object2 = new \Echron\DataTypes\IdCodeObject(20, 'object_code');
$collection = new \Echron\DataTypes\IdCodeObjectCollection();
$collection->add($object2);
}
public function testIdCodeObjectCollection_RemoveByCode()
{
$object1 = new \Echron\DataTypes\IdCodeObject(20, 'object_code');
$collection = new \Echron\DataTypes\IdCodeObjectCollection();
$collection->add($object1);
$this->assertEquals([20], $collection->getIds());
$this->assertEquals(['object_code'], $collection->getCodes());
$this->assertInstanceOf(\Echron\DataTypes\IdCodeObject::class, $collection->getById(20));
$this->assertInstanceOf(\Echron\DataTypes\IdCodeObject::class, $collection->getByCode('object_code'));
$this->assertCount(1, $collection);
$collection->removeByCode('object_code');
$this->assertEquals([], $collection->getIds());
$this->assertEquals([], $collection->getCodes());
$this->assertFalse($collection->hasId(20));
$this->assertFalse($collection->hasCode('object_code'));
$this->assertCount(0, $collection);
}
public function disabled_testIdCodeObjectCollection_ChangeIdAndCode()
{
$object = new \Echron\DataTypes\IdCodeObject(20, 'object_code');
$collection = new \Echron\DataTypes\IdCodeObjectCollection();
$collection->add($object);
$this->assertEquals([20], $collection->getIds());
$this->assertEquals(['object_code'], $collection->getCodes());
$this->assertInstanceOf(\Echron\DataTypes\IdCodeObject::class, $collection->getById(20));
$this->assertInstanceOf(\Echron\DataTypes\IdCodeObject::class, $collection->getByCode('object_code'));
$object->setId(10);
$object->setCode('object_code2');
$this->assertFalse($collection->hasId(20));
$this->assertFalse($collection->hasCode('object_code'));
$this->assertInstanceOf(\Echron\DataTypes\IdCodeObject::class, $collection->getById(10));
$this->assertInstanceOf(\Echron\DataTypes\IdCodeObject::class, $collection->getByCode('object_code2'));
$this->assertEquals([10], $collection->getIds());
$this->assertEquals(['object_code2'], $collection->getCodes());
}
}