These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace DoctrineModuleTest\Paginator\Adapter; |
||
6 | |||
7 | use Doctrine\Common\Collections\ArrayCollection; |
||
8 | use DoctrineModule\Paginator\Adapter\Collection as CollectionAdapter; |
||
9 | use PHPUnit\Framework\TestCase; |
||
10 | use function range; |
||
11 | |||
12 | /** |
||
13 | * Tests for the Collection pagination adapter |
||
14 | * |
||
15 | * @link http://www.doctrine-project.org/ |
||
16 | */ |
||
17 | class CollectionAdapterTest extends TestCase |
||
18 | { |
||
19 | /** @var CollectionAdapter */ |
||
20 | protected $adapter; |
||
21 | |||
22 | /** |
||
23 | * {@inheritDoc}. |
||
24 | */ |
||
25 | protected function setUp() : void |
||
26 | { |
||
27 | parent::setUp(); |
||
0 ignored issues
–
show
|
|||
28 | $this->adapter = new CollectionAdapter(new ArrayCollection(range(1, 101))); |
||
29 | } |
||
30 | |||
31 | public function testGetsItemsAtOffsetZero() : void |
||
32 | { |
||
33 | $expected = range(1, 10); |
||
34 | $actual = $this->adapter->getItems(0, 10); |
||
35 | $this->assertEquals($expected, $actual); |
||
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<DoctrineModuleTes...\CollectionAdapterTest> .
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...
|
|||
36 | } |
||
37 | |||
38 | public function testGetsItemsAtOffsetTen() : void |
||
39 | { |
||
40 | $expected = range(11, 20); |
||
41 | $actual = $this->adapter->getItems(10, 10); |
||
42 | $this->assertEquals($expected, $actual); |
||
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<DoctrineModuleTes...\CollectionAdapterTest> .
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 | } |
||
44 | |||
45 | public function testReturnsCorrectCount() : void |
||
46 | { |
||
47 | $this->assertEquals(101, $this->adapter->count()); |
||
48 | } |
||
49 | |||
50 | public function testEmptySet() : void |
||
51 | { |
||
52 | $adapter = new CollectionAdapter(new ArrayCollection()); |
||
53 | $actual = $adapter->getItems(0, 10); |
||
54 | $this->assertEquals([], $actual); |
||
55 | } |
||
56 | } |
||
57 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: