-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractTagRepositoryTest.php
More file actions
78 lines (67 loc) · 2.9 KB
/
Copy pathAbstractTagRepositoryTest.php
File metadata and controls
78 lines (67 loc) · 2.9 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
<?php
declare(strict_types=1);
namespace IntegerNet\AsyncVarnish\Test\Integration;
use IntegerNet\AsyncVarnish\Api\TagRepositoryInterface;
use PHPUnit\Framework\TestCase;
abstract class AbstractTagRepositoryTest extends TestCase
{
/**
* @var TagRepositoryInterface
*/
protected $tagRepository;
protected function setUp()
{
$this->tagRepository = $this->getTestSubject();
}
abstract protected function getTestSubject(): TagRepositoryInterface;
public function testInsertAndRetrieve()
{
$affected = $this->tagRepository->insertMultiple(['x', 'y', 'z']);
$this->assertEquals(3, $affected, 'insertMultiple() should return number of inserted rows');
$this->assertEqualsCanonicalizing(['x', 'y', 'z'], $this->tagRepository->getAll());
}
public function testNoDuplicatesAreRetrieved()
{
$affected = $this->tagRepository->insertMultiple(['x', 'y', 'x']);
$this->assertEquals(3, $affected, 'insertMultiple() should return number of inserted rows');
$this->assertEqualsCanonicalizing(['x', 'y'], $this->tagRepository->getAll());
}
public function testNoDuplicatesAreRetrievedAfterSubsequentCalls()
{
$affected = $this->tagRepository->insertMultiple(['x', 'y']);
$this->assertEquals(2, $affected, 'insertMultiple() should return number of inserted rows');
$affected = $this->tagRepository->insertMultiple(['y', 'z']);
$this->assertEquals(2, $affected, 'insertMultiple() should return number of inserted rows');
$this->assertEqualsCanonicalizing(['x', 'y', 'z'], $this->tagRepository->getAll());
}
public function testLastUsedIdIncreases()
{
$this->tagRepository->insertMultiple(['x']);
$this->tagRepository->getAll();
$lastUsedId = $this->tagRepository->getLastUsedId();
$this->tagRepository->insertMultiple(['y']);
$this->tagRepository->getAll();
//TODO maybe throw exception if getAll has not been called before:
$this->assertEquals($lastUsedId + 1, $this->tagRepository->getLastUsedId());
}
public function testDeleteUpToId()
{
$this->tagRepository->insertMultiple(['x', 'y', 'z']);
$this->tagRepository->getAll();
$lastUsedId = $this->tagRepository->getLastUsedId();
$this->tagRepository->insertMultiple(['a', 'b', 'c']);
$affected = $this->tagRepository->deleteUpToId($lastUsedId);
$this->assertEquals(3, $affected, 'deleteUpToId() should return number of deleted rows');
$this->assertEqualsCanonicalizing(['a', 'b', 'c'], $this->tagRepository->getAll());
}
/**
* Backport from PHPUnit 8
*
* @param array $expected
* @param array $actual
*/
public static function assertEqualsCanonicalizing(array $expected, array $actual, string $message = '')
{
self::assertEquals($expected, $actual, $message, 0.0, 10, true);
}
}