-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathVersionCollectionTest.php
85 lines (72 loc) · 2.47 KB
/
VersionCollectionTest.php
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
<?php
/*
* This file is part of the PHPCR Migrations package
*
* (c) Daniel Leech <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPCR\Migrations\Tests\Unit;
use PHPCR\Migrations\VersionCollection;
use PHPCR\Migrations\VersionInterface;
use PHPUnit\Framework\TestCase;
class VersionCollectionTest extends TestCase
{
public const VERSION1 = '201501010000';
public const VERSION2 = '201501020000';
public const VERSION3 = '201501030000';
public function setUp(): void
{
$this->version1 = $this->createMock(VersionInterface::class);
$this->version2 = $this->createMock(VersionInterface::class);
$this->version3 = $this->createMock(VersionInterface::class);
}
/**
* It knows if it contains a version.
*/
public function testHas(): void
{
$collection = $this->createCollection([
self::VERSION1 => $this->version1,
self::VERSION3 => $this->version3,
]);
$this->assertTrue($collection->has(self::VERSION1));
$this->assertTrue($collection->has(self::VERSION3));
$this->assertFalse($collection->has(self::VERSION2));
}
/**
* It returns the versions required to migrate from up from A to B.
*/
public function testFromAToBUp(): void
{
$collection = $this->createCollection([
self::VERSION1 => $this->version1,
self::VERSION2 => $this->version2,
self::VERSION3 => $this->version3,
]);
$versions = $collection->getVersions(self::VERSION1, self::VERSION3);
$this->assertEquals([
self::VERSION2, self::VERSION3,
], array_map('strval', array_keys($versions)));
}
/**
* It returns the versions required to migrate down from A to B.
*/
public function testDownFromAToBUp(): void
{
$collection = $this->createCollection([
self::VERSION1 => $this->version1,
self::VERSION2 => $this->version2,
self::VERSION3 => $this->version3,
]);
$versions = $collection->getVersions(self::VERSION3, self::VERSION1);
$this->assertEquals([
self::VERSION3, self::VERSION2,
], array_map('strval', array_keys($versions)));
}
private function createCollection(array $versions): VersionCollection
{
return new VersionCollection($versions);
}
}