Completed
Push — location_references ( 47d67d )
by
unknown
13:55
created

LimitedLocationServiceTest::testLoadLocation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace eZ\Publish\Core\LocationReference\Tests;
6
7
use eZ\Publish\Core\LocationReference\LimitedLocationService;
8
use eZ\Publish\API\Repository\LocationService;
9
use eZ\Publish\API\Repository\Values\Content\Location;
10
use PHPUnit\Framework\TestCase;
11
12
final class LimitedLocationServiceTest extends TestCase
13
{
14
    private const LOCATION_ID = 54;
15
    private const LOCATION_REMOTE_ID = 'babe4a915b1dd5d369e79adb9d6c0c6a';
16
    private const LOCATION_PATH = '/1/2/54/';
17
18
    /** @var \eZ\Publish\API\Repository\LocationService|\PHPUnit\Framework\MockObject\MockObject */
19
    private $locationService;
20
21
    /** @var \eZ\Publish\API\Repository\Values\Content\Location */
22
    private $expectedLocation;
23
24
    /** @var \eZ\Publish\Core\LocationReference\LimitedLocationService */
25
    private $limitedLocationService;
26
27
    protected function setUp(): void
28
    {
29
        $this->locationService = $this->createMock(LocationService::class);
30
        $this->expectedLocation = $this->createMock(Location::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\eZ\Pu...ontent\Location::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<eZ\Publish\API\Re...alues\Content\Location> of property $expectedLocation.

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...
31
        $this->limitedLocationService = new LimitedLocationService($this->locationService);
32
    }
33
34
    public function testLoadLocation(): void
35
    {
36
        $this->locationService
37
            ->method('loadLocation')
38
            ->with(self::LOCATION_ID)
39
            ->willReturn($this->expectedLocation);
40
41
        $this->assertEquals(
42
            $this->expectedLocation,
43
            $this->limitedLocationService->loadLocation(self::LOCATION_ID)
44
        );
45
    }
46
47
    public function testLocationByRemoteId(): void
48
    {
49
        $this->locationService
50
            ->method('loadLocationByRemoteId')
51
            ->with(self::LOCATION_REMOTE_ID)
52
            ->willReturn($this->expectedLocation);
53
54
        $this->assertEquals(
55
            $this->expectedLocation,
56
            $this->limitedLocationService->loadLocationByRemoteId(self::LOCATION_REMOTE_ID)
57
        );
58
    }
59
60
    public function testLocationByPathString(): void
61
    {
62
        $this->locationService
63
            ->method('loadLocation')
64
            ->with(self::LOCATION_ID)
65
            ->willReturn($this->expectedLocation);
66
67
        $this->assertEquals(
68
            $this->expectedLocation,
69
            $this->limitedLocationService->loadLocationByPathString(self::LOCATION_PATH)
70
        );
71
    }
72
73
    public function testParentLocation(): void
74
    {
75
        $location = $this->createMock(Location::class);
76
        $location
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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...
77
            ->method('__get')
78
            ->with('parentLocationId')
79
            ->willReturn(self::LOCATION_ID);
80
81
        $this->locationService
82
            ->method('loadLocation')
83
            ->with(self::LOCATION_ID)
84
            ->willReturn($this->expectedLocation);
85
86
        $this->assertEquals(
87
            $this->expectedLocation,
88
            $this->limitedLocationService->loadParentLocation($location)
89
        );
90
    }
91
}
92