Completed
Push — issue#666 ( 928a8e...2654e9 )
by Guilherme
04:24
created

RemoteClaimManagerTest::getRepo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the login-cidadao project or it's bundles.
4
 *
5
 * (c) Guilherme Donato <guilhermednt on github>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LoginCidadao\RemoteClaimsBundle\Tests\Model;
12
13
use Doctrine\ORM\EntityManagerInterface;
14
use LoginCidadao\CoreBundle\Entity\Authorization;
15
use LoginCidadao\OAuthBundle\Model\ClientInterface;
16
use LoginCidadao\RemoteClaimsBundle\Entity\RemoteClaimAuthorizationRepository;
17
use LoginCidadao\RemoteClaimsBundle\Model\RemoteClaimAuthorizationInterface;
18
use LoginCidadao\RemoteClaimsBundle\Model\RemoteClaimManager;
19
use LoginCidadao\CoreBundle\Model\PersonInterface;
20
use LoginCidadao\RemoteClaimsBundle\Model\TagUri;
21
22
class RemoteClaimManagerTest extends \PHPUnit_Framework_TestCase
23
{
24
    public function testEnforceNewAuthorization()
25
    {
26
        $authorization = $this->getRemoteClaimAuthorization();
27
28
        $em = $this->getEntityManager();
29
        $em->expects($this->once())->method('persist')->with($authorization);
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\EntityManagerInterface.

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...
30
31
        $repo = $this->getRepo();
32
        $repo->expects($this->once())->method('findAuthorization')->willReturn(null);
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in LoginCidadao\RemoteClaim...AuthorizationRepository.

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...
33
34
        $manager = new RemoteClaimManager($em, $repo);
0 ignored issues
show
Bug introduced by
It seems like $em defined by $this->getEntityManager() on line 28 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<Doctrine\ORM\EntityManagerInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $repo defined by $this->getRepo() on line 31 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...uthorizationRepository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
35
        $this->assertSame($authorization, $manager->enforceAuthorization($authorization));
0 ignored issues
show
Bug introduced by
It seems like $authorization defined by $this->getRemoteClaimAuthorization() on line 26 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...:enforceAuthorization() does only seem to accept object<LoginCidadao\Remo...AuthorizationInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
36
    }
37
38
    public function testEnforceExistingAuthorization()
39
    {
40
        $authorization = $this->getRemoteClaimAuthorization();
41
        $existingAuthorization = $this->getRemoteClaimAuthorization();
42
43
        $em = $this->getEntityManager();
44
        $em->expects($this->never())->method('persist');
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\EntityManagerInterface.

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...
45
46
        $repo = $this->getRepo();
47
        $repo->expects($this->once())->method('findAuthorization')->willReturn($existingAuthorization);
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in LoginCidadao\RemoteClaim...AuthorizationRepository.

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...
48
49
        $manager = new RemoteClaimManager($em, $repo);
0 ignored issues
show
Bug introduced by
It seems like $em defined by $this->getEntityManager() on line 43 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<Doctrine\ORM\EntityManagerInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $repo defined by $this->getRepo() on line 46 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...uthorizationRepository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
50
        $this->assertSame($existingAuthorization, $manager->enforceAuthorization($authorization));
0 ignored issues
show
Bug introduced by
It seems like $authorization defined by $this->getRemoteClaimAuthorization() on line 40 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...:enforceAuthorization() does only seem to accept object<LoginCidadao\Remo...AuthorizationInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
51
    }
52
53
    public function testIsAuthorizedClaimNameString()
54
    {
55
        $claimName = 'tag:example.com,2017:my_claim';
56
        $person = $this->getPerson();
57
        $client = $this->getClient();
58
        $authorization = $this->getRemoteClaimAuthorization();
59
60
        $repo = $this->getRepo();
61
        $repo->expects($this->once())->method('findAuthorization')->willReturn($authorization);
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in LoginCidadao\RemoteClaim...AuthorizationRepository.

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...
62
63
        $manager = new RemoteClaimManager($this->getEntityManager(), $repo);
0 ignored issues
show
Bug introduced by
It seems like $this->getEntityManager() targeting LoginCidadao\RemoteClaim...est::getEntityManager() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<Doctrine\ORM\EntityManagerInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $repo defined by $this->getRepo() on line 60 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...uthorizationRepository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
64
65
        $this->assertTrue($manager->isAuthorized($claimName, $person, $client));
0 ignored issues
show
Bug introduced by
It seems like $person defined by $this->getPerson() on line 56 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...Manager::isAuthorized() does only seem to accept object<LoginCidadao\Core...\Model\PersonInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $client defined by $this->getClient() on line 57 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...Manager::isAuthorized() does only seem to accept object<LoginCidadao\OAut...\Model\ClientInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
66
    }
67
68
    public function testIsAuthorizedTagUri()
69
    {
70
        $claimName = new TagUri();
71
        $person = $this->getPerson();
72
        $client = $this->getClient();
73
        $authorization = $this->getRemoteClaimAuthorization();
74
75
        $repo = $this->getRepo();
76
        $repo->expects($this->once())->method('findAuthorization')->willReturn($authorization);
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in LoginCidadao\RemoteClaim...AuthorizationRepository.

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...
77
78
        $manager = new RemoteClaimManager($this->getEntityManager(), $repo);
0 ignored issues
show
Bug introduced by
It seems like $this->getEntityManager() targeting LoginCidadao\RemoteClaim...est::getEntityManager() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<Doctrine\ORM\EntityManagerInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $repo defined by $this->getRepo() on line 75 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...uthorizationRepository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
79
80
        $this->assertTrue($manager->isAuthorized($claimName, $person, $client));
0 ignored issues
show
Bug introduced by
It seems like $person defined by $this->getPerson() on line 71 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...Manager::isAuthorized() does only seem to accept object<LoginCidadao\Core...\Model\PersonInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $client defined by $this->getClient() on line 72 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...Manager::isAuthorized() does only seem to accept object<LoginCidadao\OAut...\Model\ClientInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
81
    }
82
83
    public function testIsNotAuthorizedTagUri()
84
    {
85
        $claimName = new TagUri();
86
        $person = $this->getPerson();
87
        $client = $this->getClient();
88
89
        $repo = $this->getRepo();
90
        $repo->expects($this->once())->method('findAuthorization')->willReturn(null);
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in LoginCidadao\RemoteClaim...AuthorizationRepository.

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...
91
92
        $manager = new RemoteClaimManager($this->getEntityManager(), $repo);
0 ignored issues
show
Bug introduced by
It seems like $this->getEntityManager() targeting LoginCidadao\RemoteClaim...est::getEntityManager() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<Doctrine\ORM\EntityManagerInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $repo defined by $this->getRepo() on line 89 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...uthorizationRepository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
93
94
        $this->assertFalse($manager->isAuthorized($claimName, $person, $client));
0 ignored issues
show
Bug introduced by
It seems like $person defined by $this->getPerson() on line 86 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...Manager::isAuthorized() does only seem to accept object<LoginCidadao\Core...\Model\PersonInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $client defined by $this->getClient() on line 87 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...Manager::isAuthorized() does only seem to accept object<LoginCidadao\OAut...\Model\ClientInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
95
    }
96
97
    public function testRevokeAllAuthorizations()
98
    {
99
        $remoteClaimAuthorizations = [
100
            $this->getRemoteClaimAuthorization(),
101
            $this->getRemoteClaimAuthorization(),
102
        ];
103
104
        $authorization = $this->getAuthorization();
105
        $authorization->expects($this->once())->method('getPerson')->willReturn($this->getPerson());
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in LoginCidadao\CoreBundle\Entity\Authorization.

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...
106
        $authorization->expects($this->once())->method('getClient')->willReturn($this->getClient());
107
108
        $em = $this->getEntityManager();
109
        $em->expects($this->exactly(count($remoteClaimAuthorizations)))->method('remove')
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Doctrine\ORM\EntityManagerInterface.

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...
110
            ->with($this->isInstanceOf('LoginCidadao\RemoteClaimsBundle\Model\RemoteClaimAuthorizationInterface'));
111
112
        $repo = $this->getRepo();
113
        $repo->expects($this->once())->method('findAllByClientAndPerson')->willReturn($remoteClaimAuthorizations);
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in LoginCidadao\RemoteClaim...AuthorizationRepository.

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...
114
115
        $manager = new RemoteClaimManager($em, $repo);
0 ignored issues
show
Bug introduced by
It seems like $em defined by $this->getEntityManager() on line 108 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<Doctrine\ORM\EntityManagerInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $repo defined by $this->getRepo() on line 112 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...mManager::__construct() does only seem to accept object<LoginCidadao\Remo...uthorizationRepository>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
116
        $manager->revokeAllAuthorizations($authorization);
0 ignored issues
show
Bug introduced by
It seems like $authorization defined by $this->getAuthorization() on line 104 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...vokeAllAuthorizations() does only seem to accept object<LoginCidadao\Core...e\Entity\Authorization>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
117
    }
118
119
    /**
120
     * @return \PHPUnit_Framework_MockObject_MockObject|EntityManagerInterface
121
     */
122
    public function getEntityManager()
123
    {
124
        return $this->getMock('Doctrine\ORM\EntityManagerInterface');
125
    }
126
127
    /**
128
     * @return \PHPUnit_Framework_MockObject_MockObject|RemoteClaimAuthorizationRepository
129
     */
130
    public function getRepo()
131
    {
132
        return $this->getMockBuilder('LoginCidadao\RemoteClaimsBundle\Entity\RemoteClaimAuthorizationRepository')
133
            ->disableOriginalConstructor()->getMock();
134
    }
135
136
    /**
137
     * @return \PHPUnit_Framework_MockObject_MockObject|RemoteClaimAuthorizationInterface
138
     */
139
    public function getRemoteClaimAuthorization()
140
    {
141
        return $this->getMock('LoginCidadao\RemoteClaimsBundle\Model\RemoteClaimAuthorizationInterface');
142
    }
143
144
    /**
145
     * @return \PHPUnit_Framework_MockObject_MockObject|PersonInterface
146
     */
147
    public function getPerson()
148
    {
149
        return $this->getMock('LoginCidadao\CoreBundle\Model\PersonInterface');
150
    }
151
152
    /**
153
     * @return \PHPUnit_Framework_MockObject_MockObject|ClientInterface
154
     */
155
    public function getClient()
156
    {
157
        return $this->getMock('LoginCidadao\OAuthBundle\Model\ClientInterface');
158
    }
159
160
    /**
161
     * @return \PHPUnit_Framework_MockObject_MockObject|Authorization
162
     */
163
    public function getAuthorization()
164
    {
165
        return $this->getMock('LoginCidadao\CoreBundle\Entity\Authorization');
166
    }
167
}
168