2
2
3
3
namespace ZfModuleTest \Controller ;
4
4
5
- use ZfModule \Controller \IndexController ;
6
- use PHPUnit_Framework_TestCase ;
7
- use ZfModule \Mapper \Module as ModuleMapper ;
8
- use ZfModule \Service \Module as ModuleService ;
9
5
use Application \Service \RepositoryRetriever ;
10
- use ZfcUser \Controller \Plugin \ZfcUserAuthentication ;
11
- use EdpGithub \Collection \RepositoryCollection ;
12
6
use EdpGithub \Api ;
7
+ use EdpGithub \Collection \RepositoryCollection ;
13
8
use EdpGithub \Listener \Exception \RuntimeException as EdpGithubRuntimeException ;
9
+ use PHPUnit_Framework_TestCase ;
14
10
use Zend \Mvc \Router \RouteMatch ;
11
+ use ZfcUser \Controller \Plugin \ZfcUserAuthentication ;
12
+ use ZfModule \Controller \IndexController ;
13
+ use ZfModule \Mapper \Module as ModuleMapper ;
14
+ use ZfModule \Service \Module as ModuleService ;
15
15
16
16
class IndexControllerTest extends PHPUnit_Framework_TestCase
17
17
{
18
18
/**
19
19
* @var IndexController
20
20
*/
21
21
protected $ controller ;
22
-
22
+
23
23
/**
24
24
* @var ModuleMapper
25
25
*/
26
26
protected $ moduleMapper ;
27
-
27
+
28
28
/**
29
29
* @var ModuleService
30
30
*/
31
31
protected $ moduleService ;
32
-
32
+
33
33
/**
34
34
* @var RepositoryRetriever
35
35
*/
36
36
protected $ repositoryRetriever ;
37
-
37
+
38
38
/**
39
39
* @var ZfcUserAuthentication
40
40
*/
41
41
protected $ zfcUserAuthentication ;
42
-
42
+
43
43
public function setUp ()
44
44
{
45
45
$ this ->moduleMapper = $ this ->getMockBuilder ('ZfModule\Mapper\Module ' )
@@ -53,16 +53,16 @@ public function setUp()
53
53
$ this ->repositoryRetriever = $ this ->getMockBuilder ('Application\Service\RepositoryRetriever ' )
54
54
->disableOriginalConstructor ()
55
55
->getMock ();
56
-
56
+
57
57
$ this ->controller = new IndexController (
58
58
$ this ->moduleMapper ,
59
59
$ this ->moduleService ,
60
60
$ this ->repositoryRetriever
61
61
);
62
-
62
+
63
63
$ this ->zfcUserAuthentication = $ this ->getMockBuilder ('ZfcUser\Controller\Plugin\ZfcUserAuthentication ' )
64
64
->getMock ();
65
-
65
+
66
66
$ this ->controller ->getPluginManager ()->setService (
67
67
'zfcUserAuthentication ' ,
68
68
$ this ->zfcUserAuthentication
@@ -74,93 +74,93 @@ public function testIndexActionReturnsRepositoryListOnSuccessfulSync()
74
74
$ this ->zfcUserAuthentication ->expects ($ this ->once ())
75
75
->method ('hasIdentity ' )
76
76
->will ($ this ->returnValue (true ));
77
-
77
+
78
78
$ githubClient = $ this ->getClientMock (new Api \Repos (), [
79
79
['name ' => 'foo ' , 'fork ' => false , 'permissions ' => ['push ' => true ]]
80
80
]);
81
81
$ githubResponse = new RepositoryCollection ($ githubClient ->getHttpClient (), '' );
82
-
82
+
83
83
$ this ->repositoryRetriever ->expects ($ this ->once ())
84
84
->method ('getAuthenticatedUserRepositories ' )
85
85
->will ($ this ->returnValue ($ githubResponse ));
86
-
86
+
87
87
$ this ->moduleService ->expects ($ this ->once ())
88
88
->method ('isModule ' )
89
89
->will ($ this ->returnValue (true ));
90
-
90
+
91
91
$ viewModel = $ this ->controller ->indexAction ();
92
92
$ this ->assertInstanceOf ('Zend\View\Model\ModelInterface ' , $ viewModel );
93
93
$ this ->assertEmpty ($ viewModel ->errorMessage );
94
94
$ this ->assertNotEmpty ($ viewModel ->repositories );
95
95
}
96
-
96
+
97
97
public function testIndexActionReturnsErrorMessageWhenRepositoryRetrieverThrowsEdpGithubRuntimeException ()
98
98
{
99
99
$ this ->zfcUserAuthentication ->expects ($ this ->once ())
100
100
->method ('hasIdentity ' )
101
101
->will ($ this ->returnValue (true ));
102
102
103
103
$ exception = new EdpGithubRuntimeException ('EdpGithub throws this exception ' );
104
-
104
+
105
105
$ this ->repositoryRetriever ->expects ($ this ->once ())
106
106
->method ('getAuthenticatedUserRepositories ' )
107
107
->will ($ this ->throwException ($ exception ));
108
-
108
+
109
109
$ viewModel = $ this ->controller ->indexAction ();
110
110
$ this ->assertInstanceOf ('Zend\View\Model\ModelInterface ' , $ viewModel );
111
111
$ this ->assertEquals ($ exception ->getMessage (), $ viewModel ->errorMessage );
112
112
$ this ->assertEmpty ($ viewModel ->repositories );
113
113
}
114
-
114
+
115
115
public function testOrganizationActionReturnsRepositoryListOnSuccessfulSync ()
116
116
{
117
117
$ this ->zfcUserAuthentication ->expects ($ this ->once ())
118
118
->method ('hasIdentity ' )
119
119
->will ($ this ->returnValue (true ));
120
-
120
+
121
121
$ routeMatch = new RouteMatch (['owner ' => 'zendframework ' ]);
122
122
$ this ->controller ->getEvent ()->setRouteMatch ($ routeMatch );
123
-
123
+
124
124
$ githubClient = $ this ->getClientMock (new Api \Repos (), [
125
125
['name ' => 'foo ' , 'fork ' => false , 'permissions ' => ['push ' => true ]]
126
126
]);
127
127
$ githubResponse = new RepositoryCollection ($ githubClient ->getHttpClient (), '' );
128
-
128
+
129
129
$ this ->repositoryRetriever ->expects ($ this ->once ())
130
130
->method ('getUserRepositories ' )
131
131
->will ($ this ->returnValue ($ githubResponse ));
132
-
132
+
133
133
$ this ->moduleService ->expects ($ this ->once ())
134
134
->method ('isModule ' )
135
135
->will ($ this ->returnValue (true ));
136
-
136
+
137
137
$ viewModel = $ this ->controller ->organizationAction ();
138
138
$ this ->assertInstanceOf ('Zend\View\Model\ModelInterface ' , $ viewModel );
139
139
$ this ->assertEmpty ($ viewModel ->errorMessage );
140
140
$ this ->assertNotEmpty ($ viewModel ->repositories );
141
141
}
142
-
142
+
143
143
public function testOrganizationActionReturnsErrorMessageWhenRepositoryRetrieverThrowsEdpGithubRuntimeException ()
144
144
{
145
145
$ this ->zfcUserAuthentication ->expects ($ this ->once ())
146
146
->method ('hasIdentity ' )
147
147
->will ($ this ->returnValue (true ));
148
-
148
+
149
149
$ routeMatch = new RouteMatch (['owner ' => 'zendframework ' ]);
150
150
$ this ->controller ->getEvent ()->setRouteMatch ($ routeMatch );
151
-
151
+
152
152
$ exception = new EdpGithubRuntimeException ('EdpGithub throws this exception ' );
153
-
153
+
154
154
$ this ->repositoryRetriever ->expects ($ this ->once ())
155
155
->method ('getUserRepositories ' )
156
156
->will ($ this ->throwException ($ exception ));
157
-
157
+
158
158
$ viewModel = $ this ->controller ->organizationAction ();
159
159
$ this ->assertInstanceOf ('Zend\View\Model\ModelInterface ' , $ viewModel );
160
160
$ this ->assertEquals ($ exception ->getMessage (), $ viewModel ->errorMessage );
161
161
$ this ->assertEmpty ($ viewModel ->repositories );
162
162
}
163
-
163
+
164
164
/**
165
165
* @param Api\AbstractApi $apiInstance
166
166
* @param array $payload
0 commit comments