This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace RbCommentTest\Model; |
||
3 | |||
4 | use RbComment\Model\Comment; |
||
5 | use RbComment\Model\CommentTable; |
||
6 | use Zend\Db\Sql\Select; |
||
7 | use Zend\Db\ResultSet\ResultSet; |
||
8 | use PHPUnit_Framework_TestCase; |
||
9 | use Zend\Db\TableGateway\TableGateway; |
||
10 | |||
11 | class CommentTableTest extends PHPUnit_Framework_TestCase |
||
12 | { |
||
13 | private $tableGatewayMock; |
||
14 | |||
15 | public function setUp() |
||
16 | { |
||
17 | $this->tableGatewayMock = $this->createMock(TableGateway::class); |
||
18 | } |
||
19 | |||
20 | /** |
||
21 | * @group table |
||
22 | */ |
||
23 | public function testConstructorStoresDependencies() |
||
24 | { |
||
25 | $commentTable = new CommentTable($this->tableGatewayMock); |
||
26 | |||
27 | // Assertions |
||
28 | $this->assertAttributeEquals($this->tableGatewayMock, 'tableGateway', $commentTable); |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * @group table |
||
33 | */ |
||
34 | public function testFetchAllReturnsAllComments() |
||
35 | { |
||
36 | $resultSet = new ResultSet(); |
||
37 | |||
38 | $this->tableGatewayMock->expects($this->once()) |
||
39 | ->method('select') |
||
40 | ->willReturn($resultSet); |
||
41 | |||
42 | $commentTable = new CommentTable($this->tableGatewayMock); |
||
43 | |||
44 | $this->assertSame($resultSet, $commentTable->fetchAll()); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * @group table |
||
49 | */ |
||
50 | public function testFetchAllForThreadReturnsAllTheCommentsInThread() |
||
51 | { |
||
52 | $resultSet = new ResultSet(); |
||
53 | |||
54 | $this->tableGatewayMock->expects($this->once()) |
||
55 | ->method('selectWith') |
||
56 | ->willReturn($resultSet); |
||
57 | |||
58 | $commentTable = new CommentTable($this->tableGatewayMock); |
||
59 | |||
60 | $this->assertSame($resultSet, $commentTable->fetchAllForThread('test')); |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * @group table |
||
65 | */ |
||
66 | public function testFetchAllPendingForThreadReturnsAllThePendingCommentsInAThread() |
||
67 | { |
||
68 | $resultSet = new ResultSet(); |
||
69 | |||
70 | $this->tableGatewayMock->expects($this->once()) |
||
71 | ->method('selectWith') |
||
72 | ->willReturn($resultSet); |
||
73 | |||
74 | $commentTable = new CommentTable($this->tableGatewayMock); |
||
75 | |||
76 | $this->assertSame($resultSet, $commentTable->fetchAllPendingForThread('test')); |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * @group table |
||
81 | */ |
||
82 | public function testFetchAllUsingSelectUsesTheCustomSelectAndReturnsTheResult() |
||
83 | { |
||
84 | $resultSetMock = new ResultSet(); |
||
85 | $selectMock = new Select(); |
||
86 | |||
87 | $this->tableGatewayMock->expects($this->once()) |
||
88 | ->method('selectWith') |
||
89 | ->with($selectMock) |
||
90 | ->willReturn($resultSetMock); |
||
91 | |||
92 | $commentTableMock = new CommentTable($this->tableGatewayMock); |
||
93 | |||
94 | $this->assertSame( |
||
95 | $resultSetMock, |
||
96 | $commentTableMock->fetchAllUsingSelect($selectMock) |
||
97 | ); |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * @group table |
||
102 | */ |
||
103 | public function testCanRetrieveACommentByItsId() |
||
104 | { |
||
105 | $commentData = [ |
||
106 | 'id' => 12345, |
||
107 | 'thread' => 'f133a4599372cf531bcdbfeb1116b9afe8d09b4f', |
||
108 | 'uri' => '/test', |
||
109 | 'author' => 'Robert Boloc', |
||
110 | 'contact' => '[email protected]', |
||
111 | 'content' => 'Bla bla bla', |
||
112 | 'visible' => 1, |
||
113 | 'spam' => 0, |
||
114 | ]; |
||
115 | |||
116 | $comment = new Comment(); |
||
117 | $comment->exchangeArray($commentData); |
||
118 | |||
119 | $resultSet = new ResultSet(); |
||
120 | $resultSet->setArrayObjectPrototype(new Comment()); |
||
0 ignored issues
–
show
|
|||
121 | $resultSet->initialize([$commentData]); |
||
122 | |||
123 | $this->tableGatewayMock->expects($this->once()) |
||
124 | ->method('select') |
||
125 | ->with(['id' => 12345]) |
||
126 | ->will($this->returnValue($resultSet)); |
||
127 | |||
128 | $commentTable = new CommentTable($this->tableGatewayMock); |
||
129 | |||
130 | $this->assertEquals($comment, $commentTable->getComment(12345)); |
||
131 | } |
||
132 | |||
133 | /** |
||
134 | * @group table |
||
135 | */ |
||
136 | public function testSaveCommentWillInsertNewCommentIfDoesNotAlreadyHaveAnId() |
||
137 | { |
||
138 | $comment = new Comment(); |
||
139 | $commentData = [ |
||
140 | 'thread' => 'f133a4599372cf531bcdbfeb1116b9afe8d09b4f', |
||
141 | 'uri' => '/test', |
||
142 | 'author' => 'Robert Boloc', |
||
143 | 'contact' => '[email protected]', |
||
144 | 'content' => 'Bla bla bla', |
||
145 | 'visible' => 1, |
||
146 | 'spam' => 0, |
||
147 | ]; |
||
148 | |||
149 | $comment->exchangeArray($commentData); |
||
150 | |||
151 | $this->tableGatewayMock->expects($this->once()) |
||
152 | ->method('insert') |
||
153 | ->with($commentData); |
||
154 | |||
155 | $commentTable = new CommentTable($this->tableGatewayMock); |
||
156 | $commentTable->saveComment($comment); |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * @group table |
||
161 | */ |
||
162 | public function testSaveCommentWillUpdateExistingCommentIfItAlreadyHasAnId() |
||
163 | { |
||
164 | $comment = new Comment(); |
||
165 | $commentData = [ |
||
166 | 'id' => 12345, |
||
167 | 'thread' => 'f133a4599372cf531bcdbfeb1116b9afe8d09b4f', |
||
168 | 'uri' => '/test', |
||
169 | 'author' => 'Robert Boloc', |
||
170 | 'contact' => '[email protected]', |
||
171 | 'content' => 'Bla bla bla', |
||
172 | 'visible' => 1, |
||
173 | 'spam' => 0, |
||
174 | ]; |
||
175 | |||
176 | $comment->exchangeArray($commentData); |
||
177 | |||
178 | $resultSet = new ResultSet(); |
||
179 | $resultSet->setArrayObjectPrototype(new Comment()); |
||
0 ignored issues
–
show
new \RbComment\Model\Comment() is of type object<RbComment\Model\Comment> , but the function expects a object<ArrayObject> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
180 | $resultSet->initialize([$commentData]); |
||
181 | |||
182 | $this->tableGatewayMock->expects($this->once()) |
||
183 | ->method('select') |
||
184 | ->with(['id' => 12345]) |
||
185 | ->will($this->returnValue($resultSet)); |
||
186 | |||
187 | $updateWith = [ |
||
188 | 'thread' => 'f133a4599372cf531bcdbfeb1116b9afe8d09b4f', |
||
189 | 'uri' => '/test', |
||
190 | 'author' => 'Robert Boloc', |
||
191 | 'contact' => '[email protected]', |
||
192 | 'content' => 'Bla bla bla', |
||
193 | 'visible' => 1, |
||
194 | 'spam' => 0, |
||
195 | ]; |
||
196 | |||
197 | $this->tableGatewayMock->expects($this->once()) |
||
198 | ->method('update') |
||
199 | ->with($updateWith, ['id' => 12345]); |
||
200 | |||
201 | $commentTable = new CommentTable($this->tableGatewayMock); |
||
202 | $commentTable->saveComment($comment); |
||
203 | } |
||
204 | |||
205 | /** |
||
206 | * @group table |
||
207 | */ |
||
208 | public function testCanDeleteACommentByItsId() |
||
209 | { |
||
210 | $this->tableGatewayMock->expects($this->once()) |
||
211 | ->method('delete') |
||
212 | ->with(['id' => 12345]); |
||
213 | |||
214 | $commentTable = new CommentTable($this->tableGatewayMock); |
||
215 | $commentTable->deleteComment(12345); |
||
216 | } |
||
217 | |||
218 | /** |
||
219 | * @group table |
||
220 | */ |
||
221 | public function testCanDeleteSpam() |
||
222 | { |
||
223 | $this->tableGatewayMock->expects($this->once()) |
||
224 | ->method('delete') |
||
225 | ->with(['spam' => 1]); |
||
226 | |||
227 | $commentTable = new CommentTable($this->tableGatewayMock); |
||
228 | $commentTable->deleteSpam(); |
||
229 | } |
||
230 | } |
||
231 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: