-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTransferTest.php
More file actions
94 lines (81 loc) · 3.33 KB
/
Copy pathTransferTest.php
File metadata and controls
94 lines (81 loc) · 3.33 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
<?php
namespace Utopia\Tests\Unit\General;
use PHPUnit\Framework\TestCase;
use Utopia\Migration\Resource;
use Utopia\Migration\Resources\Database\Database;
use Utopia\Migration\Resources\Database\Row;
use Utopia\Migration\Resources\Database\Table;
use Utopia\Migration\Transfer;
use Utopia\Tests\Unit\Adapters\MockDestination;
use Utopia\Tests\Unit\Adapters\MockSource;
class TransferTest extends TestCase
{
protected Transfer $transfer;
protected MockSource $source;
protected MockDestination $destination;
public function setup(): void
{
$this->source = new MockSource();
$this->destination = new MockDestination();
$this->transfer = new Transfer(
$this->source,
$this->destination
);
}
/**
* @throws \Exception
*/
public function testRootResourceId(): void
{
/**
* TEST FOR FAILURE
* Make sure we can't create a transfer with multiple root resources when supplying a rootResourceId
*/
try {
$this->transfer->run([Resource::TYPE_USER, Resource::TYPE_DATABASE], function () {
}, 'rootResourceId');
$this->fail('Multiple root resources should not be allowed');
} catch (\Exception $e) {
$this->assertSame('Resource type must be set when resource ID is set.', $e->getMessage());
}
$this->source->pushMockResource(new Database('test', 'test'));
$this->source->pushMockResource(new Database('test2', 'test'));
/**
* TEST FOR SUCCESS
*/
$this->transfer->run(
[Resource::TYPE_DATABASE],
function () {
},
'test',
Resource::TYPE_DATABASE
);
$this->assertCount(1, $this->destination->getResourceTypeData(Transfer::GROUP_DATABASES, Resource::TYPE_DATABASE));
$database = $this->destination->getResourceById(Transfer::GROUP_DATABASES, Resource::TYPE_DATABASE, 'test');
/** @var Database $database */
$this->assertNotNull($database);
$this->assertSame('test', $database->getDatabaseName());
$this->assertSame('test', $database->getId());
}
/**
* Row and document counts are aggregated into the cache by status. When such
* a count exists for a resource type that was not part of the migration
* request, getStatusCounters() must ignore it, exactly as it already does for
* non-row resources via the isset() guard. Otherwise it reads an unseeded
* 'pending' key (triggering an "Undefined array key" warning) and reports a
* phantom, non-empty counter for a type the caller never asked to migrate.
*/
public function testStatusCountersIgnoreUnrequestedRowCounts(): void
{
// No resource types were requested, so 'row'/'document' are unrequested.
// A row count still leaks into the cache: the destination tallies row and
// document counts by status as it imports them.
$table = new Table(new Database('db', 'db'), 'table', 'table');
$row = new Row('row-1', $table);
$row->setStatus(Resource::STATUS_SUCCESS);
$this->transfer->getCache()->add($row);
$counters = $this->transfer->getStatusCounters();
$this->assertArrayNotHasKey(Resource::TYPE_ROW, $counters);
$this->assertSame([], $counters);
}
}