Test Failed
Push — master ( 475bfc...ca0e1d )
by Oss
05:46
created

DeleteContractTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 111
Duplicated Lines 25.23 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 4
dl 28
loc 111
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A tearDown() 0 4 1
A testSetGetRootSchemaName() 0 6 1
A testSetGetOperationType() 0 6 1
A testSetGetContractType() 0 6 1
A testValidateException() 0 5 1
A testValidate() 28 28 1
A testAddFilter() 0 24 1
A testToArray() 0 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 View Code Duplication
    public function testValidate()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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