|
1
|
|
|
<?php |
|
2
|
|
|
namespace Tests\AppBundle\Sync; |
|
3
|
|
|
|
|
4
|
|
|
use AppBundle\Sync\Entity\Task; |
|
5
|
|
|
use AppBundle\Sync\Processor; |
|
6
|
|
|
use AppBundle\Sync\Entity\Task\Add; |
|
7
|
|
|
use AppBundle\Sync\Entity\Task\Delete; |
|
8
|
|
|
use AppBundle\Sync\Entity\Task\Update; |
|
9
|
|
|
use AppBundle\Sync\Storage\StorageInterface; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Task Processor tests |
|
13
|
|
|
* |
|
14
|
|
|
* @author Sergey Sadovoi <[email protected]> |
|
15
|
|
|
*/ |
|
16
|
|
|
class ProcessorTest extends \PHPUnit_Framework_TestCase |
|
17
|
|
|
{ |
|
18
|
|
View Code Duplication |
public function testAdd() |
|
|
|
|
|
|
19
|
|
|
{ |
|
20
|
|
|
$storage = $this->getMockForAbstractClass(StorageInterface::class); |
|
21
|
|
|
$storage->expects($this->once()) |
|
22
|
|
|
->method('put'); |
|
23
|
|
|
|
|
24
|
|
|
$processor = new Processor($storage); |
|
25
|
|
|
$task = new Add(); |
|
26
|
|
|
|
|
27
|
|
|
$processor->execute($task); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
View Code Duplication |
public function testUpdate() |
|
|
|
|
|
|
31
|
|
|
{ |
|
32
|
|
|
$storage = $this->getMockForAbstractClass(StorageInterface::class); |
|
33
|
|
|
$storage->expects($this->once()) |
|
34
|
|
|
->method('put'); |
|
35
|
|
|
|
|
36
|
|
|
$processor = new Processor($storage); |
|
37
|
|
|
$task = new Update(); |
|
38
|
|
|
|
|
39
|
|
|
$processor->execute($task); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
View Code Duplication |
public function testDelete() |
|
|
|
|
|
|
43
|
|
|
{ |
|
44
|
|
|
$storage = $this->getMockForAbstractClass(StorageInterface::class); |
|
45
|
|
|
$storage->expects($this->once()) |
|
46
|
|
|
->method('delete'); |
|
47
|
|
|
|
|
48
|
|
|
$processor = new Processor($storage); |
|
49
|
|
|
$task = new Delete(); |
|
50
|
|
|
|
|
51
|
|
|
$processor->execute($task); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @expectedException \AppBundle\Exception\TaskException |
|
56
|
|
|
* @expectedExceptionCode \AppBundle\Exception\TaskException::INVALID_TASK |
|
57
|
|
|
*/ |
|
58
|
|
View Code Duplication |
public function testInvalidTask() |
|
|
|
|
|
|
59
|
|
|
{ |
|
60
|
|
|
$storage = $this->getMockForAbstractClass(StorageInterface::class); |
|
61
|
|
|
$processor = new Processor($storage); |
|
62
|
|
|
$task = $this->getMockBuilder(Task::class) |
|
63
|
|
|
->getMock(); |
|
64
|
|
|
|
|
65
|
|
|
$processor->execute($task); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.