1
|
|
|
<?php |
2
|
|
|
namespace Tests\AppBundle\Sync; |
3
|
|
|
|
4
|
|
|
use AppBundle\Sync\Entity\File; |
5
|
|
|
use AppBundle\Sync\Entity\FileCollection; |
6
|
|
|
use AppBundle\Sync\TaskGenerator; |
7
|
|
|
use Nelmio\Alice\Fixtures\Loader; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Task Generator tests |
11
|
|
|
* |
12
|
|
|
* @author Sergey Sadovoi <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class TaskGeneratorTest extends \PHPUnit_Framework_TestCase |
15
|
|
|
{ |
16
|
|
|
public function testSuccessHandle() |
17
|
|
|
{ |
18
|
|
|
// Sample files |
19
|
|
|
$loader = new Loader(); |
20
|
|
|
$files = $loader->load(__DIR__ . '/../Fixtures/files.yml'); |
21
|
|
|
|
22
|
|
|
// Collecting master |
23
|
|
|
$masterCollection = new FileCollection(); |
24
|
|
|
$masterCollection->addFile($files['file1']); |
25
|
|
|
$masterCollection->addFile($files['file2']); |
26
|
|
|
$masterCollection->addFile($files['file3']); |
27
|
|
|
|
28
|
|
|
// Collecting slave |
29
|
|
|
$slaveCollection = new FileCollection(); |
30
|
|
|
$slaveCollection->addFile($files['file1']); |
31
|
|
|
$slaveCollection->addFile($files['file4']); |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var File $file3 |
35
|
|
|
*/ |
36
|
|
|
$file3 = clone $files['file3']; |
37
|
|
|
$file3->setSize(10); |
38
|
|
|
$slaveCollection->addFile($file3); |
39
|
|
|
|
40
|
|
|
// Generate tasks |
41
|
|
|
$taskGenerator = new TaskGenerator(); |
42
|
|
|
$taskGenerator->setSlavePathTpl('/path/to/__program__/__uid__'); |
43
|
|
|
$tasks = $taskGenerator->handle($masterCollection, $slaveCollection); |
44
|
|
|
|
45
|
|
|
// Tasks check |
46
|
|
|
$this->assertCount(3, $tasks); |
47
|
|
|
$this->assertEquals('add', $tasks->get(0)->getName()); |
48
|
|
|
$this->assertEquals('update', $tasks->get(1)->getName()); |
49
|
|
|
$this->assertEquals('delete', $tasks->get(2)->getName()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @expectedException \AppBundle\Exception\TaskException |
54
|
|
|
* @expectedExceptionCode \AppBundle\Exception\TaskException::SLAVE_PATH_NOT_SET |
55
|
|
|
*/ |
56
|
|
|
public function testNotSetPathTpl() |
57
|
|
|
{ |
58
|
|
|
$taskGenerator = new TaskGenerator(); |
59
|
|
|
$taskGenerator->getSlavePathTpl(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @expectedException \AppBundle\Exception\TaskException |
64
|
|
|
* @expectedExceptionCode \AppBundle\Exception\TaskException::HUGE_AMOUNT_TO_DELETE |
65
|
|
|
*/ |
66
|
|
|
public function testHugeAmountOfFiles() |
67
|
|
|
{ |
68
|
|
|
// Sample files |
69
|
|
|
$loader = new Loader(); |
70
|
|
|
$files = $loader->load(__DIR__ . '/../Fixtures/alotOfFiles.yml'); |
71
|
|
|
|
72
|
|
|
// Collecting master |
73
|
|
|
$masterCollection = new FileCollection(); |
74
|
|
|
|
75
|
|
|
// Collecting slave |
76
|
|
|
$slaveCollection = new FileCollection(); |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @var File $file |
80
|
|
|
*/ |
81
|
|
|
foreach ($files as $file) { |
82
|
|
|
$slaveCollection->addFile($file); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
// Generate tasks |
86
|
|
|
$taskGenerator = new TaskGenerator(); |
87
|
|
|
$taskGenerator->setSlavePathTpl('/path/to/__program__/__uid__'); |
88
|
|
|
$taskGenerator->handle($masterCollection, $slaveCollection); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|