1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Test\Brownie\BpmOnline\DataService\Contract; |
4
|
|
|
|
5
|
|
|
use Brownie\BpmOnline\DataService\Column\ColumnExpression; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
use Brownie\BpmOnline\DataService\Contract\InsertContract; |
8
|
|
|
use Prophecy\Prophecy\MethodProphecy; |
9
|
|
|
|
10
|
|
|
class InsertContractTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @var InsertContract |
15
|
|
|
*/ |
16
|
|
|
private $insertContract; |
17
|
|
|
|
18
|
|
|
protected function setUp() |
19
|
|
|
{ |
20
|
|
|
$this->insertContract = new InsertContract('rootSchemaName'); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
protected function tearDown() |
24
|
|
|
{ |
25
|
|
|
$this->insertContract = null; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testSetGetRootSchemaName() |
29
|
|
|
{ |
30
|
|
|
$this->assertEquals('rootSchemaName', $this->insertContract->getRootSchemaName()); |
31
|
|
|
$this->insertContract->setRootSchemaName('TestRootSchemaName'); |
32
|
|
|
$this->assertEquals('TestRootSchemaName', $this->insertContract->getRootSchemaName()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testSetGetOperationType() |
36
|
|
|
{ |
37
|
|
|
$this->assertEquals(1, $this->insertContract->getOperationType()); |
38
|
|
|
$this->insertContract->setOperationType(100); |
39
|
|
|
$this->assertEquals(100, $this->insertContract->getOperationType()); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testSetGetContractType() |
43
|
|
|
{ |
44
|
|
|
$this->assertEquals('InsertQuery', $this->insertContract->getContractType()); |
45
|
|
|
$this->insertContract->setContractType('TestInsertQuery'); |
46
|
|
|
$this->assertEquals('TestInsertQuery', $this->insertContract->getContractType()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @expectedException \Brownie\BpmOnline\Exception\ValidateException |
51
|
|
|
*/ |
52
|
|
|
public function testValidateException() |
53
|
|
|
{ |
54
|
|
|
$this->insertContract->validate(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testAddColumn() |
58
|
|
|
{ |
59
|
|
|
$columnExpression = $this->prophesize(ColumnExpression::class); |
60
|
|
|
$columnExpressionMethodToArray = new MethodProphecy( |
61
|
|
|
$columnExpression, |
62
|
|
|
'toArray', |
63
|
|
|
[] |
64
|
|
|
); |
65
|
|
|
$columnExpression |
66
|
|
|
->addMethodProphecy( |
67
|
|
|
$columnExpressionMethodToArray->willReturn([]) |
68
|
|
|
); |
69
|
|
|
|
70
|
|
|
$insertContract = $this->insertContract->addColumn('TestColumn', $columnExpression->reveal()); |
71
|
|
|
|
72
|
|
|
$this->assertInstanceOf(InsertContract::class, $insertContract); |
73
|
|
|
|
74
|
|
|
$this->insertContract->validate(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testToArray() |
78
|
|
|
{ |
79
|
|
|
$this->assertEquals([ |
80
|
|
|
'RootSchemaName' => 'rootSchemaName', |
81
|
|
|
'OperationType' => 1, |
82
|
|
|
'ColumnValues' => [ |
83
|
|
|
'Items' => [] |
84
|
|
|
] |
85
|
|
|
], $this->insertContract->toArray()); |
86
|
|
|
|
87
|
|
|
$columnExpression = $this->prophesize(ColumnExpression::class); |
88
|
|
|
$columnExpressionMethodToArray = new MethodProphecy( |
89
|
|
|
$columnExpression, |
90
|
|
|
'toArray', |
91
|
|
|
array() |
92
|
|
|
); |
93
|
|
|
$columnExpression |
94
|
|
|
->addMethodProphecy( |
95
|
|
|
$columnExpressionMethodToArray->willReturn([ |
96
|
|
|
'test' => 'Ok' |
97
|
|
|
]) |
98
|
|
|
); |
99
|
|
|
|
100
|
|
|
$this->insertContract->addColumn('TestColumn', $columnExpression->reveal()); |
101
|
|
|
|
102
|
|
|
$this->assertEquals([ |
103
|
|
|
'RootSchemaName' => 'rootSchemaName', |
104
|
|
|
'OperationType' => 1, |
105
|
|
|
'ColumnValues' => [ |
106
|
|
|
'Items' => [ |
107
|
|
|
'TestColumn' => ['test' => 'Ok'] |
108
|
|
|
] |
109
|
|
|
] |
110
|
|
|
], $this->insertContract->toArray()); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|