Passed
Push — master ( e1c5c8...a48a63 )
by Guillermo A.
08:16
created

RepositoryTest::testFindById()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace GuillermoandraeTest\Repositories;
4
5
use Guillermoandrae\Common\Collection;
6
use Guillermoandrae\Models\AbstractModel;
7
use Guillermoandrae\Repositories\AbstractRepository;
8
use Guillermoandrae\Repositories\RepositoryInterface;
9
use PHPUnit\Framework\TestCase;
10
11
class RepositoryTest extends TestCase
12
{
13
    /**
14
     * @var RepositoryInterface
15
     */
16
    private $repository;
17
18
    public function testFindById()
19
    {
20
        $id = 1;
21
        $model = $this->getMockForAbstractClass(AbstractModel::class);
22
        $this->repository->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Guillermoandrae\Repositories\RepositoryInterface. ( Ignorable by Annotation )

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

22
        $this->repository->/** @scrutinizer ignore-call */ 
23
                           expects($this->once())

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...
23
            ->method('findWhere')
24
            ->with($this->equalTo(['id' => $id]))
25
            ->willReturn(new Collection([$model]));
26
        $this->assertSame($model, $this->repository->findById($id));
27
    }
28
29
    public function testFind()
30
    {
31
        $id = 1;
32
        $model = $this->getMockForAbstractClass(AbstractModel::class);
33
        $this->repository->expects($this->any())
34
            ->method('findWhere')
35
            ->with($this->equalTo(['id' => $id]))
36
            ->willReturn(new Collection([$model]));
37
        $this->assertSame($this->repository->find($id), $this->repository->findById($id));
38
    }
39
40
    protected function setUp()
41
    {
42
        $this->repository = $this->getMockForAbstractClass(AbstractRepository::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockForAbstrac...tractRepository::class) of type PHPUnit\Framework\MockObject\MockObject is incompatible with the declared type Guillermoandrae\Repositories\RepositoryInterface of property $repository.

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

Loading history...
43
    }
44
}
45