Completed
Pull Request — master (#8)
by Pavel
05:07
created

ProxyTestAbstract::getClientNames()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Bankiru\Api\Tests;
4
5
use Bankiru\Api\Test\Entity\Sub\SubEntity;
6
use Doctrine\Common\Proxy\Proxy;
7
use GuzzleHttp\Psr7\Response;
8
9
class ProxyTestAbstract extends AbstractEntityManagerTest
10
{
11 1
    public function testLazyProxy()
12
    {
13 1
        $manager = $this->getManager();
14
15 1
        $this->getResponseMock()->append(
16 1
            new Response(
17 1
                200,
18 1
                [],
19 1
                json_encode(
20
                    [
21 1
                        'jsonrpc' => '2.0',
22 1
                        'id'      => 'test',
23
                        'result'  => [
24 1
                            'id'          => 2,
25 1
                            'payload'     => 'test-payload',
26 1
                            'sub-payload' => 'sub-payload',
27 1
                        ],
28
                    ]
29 1
                )
30 1
            )
31 1
        );
32
33
        /** @var SubEntity|Proxy $entity */
34 1
        $entity = $manager->getReference(SubEntity::class, 2);
35
36
        //Test that entity is a proxy and request was not send
37 1
        self::assertInstanceOf(Proxy::class, $entity);
38 1
        self::assertFalse($entity->__isInitialized());
0 ignored issues
show
Bug introduced by
The method __isInitialized does only exist in Doctrine\Common\Proxy\Proxy, but not in Bankiru\Api\Test\Entity\Sub\SubEntity.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
39 1
        self::assertGreaterThan(0, $this->getResponseMock()->count());
40
41
        //Test that we can obtain ID and request was still not sent
42 1
        self::assertEquals(2, $entity->getId());
0 ignored issues
show
Bug introduced by
The method getId does only exist in Bankiru\Api\Test\Entity\Sub\SubEntity, but not in Doctrine\Common\Proxy\Proxy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
43 1
        self::assertInstanceOf(Proxy::class, $entity);
44 1
        self::assertFalse($entity->__isInitialized());
45 1
        self::assertGreaterThan(0, $this->getResponseMock()->count());
46
47
        //Test that we can obtain data and request was sent
48 1
        self::assertInstanceOf(SubEntity::class, $entity);
49 1
        self::assertEquals('test-payload', $entity->getPayload());
0 ignored issues
show
Bug introduced by
The method getPayload does only exist in Bankiru\Api\Test\Entity\Sub\SubEntity, but not in Doctrine\Common\Proxy\Proxy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
50 1
        self::assertEquals('sub-payload', $entity->getSubPayload());
0 ignored issues
show
Bug introduced by
The method getSubPayload does only exist in Bankiru\Api\Test\Entity\Sub\SubEntity, but not in Doctrine\Common\Proxy\Proxy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
51
52
        //Test that we are still a Proxy object
53 1
        self::assertInstanceOf(Proxy::class, $entity);
54 1
        self::assertTrue($entity->__isInitialized());
55 1
        self::assertEquals(0, $this->getResponseMock()->count());
56 1
    }
57
58 1 View Code Duplication
    public function testSimpleProxy()
0 ignored issues
show
Duplication introduced by
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...
59
    {
60 1
        $repository = $this->getManager()->getRepository(SubEntity::class);
61
62 1
        $this->getResponseMock()->append(
63 1
            new Response(
64 1
                200,
65 1
                [],
66 1
                json_encode(
67
                    [
68 1
                        'jsonrpc' => '2.0',
69 1
                        'id'      => 'test',
70
                        'result'  => [
71 1
                            'id'          => 2,
72 1
                            'payload'     => 'test-payload',
73 1
                            'sub-payload' => 'sub-payload',
74 1
                        ],
75
                    ]
76 1
                )
77 1
            )
78 1
        );
79
80
        /** @var SubEntity|Proxy $entity */
81 1
        $entity = $repository->find(2);
82
83
        //Test that we can obtain data and request was sent
84 1
        self::assertInstanceOf(SubEntity::class, $entity);
85 1
        self::assertEquals(2, $entity->getId());
0 ignored issues
show
Bug introduced by
The method getId does only exist in Bankiru\Api\Test\Entity\Sub\SubEntity, but not in Doctrine\Common\Proxy\Proxy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
86 1
        self::assertEquals('test-payload', $entity->getPayload());
0 ignored issues
show
Bug introduced by
The method getPayload does only exist in Bankiru\Api\Test\Entity\Sub\SubEntity, but not in Doctrine\Common\Proxy\Proxy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
87 1
        self::assertEquals('sub-payload', $entity->getSubPayload());
0 ignored issues
show
Bug introduced by
The method getSubPayload does only exist in Bankiru\Api\Test\Entity\Sub\SubEntity, but not in Doctrine\Common\Proxy\Proxy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
88 1
    }
89
90 2
    protected function getClientNames()
91
    {
92 2
        return [self::DEFAULT_CLIENT, 'test-reference-client'];
93
    }
94
}
95