These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\AdminListBundle\Tests\AdminList; |
||
4 | |||
5 | use Doctrine\DBAL\Query\QueryBuilder; |
||
6 | use Doctrine\DBAL\Statement; |
||
7 | use Kunstmaan\AdminListBundle\Helper\DoctrineDBALAdapter; |
||
8 | use LogicException; |
||
9 | use PHPUnit\Framework\TestCase; |
||
10 | |||
11 | /** |
||
12 | * Class AdminListTest |
||
13 | */ |
||
14 | class DoctrineDBALAdapterTest extends TestCase |
||
15 | { |
||
16 | /** |
||
17 | * @var DoctrineDBALAdapter |
||
18 | */ |
||
19 | private $adapter; |
||
20 | |||
21 | /** |
||
22 | * @var QueryBuilder |
||
23 | */ |
||
24 | private $qb; |
||
25 | |||
26 | public function setUp() |
||
27 | { |
||
28 | $statement = $this->createMock(Statement::class); |
||
29 | $statement->expects($this->any())->method('fetchAll')->willReturn([1, 2, 3]); |
||
30 | $statement->expects($this->any())->method('fetchColumn')->willReturn([1, 2, 3]); |
||
31 | $qb = $this->createMock(QueryBuilder::class); |
||
32 | $qb->expects($this->any())->method('setMaxResults')->willReturn($qb); |
||
33 | $qb->expects($this->any())->method('setFirstResult')->willReturn($qb); |
||
34 | $qb->expects($this->any())->method('select')->willReturn($qb); |
||
35 | $qb->expects($this->any())->method('orderBy')->willReturn($qb); |
||
36 | $qb->expects($this->any())->method('execute')->willReturn($statement); |
||
37 | $this->qb = $qb; |
||
0 ignored issues
–
show
|
|||
38 | } |
||
39 | |||
40 | public function testGetQueryBuilder() |
||
41 | { |
||
42 | $this->qb->expects($this->any())->method('getType')->willReturn(QueryBuilder::SELECT); |
||
0 ignored issues
–
show
The method
expects() does not seem to exist on object<Doctrine\DBAL\Query\QueryBuilder> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
43 | $this->adapter = new DoctrineDBALAdapter($this->qb, 'table.somefield'); |
||
44 | $this->assertInstanceOf(QueryBuilder::class, $this->adapter->getQueryBuilder()); |
||
45 | } |
||
46 | |||
47 | public function testConstructorThrowsException() |
||
48 | { |
||
49 | $this->expectException(LogicException::class); |
||
50 | $this->adapter = new DoctrineDBALAdapter($this->qb, 'somefield'); |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * @throws \ReflectionException |
||
55 | */ |
||
56 | public function testConstructorThrowsAnotherException() |
||
57 | { |
||
58 | $this->qb->expects($this->any())->method('getType')->willReturn(QueryBuilder::DELETE); |
||
0 ignored issues
–
show
The method
expects() does not seem to exist on object<Doctrine\DBAL\Query\QueryBuilder> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
59 | |||
60 | $this->expectException(LogicException::class); |
||
61 | |||
62 | $this->adapter = new DoctrineDBALAdapter($this->qb, 'table.somefield'); |
||
63 | } |
||
64 | |||
65 | View Code Duplication | public function testGetSlice() |
|
0 ignored issues
–
show
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...
|
|||
66 | { |
||
67 | $this->qb->expects($this->any())->method('getType')->willReturn(QueryBuilder::SELECT); |
||
0 ignored issues
–
show
The method
expects() does not seem to exist on object<Doctrine\DBAL\Query\QueryBuilder> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
68 | $this->adapter = new DoctrineDBALAdapter($this->qb, 'table.somefield'); |
||
69 | $result = $this->adapter->getSlice(0, 3); |
||
70 | $this->assertCount(3, $result); |
||
0 ignored issues
–
show
$result is of type array|object<Traversable> , but the function expects a object<Countable>|object...nit\Framework\iterable> .
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);
Loading history...
|
|||
71 | } |
||
72 | |||
73 | View Code Duplication | public function testNbResults() |
|
0 ignored issues
–
show
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...
|
|||
74 | { |
||
75 | $this->qb->expects($this->any())->method('getType')->willReturn(QueryBuilder::SELECT); |
||
0 ignored issues
–
show
The method
expects() does not seem to exist on object<Doctrine\DBAL\Query\QueryBuilder> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
76 | $this->adapter = new DoctrineDBALAdapter($this->qb, 'table.somefield'); |
||
77 | $result = $this->adapter->getNbResults(); |
||
78 | $this->assertCount(3, $result); |
||
0 ignored issues
–
show
$result is of type integer , but the function expects a object<Countable>|object...nit\Framework\iterable> .
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);
Loading history...
|
|||
79 | } |
||
80 | } |
||
81 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..