Completed
Push — issue#666 ( 5bb037...827179 )
by Guilherme
04:30 queued 33s
created

RemoteClaimFetcherTest::testFetchByTagUri()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 20
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 28
rs 8.8571
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\Fetcher;
12
13
use Doctrine\ORM\EntityManagerInterface;
14
use LoginCidadao\OAuthBundle\Entity\ClientRepository;
15
use LoginCidadao\RemoteClaimsBundle\Entity\RemoteClaimRepository;
16
use LoginCidadao\RemoteClaimsBundle\Fetcher\RemoteClaimFetcher;
17
use LoginCidadao\RemoteClaimsBundle\Model\HttpUri;
18
use LoginCidadao\RemoteClaimsBundle\Tests\Http\HttpMocker;
19
use LoginCidadao\RemoteClaimsBundle\Tests\Parser\RemoteClaimParserTest;
20
21
class RemoteClaimFetcherTest extends \PHPUnit_Framework_TestCase
22
{
23
    /**
24
     * Test the Claim fetch using HTTP URI.
25
     */
26
    public function testFetchByHttpUri()
27
    {
28
        $uri = 'https://dummy.com';
29
30
        $data = RemoteClaimParserTest::$claimMetadata;
31
32
        $fetcher = $this->getFetcher(new HttpMocker($data));
33
        $remoteClaim = $fetcher->fetchRemoteClaim($uri);
34
35
        $this->assertInstanceOf('LoginCidadao\RemoteClaimsBundle\Model\RemoteClaimInterface', $remoteClaim);
36
        $this->assertEquals($data['claim_display_name'], $remoteClaim->getDisplayName());
37
    }
38
39
    /**
40
     * Test the Claim fetch using Tag URI.
41
     */
42
    public function testFetchByTagUri()
43
    {
44
        $uri = 'https://dummy.com';
45
46
        $data = RemoteClaimParserTest::$claimMetadata;
47
        $tagUri = $data['claim_name'];
48
49
        $httpMocker = new HttpMocker($data, $uri);
50
        $fetcher = $this->getFetcher($httpMocker);
51
        $remoteClaim = $fetcher->fetchRemoteClaim($tagUri);
52
53
        $requests = $httpMocker->getHistory()->getRequests();
54
        $firstRequest = reset($requests);
55
56
        $this->assertInstanceOf('LoginCidadao\RemoteClaimsBundle\Model\RemoteClaimInterface', $remoteClaim);
57
        $this->assertEquals($data['claim_display_name'], $remoteClaim->getDisplayName());
58
        $this->assertCount(2, $requests);
59
60
        $webFingerUrl = HttpUri::createFromString($firstRequest->getUrl());
61
        $this->assertEquals('https', $webFingerUrl->getScheme());
62
        $this->assertEquals('example.com', $webFingerUrl->getHost());
63
        $this->assertEquals('/.well-known/webfinger', $webFingerUrl->getPath());
64
65
        $webFingerParams = explode('&', $webFingerUrl->getQuery());
66
        $this->assertContains('rel=http%3A%2F%2Fopenid.net%2Fspecs%2Fconnect%2F1.0%2Fclaim', $webFingerParams);
67
        $encodedTag = urlencode($tagUri);
68
        $this->assertContains("resource={$encodedTag}", $webFingerParams);
69
    }
70
71
    public function testFetchNotFound()
72
    {
73
        $this->setExpectedException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException');
74
75
        $tagUri = 'tag:example.com,2018:my_claim';
76
        $fetcher = $this->getFetcher();
77
        $fetcher->fetchRemoteClaim($tagUri);
78
    }
79
80
    /**
81
     * This test assumes the Remote Claim is already known by the IdP.
82
     * The existing Remote Claim is expected to be returned.
83
     */
84
    public function testExistingClaim()
85
    {
86
        $claimUri = 'https://dummy.com';
87
88
        $provider = $this->getMock('LoginCidadao\RemoteClaimsBundle\Model\ClaimProviderInterface');
89
        $provider->expects($this->once())->method('getRedirectUris')->willReturn(['https://redirect.uri']);
90
91
        $existingClaim = $this->getMock('LoginCidadao\RemoteClaimsBundle\Model\RemoteClaimInterface');
92
        $existingClaim->expects($this->once())->method('getProvider')->willReturn($provider);
93
94
        $claimRepository = $this->getClaimRepository();
95
        $claimRepository->expects($this->once())->method('findOneBy')->willReturn($existingClaim);
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in LoginCidadao\RemoteClaim...y\RemoteClaimRepository.

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...
96
97
        $clientRepository = $this->getClientRepository();
98
        $clientRepository->expects($this->once())->method('findByRedirectUris')->willReturn([$provider]);
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in LoginCidadao\OAuthBundle\Entity\ClientRepository.

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...
99
100
        $em = $this->getEntityManager();
101
        $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...
102
103
        $fetcher = $this->getFetcher(null, $em, $claimRepository, $clientRepository);
0 ignored issues
show
Bug introduced by
It seems like $em defined by $this->getEntityManager() on line 100 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...tcherTest::getFetcher() does only seem to accept null|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 $claimRepository defined by $this->getClaimRepository() on line 94 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...tcherTest::getFetcher() does only seem to accept null|object<LoginCidadao...\RemoteClaimRepository>, 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 $clientRepository defined by $this->getClientRepository() on line 97 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...tcherTest::getFetcher() does only seem to accept null|object<LoginCidadao...ntity\ClientRepository>, 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...
104
        $actual = $fetcher->getRemoteClaim($claimUri);
105
106
        $this->assertEquals($existingClaim, $actual);
107
    }
108
109
    /**
110
     * This method tests a new Remote Claim, unknown by the IdP.
111
     * The Claim MUST be fetched and persisted.
112
     */
113
    public function testNewClaim()
114
    {
115
        $claimUri = 'https://dummy.com';
116
117
        $provider = $this->getMock('LoginCidadao\RemoteClaimsBundle\Model\ClaimProviderInterface');
118
119
        $existingClaim = null;
120
121
        $claimRepository = $this->getClaimRepository();
122
        $claimRepository->expects($this->once())->method('findOneBy')->willReturn($existingClaim);
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in LoginCidadao\RemoteClaim...y\RemoteClaimRepository.

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...
123
124
        $clientRepository = $this->getClientRepository();
125
        $clientRepository->expects($this->once())->method('findByRedirectUris')->willReturn([$provider]);
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in LoginCidadao\OAuthBundle\Entity\ClientRepository.

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...
126
127
        $em = $this->getEntityManager();
128
        $em->expects($this->once())->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...
129
            ->with($this->isInstanceOf('LoginCidadao\RemoteClaimsBundle\Model\RemoteClaimInterface'));
130
131
        $fetcher = $this->getFetcher(null, $em, $claimRepository, $clientRepository);
0 ignored issues
show
Bug introduced by
It seems like $em defined by $this->getEntityManager() on line 127 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...tcherTest::getFetcher() does only seem to accept null|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 $claimRepository defined by $this->getClaimRepository() on line 121 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...tcherTest::getFetcher() does only seem to accept null|object<LoginCidadao...\RemoteClaimRepository>, 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 $clientRepository defined by $this->getClientRepository() on line 124 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...tcherTest::getFetcher() does only seem to accept null|object<LoginCidadao...ntity\ClientRepository>, 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...
132
        $actual = $fetcher->getRemoteClaim($claimUri);
133
134
        $this->assertInstanceOf('LoginCidadao\RemoteClaimsBundle\Model\RemoteClaimInterface', $actual);
135
    }
136
137
    /**
138
     * Test that the method fails when the Claim Provider is not already persisted.
139
     */
140
    public function testNonExistentProvider()
141
    {
142
        $this->setExpectedException('LoginCidadao\RemoteClaimsBundle\Exception\ClaimProviderNotFoundException');
143
        $claimUri = 'https://dummy.com';
144
145
        $clientRepository = $this->getClientRepository();
146
        $clientRepository->expects($this->once())->method('findByRedirectUris')->willReturn(null);
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in LoginCidadao\OAuthBundle\Entity\ClientRepository.

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...
147
148
        $em = $this->getEntityManager();
149
        $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...
150
151
        $fetcher = $this->getFetcher(null, $em, null, $clientRepository);
0 ignored issues
show
Bug introduced by
It seems like $em defined by $this->getEntityManager() on line 148 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...tcherTest::getFetcher() does only seem to accept null|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 $clientRepository defined by $this->getClientRepository() on line 145 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...tcherTest::getFetcher() does only seem to accept null|object<LoginCidadao...ntity\ClientRepository>, 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...
152
        $fetcher->getRemoteClaim($claimUri);
153
    }
154
155
    /**
156
     * It should also fail when more than one Claim Provider is found.
157
     */
158
    public function testManyProviders()
159
    {
160
        $this->setExpectedException('\InvalidArgumentException');
161
        $claimUri = 'https://dummy.com';
162
163
        $provider1 = $this->getMock('LoginCidadao\RemoteClaimsBundle\Model\ClaimProviderInterface');
164
        $provider2 = $this->getMock('LoginCidadao\RemoteClaimsBundle\Model\ClaimProviderInterface');
165
166
        $clientRepository = $this->getClientRepository();
167
        $clientRepository->expects($this->once())->method('findByRedirectUris')->willReturn([$provider1, $provider2]);
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in LoginCidadao\OAuthBundle\Entity\ClientRepository.

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...
168
169
        $em = $this->getEntityManager();
170
        $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...
171
172
        $fetcher = $this->getFetcher(null, $em, null, $clientRepository);
0 ignored issues
show
Bug introduced by
It seems like $em defined by $this->getEntityManager() on line 169 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...tcherTest::getFetcher() does only seem to accept null|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 $clientRepository defined by $this->getClientRepository() on line 166 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, LoginCidadao\RemoteClaim...tcherTest::getFetcher() does only seem to accept null|object<LoginCidadao...ntity\ClientRepository>, 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...
173
        $fetcher->getRemoteClaim($claimUri);
174
    }
175
176
    /**
177
     * @param HttpMocker|null $httpMocker
178
     * @param EntityManagerInterface|null $em
179
     * @param RemoteClaimRepository|null $claimRepository
180
     * @param ClientRepository|null $clientRepository
181
     * @return RemoteClaimFetcher
182
     */
183
    private function getFetcher(
184
        HttpMocker $httpMocker = null,
185
        EntityManagerInterface $em = null,
186
        RemoteClaimRepository $claimRepository = null,
187
        ClientRepository $clientRepository = null
188
    ) {
189
        if ($httpMocker === null) {
190
            $httpMocker = new HttpMocker();
191
        }
192
        if ($em === null) {
193
            $em = $this->getEntityManager();
194
        }
195
        if ($claimRepository === null) {
196
            $claimRepository = $this->getClaimRepository();
197
        }
198
        if ($clientRepository === null) {
199
            $clientRepository = $this->getClientRepository();
200
        }
201
        $httpClient = $httpMocker->getClient();
202
203
        $fetcher = new RemoteClaimFetcher($httpClient, $em, $claimRepository, $clientRepository);
204
205
        return $fetcher;
206
    }
207
208
    /**
209
     * @return \PHPUnit_Framework_MockObject_MockObject|EntityManagerInterface
210
     */
211
    private function getEntityManager()
212
    {
213
        $em = $this->getMock('Doctrine\ORM\EntityManagerInterface');
214
215
        return $em;
216
    }
217
218
    /**
219
     * @return RemoteClaimRepository|\PHPUnit_Framework_MockObject_MockObject
220
     */
221
    private function getClaimRepository()
222
    {
223
        return $this->getMockBuilder('LoginCidadao\RemoteClaimsBundle\Entity\RemoteClaimRepository')
224
            ->disableOriginalConstructor()
225
            ->getMock();
226
    }
227
228
    /**
229
     * @return ClientRepository|\PHPUnit_Framework_MockObject_MockObject
230
     */
231
    private function getClientRepository()
232
    {
233
        $repo = $this->getMockBuilder('LoginCidadao\OAuthBundle\Entity\ClientRepository')
234
            ->disableOriginalConstructor()->getMock();
235
236
        return $repo;
237
    }
238
}
239