Completed
Push — master ( bc825a...1aba9a )
by William
06:03
created

ReportsTableTest::testGetRelatedByField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 68
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 45
nc 1
nop 0
dl 0
loc 68
rs 9.2
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace App\Test\TestCase\Model\Table;
4
5
use Cake\ORM\TableRegistry;
6
use Cake\TestSuite\TestCase;
7
8
class ReportsTableTest extends TestCase
9
{
10
    public $fixtures = [
11
        'app.Notifications',
12
        'app.Developers',
13
        'app.Reports',
14
        'app.Incidents',
15
    ];
16
17
    public function setUp()
18
    {
19
        parent::setUp();
20
        $this->Reports = TableRegistry::get('Reports');
0 ignored issues
show
Deprecated Code introduced by
The function Cake\ORM\TableRegistry::get() has been deprecated: 3.6.0 Use \Cake\ORM\Locator\TableLocator::get() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

20
        $this->Reports = /** @scrutinizer ignore-deprecated */ TableRegistry::get('Reports');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Bug Best Practice introduced by
The property Reports does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
21
    }
22
23
    public function testGetIncidents()
24
    {
25
        $this->Reports->id = 4;
26
        $incidents = $this->Reports->getIncidents();
27
        $this->assertInstanceOf('Cake\ORM\Query', $incidents);
28
        $result = $incidents->hydrate(false)->toArray();
29
        $this->assertEquals(count($result), 2);
30
31
        //$this->Reports->saveField("related_to", null); TODO: fix related to issue
32
        //$incidents = $this->Report->getIncidents();
33
        //$this->assertEquals(count($incidents), 2);
34
    }
35
36
    //TODO: will do after related to fix
37
    //public function testGetRelatedReports() {
38
    //    $this->Reports->id = 2;
39
    //    $reports = $this->Reports->getRelatedReports();
40
    //    $this->assertEquals(count($reports), 0);
41
    //
42
    //    $this->Report->read(null, 4);
43
    //    $reports = $this->Report->getRelatedReports();
44
    //    $this->assertEquals(count($reports), 1);
45
    //}
46
47
    /**
48
     * @return void
49
     */
50
    public function testGetIncidentsWithDescription()
51
    {
52
        $this->Reports->id = 4;
53
        $incidents = $this->Reports->getIncidentsWithDescription();
54
        $this->assertInstanceOf('Cake\ORM\Query', $incidents);
55
        $result = $incidents->hydrate(false)->toArray();
56
        $this->assertEquals(count($result), 1);
57
    }
58
59
    public function testGetIncidentsWithDifferentStacktrace()
60
    {
61
        $this->Reports->id = 4;
62
        $incidents = $this->Reports->getIncidentsWithDifferentStacktrace();
63
        $this->assertInstanceOf('Cake\ORM\Query', $incidents);
64
        $result = $incidents->hydrate(false)->toArray();
65
        $this->assertEquals(count($result), 1);
66
    }
67
68
    // TODO: will do after related to fix
69
    //    public function testRemoveFromRelatedGroup() {
70
    //        $this->Report->read(null, 1);
71
    //        $this->Report->removeFromRelatedGroup();
72
    //        $incidents = $this->Report->getIncidents();
73
    //        $this->assertEquals(count($incidents), 1);
74
    //    }
75
76
    /**
77
     * @return void
78
     */
79
    public function testGetUrl()
80
    {
81
        $this->Reports->id = 1;
82
        $this->assertStringEndsWith(
83
            '/reports/view/1',
84
            $this->Reports->getUrl()
85
        );
86
    }
87
88
    // TODO: will do after realted to fix
89
    //public function testAddToRelatedGroup() {
90
    //    $this->Report->read(null, 2);
91
    //    $this->Report->addToRelatedGroup(4);
92
    //
93
    //    $this->Report->read(null, 2);
94
    //    $incidents = $this->Report->getIncidents();
95
    //    $this->assertEquals(count($incidents), 3);
96
    //
97
    //    $this->Report->saveField("related_to", null);
98
    //    $this->Report->addToRelatedGroup(1);
99
    //    $this->Report->read(null, 2);
100
    //    $incidents = $this->Report->getIncidents();
101
    //    $this->assertEquals(count($incidents), 3);
102
    //}
103
104
    /**
105
     * @return void
106
     */
107
    public function testGetRelatedByField()
108
    {
109
        $this->Reports->id = 1;
110
        $result = $this->Reports->getRelatedByField('php_version');
111
        $this->assertInstanceOf('Cake\ORM\Query', $result);
112
        $result = $result->hydrate(false)->toArray();
113
        $expected = [
114
            [
115
                'php_version' => '5.5',
116
                'count' => '1',
117
            ],
118
        ];
119
        $this->assertEquals($expected, $result);
120
        $this->Reports->id = 4;
121
        $result = $this->Reports->getRelatedByField('php_version', 1);
122
        $this->assertInstanceOf('Cake\ORM\Query', $result);
123
        $result = $result->hydrate(false)->toArray();
124
        $expected = [
125
            [
126
                'php_version' => '5.3',
127
                'count' => '2',
128
            ],
129
        ];
130
        $this->assertEquals($expected, $result);
131
        $this->Reports->id = 1;
132
        $result = $this->Reports->getRelatedByField(
133
            'php_version',
134
            10,
135
            false,
136
            true,
137
            '2013-08-29 18:10:01'
138
        );
139
        $this->assertInstanceOf('Cake\ORM\Query', $result);
140
        $result = $result->hydrate(false)->toArray();
141
        $expected = [
142
            [
143
                'php_version' => '5.5',
144
                'count' => '1',
145
            ],
146
        ];
147
        $this->assertEquals($expected, $result);
148
149
        $result = $this->Reports->getRelatedByField('php_version', 10, false, false);
150
        $this->assertInstanceOf('Cake\ORM\Query', $result);
151
        $result = $result->hydrate(false)->toArray();
152
        $expected = [
153
            [
154
                'php_version' => '5.5',
155
                'count' => '1',
156
            ],
157
            [
158
                'php_version' => '5.3',
159
                'count' => '4',
160
            ],
161
        ];
162
        $this->assertEquals($expected, $result);
163
        $result = $this->Reports->getRelatedByField('php_version', 10, true);
164
        $this->assertInstanceOf('Cake\ORM\Query', $result[0]);
165
        $result[0] = $result[0]->hydrate(false)->toArray();
166
        $expected = [
167
            [
168
                [
169
                    'php_version' => '5.5',
170
                    'count' => '1',
171
                ],
172
            ], 1,
173
        ];
174
        $this->assertEquals($expected, $result);
175
    }
176
}
177