|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace OAuth\Unit\UserData; |
|
4
|
|
|
|
|
5
|
|
|
use OAuth\UserData\ExtractorFactory; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-02-07 at 21:13:15. |
|
9
|
|
|
*/ |
|
10
|
|
|
class ExtractorFactoryTest extends \PHPUnit_Framework_TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var ExtractorFactory |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $factory; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Sets up the fixture, for example, opens a network connection. |
|
19
|
|
|
* This method is called before a test is executed. |
|
20
|
|
|
*/ |
|
21
|
|
|
protected function setUp() |
|
22
|
|
|
{ |
|
23
|
|
|
$this->factory = new ExtractorFactory(); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Tears down the fixture, for example, closes a network connection. |
|
28
|
|
|
* This method is called after a test is executed. |
|
29
|
|
|
*/ |
|
30
|
|
|
protected function tearDown() |
|
31
|
|
|
{ |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @covers \OAuth\UserData\ExtractorFactory |
|
36
|
|
|
*/ |
|
37
|
|
|
public function testImplementsExtractorFactoryInterface() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->assertInstanceOf('\\OAuth\\UserData\\ExtractorFactoryInterface', $this->factory); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @covers \OAuth\UserData\ExtractorFactory |
|
44
|
|
|
*/ |
|
45
|
|
|
public function testGetMappedExtractor() |
|
46
|
|
|
{ |
|
47
|
|
|
/** |
|
48
|
|
|
* @var \Oauth\Common\Service\ServiceInterface $service |
|
49
|
|
|
*/ |
|
50
|
|
|
$service = $this->getMock('\\OAuth\\Common\\Service\\ServiceInterface', array(), array(), 'FakeService'); |
|
51
|
|
|
$this->factory->addExtractorMapping('FakeService', '\\OAuth\\UserData\\Extractor\\Facebook'); |
|
52
|
|
|
$extractor = $this->factory->get($service); |
|
53
|
|
|
$this->assertInstanceOf('\\OAuth\\UserData\\Extractor\\Facebook', $extractor); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @covers \OAuth\UserData\ExtractorFactory |
|
58
|
|
|
*/ |
|
59
|
|
|
public function testGetUnmappedExtractor() |
|
60
|
|
|
{ |
|
61
|
|
|
/** |
|
62
|
|
|
* @var \Oauth\Common\Service\ServiceInterface $service |
|
63
|
|
|
*/ |
|
64
|
|
|
$service = $this->getMock('\\OAuth\\OAuth2\\Service\\Facebook', array(), array(), 'Facebook', false); |
|
65
|
|
|
$extractor = $this->factory->get($service); |
|
66
|
|
|
$this->assertInstanceOf('\\OAuth\\UserData\\Extractor\\Facebook', $extractor); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @covers \OAuth\UserData\ExtractorFactory |
|
71
|
|
|
* @expectedException \OAuth\UserData\Exception\UndefinedExtractorException |
|
72
|
|
|
* @expectedExceptionMessage Cannot find an extractor for the service "FakeService". Registered extractors: [] |
|
73
|
|
|
*/ |
|
74
|
|
|
public function testGetThrowsUnmatchedExtractorException() |
|
75
|
|
|
{ |
|
76
|
|
|
/** |
|
77
|
|
|
* @var \Oauth\Common\Service\ServiceInterface $service |
|
78
|
|
|
*/ |
|
79
|
|
|
$service = $this->getMock('\\OAuth\\Common\\Service\\ServiceInterface', array(), array(), 'FakeService'); |
|
80
|
|
|
$this->factory->get($service); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @covers \OAuth\UserData\ExtractorFactory |
|
85
|
|
|
* @expectedException \OAuth\UserData\Exception\InvalidExtractorException |
|
86
|
|
|
* @expectedExceptionMessage The class "stdClass" does not implement the interface OAuth\UserData\Extractor\ExtractorInterface |
|
87
|
|
|
*/ |
|
88
|
|
|
public function testGetThrowsInvalidExtractorException() |
|
89
|
|
|
{ |
|
90
|
|
|
/** |
|
91
|
|
|
* @var \Oauth\Common\Service\ServiceInterface $service |
|
92
|
|
|
*/ |
|
93
|
|
|
$service = $this->getMock('\\OAuth\\Common\\Service\\ServiceInterface', array(), array(), 'FakeService'); |
|
94
|
|
|
$this->factory->addExtractorMapping('FakeService', 'stdClass'); |
|
95
|
|
|
$this->factory->get($service); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|