1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Dbal\Actions\AbstractAction |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2021 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/techdivision/import-dbal |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Dbal\Actions; |
22
|
|
|
|
23
|
|
|
use PHPUnit\Framework\TestCase; |
24
|
|
|
use TechDivision\Import\Dbal\Actions\Processors\ProcessorInterface; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Test class for the abstract action implementation. |
28
|
|
|
* |
29
|
|
|
* @author Tim Wagner <[email protected]> |
30
|
|
|
* @copyright 2021 TechDivision GmbH <[email protected]> |
31
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
32
|
|
|
* @link https://github.com/techdivision/import-dbal |
33
|
|
|
* @link http://www.techdivision.com |
34
|
|
|
*/ |
35
|
|
|
class AbstractActionTest extends TestCase |
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Test's the getter/setter for the create processor. |
40
|
|
|
* |
41
|
|
|
* @return void |
42
|
|
|
*/ |
43
|
|
|
public function testSetGetCreateProcessor() |
44
|
|
|
{ |
45
|
|
|
|
46
|
|
|
// create a persist processor mock instance |
47
|
|
|
$mockCreateProcessor = $this->getMockBuilder($processorInterface = ProcessorInterface::class) |
48
|
|
|
->setMethods(get_class_methods($processorInterface)) |
49
|
|
|
->getMock(); |
50
|
|
|
|
51
|
|
|
// create a mock for the abstract action |
52
|
|
|
$mockAction = $this->getMockForAbstractClass(AbstractAction::class); |
53
|
|
|
|
54
|
|
|
// test the setter/getter for the persist processor |
55
|
|
|
$mockAction->setCreateProcessor($mockCreateProcessor); |
56
|
|
|
$this->assertSame($mockCreateProcessor, $mockAction->getCreateProcessor()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Test's the getter/setter for the delete processor. |
61
|
|
|
* |
62
|
|
|
* @return void |
63
|
|
|
*/ |
64
|
|
|
public function testSetGetDeleteProcessor() |
65
|
|
|
{ |
66
|
|
|
|
67
|
|
|
// create a delete processor mock instance |
68
|
|
|
$mockDeleteProcessor = $this->getMockBuilder($processorInterface = ProcessorInterface::class) |
69
|
|
|
->setMethods(get_class_methods($processorInterface)) |
70
|
|
|
->getMock(); |
71
|
|
|
|
72
|
|
|
// create a mock for the abstract action |
73
|
|
|
$mockAction = $this->getMockForAbstractClass(AbstractAction::class); |
74
|
|
|
|
75
|
|
|
// test the setter/getter for the delete processor |
76
|
|
|
$mockAction->setDeleteProcessor($mockDeleteProcessor); |
77
|
|
|
$this->assertSame($mockDeleteProcessor, $mockAction->getDeleteProcessor()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Test's the persist() method successfull. |
82
|
|
|
* |
83
|
|
|
* @return void |
84
|
|
|
*/ |
85
|
|
|
public function testCreateWithSuccess() |
86
|
|
|
{ |
87
|
|
|
|
88
|
|
|
// create a create processor mock instance |
89
|
|
|
$mockCreateProcessor = $this->getMockBuilder($processorInterface = ProcessorInterface::class) |
90
|
|
|
->setMethods(get_class_methods($processorInterface)) |
91
|
|
|
->getMock(); |
92
|
|
|
$mockCreateProcessor->expects($this->once()) |
93
|
|
|
->method('execute') |
94
|
|
|
->with($row = array()) |
95
|
|
|
->willReturn(null); |
96
|
|
|
|
97
|
|
|
// create a mock for the abstract action |
98
|
|
|
$mockAction = $this->getMockBuilder(AbstractAction::class) |
99
|
|
|
->setMethods(array('getCreateProcessor')) |
100
|
|
|
->getMock(); |
101
|
|
|
$mockAction->expects($this->once()) |
102
|
|
|
->method('getCreateProcessor') |
103
|
|
|
->willReturn($mockCreateProcessor); |
104
|
|
|
|
105
|
|
|
// test the persist() method |
106
|
|
|
$this->assertNull($mockAction->create($row)); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Test's the delete() method successfull. |
111
|
|
|
* |
112
|
|
|
* @return void |
113
|
|
|
*/ |
114
|
|
|
public function testDeleteWithSuccess() |
115
|
|
|
{ |
116
|
|
|
|
117
|
|
|
// create a delete processor mock instance |
118
|
|
|
$mockDeleteProcessor = $this->getMockBuilder($processorInterface = ProcessorInterface::class) |
119
|
|
|
->setMethods(get_class_methods($processorInterface)) |
120
|
|
|
->getMock(); |
121
|
|
|
$mockDeleteProcessor->expects($this->once()) |
122
|
|
|
->method('execute') |
123
|
|
|
->with($row = array()) |
124
|
|
|
->willReturn(null); |
125
|
|
|
|
126
|
|
|
// create a mock for the abstract action |
127
|
|
|
$mockAction = $this->getMockBuilder(AbstractAction::class) |
128
|
|
|
->setMethods(array('getDeleteProcessor')) |
129
|
|
|
->getMock(); |
130
|
|
|
$mockAction->expects($this->once()) |
131
|
|
|
->method('getDeleteProcessor') |
132
|
|
|
->willReturn($mockDeleteProcessor); |
133
|
|
|
|
134
|
|
|
// test the delete() method |
135
|
|
|
$this->assertNull($mockAction->delete($row)); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|