Completed
Branch master (1820a0)
by Oss
02:45
created

DeleteContractTest::testAddFilter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 9.536
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Test\Brownie\BpmOnline\DataService\Contract;
4
5
use Brownie\BpmOnline\DataService\Column\ColumnFilter;
6
use PHPUnit\Framework\TestCase;
7
use Brownie\BpmOnline\DataService\Contract\DeleteContract;
8
use Prophecy\Prophecy\MethodProphecy;
9
10
class DeleteContractTest extends TestCase
11
{
12
13
    /**
14
     * @var DeleteContract
15
     */
16
    private $deleteContract;
17
18
    protected function setUp()
19
    {
20
        $this->deleteContract = new DeleteContract('rootSchemaName');
21
    }
22
23
    protected function tearDown()
24
    {
25
        $this->deleteContract = null;
26
    }
27
28
    public function testSetGetRootSchemaName()
29
    {
30
        $this->assertEquals('rootSchemaName', $this->deleteContract->getRootSchemaName());
31
        $this->deleteContract->setRootSchemaName('TestRootSchemaName');
32
        $this->assertEquals('TestRootSchemaName', $this->deleteContract->getRootSchemaName());
33
    }
34
35
    public function testSetGetOperationType()
36
    {
37
        $this->assertEquals(3, $this->deleteContract->getOperationType());
38
        $this->deleteContract->setOperationType(300);
39
        $this->assertEquals(300, $this->deleteContract->getOperationType());
40
    }
41
42
    public function testSetGetContractType()
43
    {
44
        $this->assertEquals('DeleteQuery', $this->deleteContract->getContractType());
45
        $this->deleteContract->setContractType('TestDeleteQuery');
46
        $this->assertEquals('TestDeleteQuery', $this->deleteContract->getContractType());
47
    }
48
49
    /**
50
     * @expectedException \Brownie\BpmOnline\Exception\ValidateException
51
     */
52
    public function testValidateException()
53
    {
54
        $this->deleteContract->setOperationType(1);
55
        $this->assertNull($this->deleteContract->validate());
56
    }
57
58
    public function testValidate()
59
    {
60
        $columnFilter = $this->prophesize(ColumnFilter::class);
61
        $columnFilterMethodToArray = new MethodProphecy(
62
            $columnFilter,
63
            'toArray',
64
            []
65
        );
66
        $columnFilter
67
            ->addMethodProphecy(
68
                $columnFilterMethodToArray->willReturn(['test' => 'Ok'])
69
            );
70
71
        $columnFilterMethodValidate = new MethodProphecy(
72
            $columnFilter,
73
            'validate',
74
            []
75
        );
76
        $columnFilter
77
            ->addMethodProphecy(
78
                $columnFilterMethodValidate->willReturn(null)
79
            );
80
81
        $deleteContract = $this->deleteContract->addFilter($columnFilter->reveal());
82
83
        $this->assertInstanceOf(DeleteContract::class, $deleteContract);
84
        $this->assertNull($this->deleteContract->validate());
85
    }
86
87
    public function testAddFilter()
88
    {
89
        $columnFilter = $this->prophesize(ColumnFilter::class);
90
        $columnFilterMethodToArray = new MethodProphecy(
91
            $columnFilter,
92
            'toArray',
93
            []
94
        );
95
        $columnFilter
96
            ->addMethodProphecy(
97
                $columnFilterMethodToArray->willReturn(['test' => 'Ok'])
98
            );
99
100
        $deleteContract = $this->deleteContract->addFilter($columnFilter->reveal());
101
102
        $this->assertInstanceOf(DeleteContract::class, $deleteContract);
103
        $this->assertEquals([
104
            'RootSchemaName' => 'rootSchemaName',
105
            'OperationType' => 3,
106
            'Filters' => [
107
                'test' => 'Ok',
108
            ],
109
        ], $this->deleteContract->toArray());
110
    }
111
112
    public function testToArray()
113
    {
114
        $this->assertEquals([
115
            'RootSchemaName' => 'rootSchemaName',
116
            'OperationType' => 3,
117
            'Filters' => [],
118
        ], $this->deleteContract->toArray());
119
    }
120
}
121