Completed
Push — issue#666 ( 0f58f5...3afa36 )
by Guilherme
03:38
created

RemoteClaimFetcherTest::testExistingClaim()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 15
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 24
rs 8.9713
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\Tests\Http\HttpMocker;
18
use LoginCidadao\RemoteClaimsBundle\Tests\Parser\RemoteClaimParserTest;
19
20
class RemoteClaimFetcherTest extends \PHPUnit_Framework_TestCase
21
{
22
    /**
23
     * Test the Claim fetch using HTTP URI.
24
     */
25
    public function testFetchByHttpUri()
26
    {
27
        $uri = 'https://dummy.com';
28
29
        $data = RemoteClaimParserTest::$claimMetadata;
30
31
        $fetcher = $this->getFetcher(new HttpMocker($data));
32
        $remoteClaim = $fetcher->fetchRemoteClaim($uri);
33
34
        $this->assertInstanceOf('LoginCidadao\RemoteClaimsBundle\Model\RemoteClaimInterface', $remoteClaim);
35
        $this->assertEquals($data['claim_display_name'], $remoteClaim->getDisplayName());
36
    }
37
38
    /**
39
     * Test the Claim fetch using Tag URI.
40
     */
41
    public function testFetchByTagUri()
42
    {
43
        $uri = 'https://dummy.com';
44
45
        $data = RemoteClaimParserTest::$claimMetadata;
46
        $tagUri = $data['claim_name'];
47
48
        $httpMocker = new HttpMocker($data, $uri);
49
        $fetcher = $this->getFetcher($httpMocker);
50
        $remoteClaim = $fetcher->fetchRemoteClaim($tagUri);
51
52
        $requests = $httpMocker->getHistory()->getRequests();
53
        $firstRequest = reset($requests);
54
55
        $this->assertInstanceOf('LoginCidadao\RemoteClaimsBundle\Model\RemoteClaimInterface', $remoteClaim);
56
        $this->assertEquals($data['claim_display_name'], $remoteClaim->getDisplayName());
57
        $this->assertCount(2, $requests);
58
        $this->assertEquals('https://example.com?rel=http%3A%2F%2Fopenid.net%2Fspecs%2Fconnect%2F1.0%2Fclaim',
59
            $firstRequest->getUrl());
60
    }
61
62
    public function testFetchNotFound()
63
    {
64
        $this->setExpectedException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException');
65
66
        $tagUri = 'tag:example.com,2018:my_claim';
67
        $fetcher = $this->getFetcher();
68
        $fetcher->fetchRemoteClaim($tagUri);
69
    }
70
71
    /**
72
     * This test assumes the Remote Claim is already known by the IdP.
73
     * The existing Remote Claim is expected to be returned.
74
     */
75
    public function testExistingClaim()
76
    {
77
        $claimUri = 'https://dummy.com';
78
79
        $provider = $this->getMock('LoginCidadao\RemoteClaimsBundle\Model\ClaimProviderInterface');
80
        $provider->expects($this->once())->method('getRedirectUris')->willReturn(['https://redirect.uri']);
81
82
        $existingClaim = $this->getMock('LoginCidadao\RemoteClaimsBundle\Model\RemoteClaimInterface');
83
        $existingClaim->expects($this->once())->method('getProvider')->willReturn($provider);
84
85
        $claimRepository = $this->getClaimRepository();
86
        $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...
87
88
        $clientRepository = $this->getClientRepository();
89
        $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...
90
91
        $em = $this->getEntityManager();
92
        $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...
93
94
        $fetcher = $this->getFetcher(null, $em, $claimRepository, $clientRepository);
0 ignored issues
show
Bug introduced by
It seems like $em defined by $this->getEntityManager() on line 91 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 85 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 88 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...
95
        $actual = $fetcher->getRemoteClaim($claimUri);
96
97
        $this->assertEquals($existingClaim, $actual);
98
    }
99
100
    /**
101
     * This method tests a new Remote Claim, unknown by the IdP.
102
     * The Claim MUST be fetched and persisted.
103
     */
104
    public function testNewClaim()
105
    {
106
        $claimUri = 'https://dummy.com';
107
108
        $provider = $this->getMock('LoginCidadao\RemoteClaimsBundle\Model\ClaimProviderInterface');
109
110
        $existingClaim = null;
111
112
        $claimRepository = $this->getClaimRepository();
113
        $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...
114
115
        $clientRepository = $this->getClientRepository();
116
        $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...
117
118
        $em = $this->getEntityManager();
119
        $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...
120
            ->with($this->isInstanceOf('LoginCidadao\RemoteClaimsBundle\Model\RemoteClaimInterface'));
121
122
        $fetcher = $this->getFetcher(null, $em, $claimRepository, $clientRepository);
0 ignored issues
show
Bug introduced by
It seems like $em defined by $this->getEntityManager() on line 118 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 112 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 115 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...
123
        $actual = $fetcher->getRemoteClaim($claimUri);
124
125
        $this->assertInstanceOf('LoginCidadao\RemoteClaimsBundle\Model\RemoteClaimInterface', $actual);
126
    }
127
128
    /**
129
     * Test that the method fails when the Claim Provider is not already persisted.
130
     */
131
    public function testNonExistentProvider()
132
    {
133
        $this->setExpectedException('LoginCidadao\RemoteClaimsBundle\Exception\ClaimProviderNotFoundException');
134
        $claimUri = 'https://dummy.com';
135
136
        $clientRepository = $this->getClientRepository();
137
        $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...
138
139
        $em = $this->getEntityManager();
140
        $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...
141
142
        $fetcher = $this->getFetcher(null, $em, null, $clientRepository);
0 ignored issues
show
Bug introduced by
It seems like $em defined by $this->getEntityManager() on line 139 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 136 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...
143
        $fetcher->getRemoteClaim($claimUri);
144
    }
145
146
    /**
147
     * It should also fail when more than one Claim Provider is found.
148
     */
149
    public function testManyProviders()
150
    {
151
        $this->setExpectedException('\InvalidArgumentException');
152
        $claimUri = 'https://dummy.com';
153
154
        $provider1 = $this->getMock('LoginCidadao\RemoteClaimsBundle\Model\ClaimProviderInterface');
155
        $provider2 = $this->getMock('LoginCidadao\RemoteClaimsBundle\Model\ClaimProviderInterface');
156
157
        $clientRepository = $this->getClientRepository();
158
        $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...
159
160
        $em = $this->getEntityManager();
161
        $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...
162
163
        $fetcher = $this->getFetcher(null, $em, null, $clientRepository);
0 ignored issues
show
Bug introduced by
It seems like $em defined by $this->getEntityManager() on line 160 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 157 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...
164
        $fetcher->getRemoteClaim($claimUri);
165
    }
166
167
    /**
168
     * @param HttpMocker|null $httpMocker
169
     * @param EntityManagerInterface|null $em
170
     * @param RemoteClaimRepository|null $claimRepository
171
     * @param ClientRepository|null $clientRepository
172
     * @return RemoteClaimFetcher
173
     */
174
    private function getFetcher(
175
        HttpMocker $httpMocker = null,
176
        EntityManagerInterface $em = null,
177
        RemoteClaimRepository $claimRepository = null,
178
        ClientRepository $clientRepository = null
179
    ) {
180
        if ($httpMocker === null) {
181
            $httpMocker = new HttpMocker();
182
        }
183
        if ($em === null) {
184
            $em = $this->getEntityManager();
185
        }
186
        if ($claimRepository === null) {
187
            $claimRepository = $this->getClaimRepository();
188
        }
189
        if ($clientRepository === null) {
190
            $clientRepository = $this->getClientRepository();
191
        }
192
        $httpClient = $httpMocker->getClient();
193
194
        $fetcher = new RemoteClaimFetcher($httpClient, $em, $claimRepository, $clientRepository);
195
196
        return $fetcher;
197
    }
198
199
    /**
200
     * @return \PHPUnit_Framework_MockObject_MockObject|EntityManagerInterface
201
     */
202
    private function getEntityManager()
203
    {
204
        $em = $this->getMock('Doctrine\ORM\EntityManagerInterface');
205
206
        return $em;
207
    }
208
209
    /**
210
     * @return RemoteClaimRepository|\PHPUnit_Framework_MockObject_MockObject
211
     */
212
    private function getClaimRepository()
213
    {
214
        return $this->getMockBuilder('LoginCidadao\RemoteClaimsBundle\Entity\RemoteClaimRepository')
215
            ->disableOriginalConstructor()
216
            ->getMock();
217
    }
218
219
    /**
220
     * @return ClientRepository|\PHPUnit_Framework_MockObject_MockObject
221
     */
222
    private function getClientRepository()
223
    {
224
        $repo = $this->getMockBuilder('LoginCidadao\OAuthBundle\Entity\ClientRepository')
225
            ->disableOriginalConstructor()->getMock();
226
227
        return $repo;
228
    }
229
}
230