Failed Conditions
Pull Request — master (#6649)
by Marco
140:45 queued 75:42
created

LazyPropertyMapTest::testDirectPropertyAccess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LazyMapTest;
6
7
use Doctrine\ORM\Internal\Hydration\Cache\LazyPropertyMap;
8
use PHPUnit\Framework\TestCase;
9
use stdClass;
10
11
/**
12
 * @link https://github.com/Ocramius/LazyMap/blob/1.0.0/tests/LazyMapTest/CallbackLazyMapTest.php
13
 *
14
 * @covers \Doctrine\ORM\Internal\Hydration\Cache\LazyPropertyMap
15
 */
16
class LazyPropertyMapTest extends TestCase
17
{
18
    /**
19
     * @var \LazyMap\CallbackLazyMap
20
     */
21
    protected $lazyMap;
22
23
    /**
24
     * @var callable|\PHPUnit_Framework_MockObject_MockObject
25
     */
26
    protected $callback;
27
28
    protected function setUp() : void
29
    {
30
        parent::setUp();
31
32
        $this->callback = $this->getMockBuilder(stdClass::class)->setMethods(['__invoke'])->getMock();
33
        $this->lazyMap  = new LazyPropertyMap($this->callback);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Doctrine\ORM\Intern...rtyMap($this->callback) of type object<Doctrine\ORM\Inte...\Cache\LazyPropertyMap> is incompatible with the declared type object<LazyMap\CallbackLazyMap> of property $lazyMap.

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...
34
    }
35
36
    public function testDirectPropertyAccess()
37
    {
38
        $count = 0;
39
        $this
0 ignored issues
show
Bug introduced by
The method expects cannot be called on $this->callback (of type callable).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
40
            ->callback
41
            ->expects(self::exactly(3))
42
            ->method('__invoke')
43
            ->will(self::returnCallback(function ($name) use (& $count) {
44
                $count += 1;
45
46
                return $name . ' - ' . $count;
47
            }));
48
49
        $this->assertSame('foo - 1', $this->lazyMap->foo);
50
        $this->assertSame('bar - 2', $this->lazyMap->bar);
51
        $this->assertSame('baz\\tab - 3', $this->lazyMap->{'baz\\tab'});
52
    }
53
}
54