22
33namespace ZfModuleTest \Controller ;
44
5- use ZfModule \Controller \IndexController ;
6- use PHPUnit_Framework_TestCase ;
7- use ZfModule \Mapper \Module as ModuleMapper ;
8- use ZfModule \Service \Module as ModuleService ;
95use Application \Service \RepositoryRetriever ;
10- use ZfcUser \Controller \Plugin \ZfcUserAuthentication ;
11- use EdpGithub \Collection \RepositoryCollection ;
126use EdpGithub \Api ;
7+ use EdpGithub \Collection \RepositoryCollection ;
138use EdpGithub \Listener \Exception \RuntimeException as EdpGithubRuntimeException ;
9+ use PHPUnit_Framework_TestCase ;
1410use 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 ;
1515
1616class IndexControllerTest extends PHPUnit_Framework_TestCase
1717{
1818 /**
1919 * @var IndexController
2020 */
2121 protected $ controller ;
22-
22+
2323 /**
2424 * @var ModuleMapper
2525 */
2626 protected $ moduleMapper ;
27-
27+
2828 /**
2929 * @var ModuleService
3030 */
3131 protected $ moduleService ;
32-
32+
3333 /**
3434 * @var RepositoryRetriever
3535 */
3636 protected $ repositoryRetriever ;
37-
37+
3838 /**
3939 * @var ZfcUserAuthentication
4040 */
4141 protected $ zfcUserAuthentication ;
42-
42+
4343 public function setUp ()
4444 {
4545 $ this ->moduleMapper = $ this ->getMockBuilder ('ZfModule\Mapper\Module ' )
@@ -53,16 +53,16 @@ public function setUp()
5353 $ this ->repositoryRetriever = $ this ->getMockBuilder ('Application\Service\RepositoryRetriever ' )
5454 ->disableOriginalConstructor ()
5555 ->getMock ();
56-
56+
5757 $ this ->controller = new IndexController (
5858 $ this ->moduleMapper ,
5959 $ this ->moduleService ,
6060 $ this ->repositoryRetriever
6161 );
62-
62+
6363 $ this ->zfcUserAuthentication = $ this ->getMockBuilder ('ZfcUser\Controller\Plugin\ZfcUserAuthentication ' )
6464 ->getMock ();
65-
65+
6666 $ this ->controller ->getPluginManager ()->setService (
6767 'zfcUserAuthentication ' ,
6868 $ this ->zfcUserAuthentication
@@ -74,93 +74,93 @@ public function testIndexActionReturnsRepositoryListOnSuccessfulSync()
7474 $ this ->zfcUserAuthentication ->expects ($ this ->once ())
7575 ->method ('hasIdentity ' )
7676 ->will ($ this ->returnValue (true ));
77-
77+
7878 $ githubClient = $ this ->getClientMock (new Api \Repos (), [
7979 ['name ' => 'foo ' , 'fork ' => false , 'permissions ' => ['push ' => true ]]
8080 ]);
8181 $ githubResponse = new RepositoryCollection ($ githubClient ->getHttpClient (), '' );
82-
82+
8383 $ this ->repositoryRetriever ->expects ($ this ->once ())
8484 ->method ('getAuthenticatedUserRepositories ' )
8585 ->will ($ this ->returnValue ($ githubResponse ));
86-
86+
8787 $ this ->moduleService ->expects ($ this ->once ())
8888 ->method ('isModule ' )
8989 ->will ($ this ->returnValue (true ));
90-
90+
9191 $ viewModel = $ this ->controller ->indexAction ();
9292 $ this ->assertInstanceOf ('Zend\View\Model\ModelInterface ' , $ viewModel );
9393 $ this ->assertEmpty ($ viewModel ->errorMessage );
9494 $ this ->assertNotEmpty ($ viewModel ->repositories );
9595 }
96-
96+
9797 public function testIndexActionReturnsErrorMessageWhenRepositoryRetrieverThrowsEdpGithubRuntimeException ()
9898 {
9999 $ this ->zfcUserAuthentication ->expects ($ this ->once ())
100100 ->method ('hasIdentity ' )
101101 ->will ($ this ->returnValue (true ));
102102
103103 $ exception = new EdpGithubRuntimeException ('EdpGithub throws this exception ' );
104-
104+
105105 $ this ->repositoryRetriever ->expects ($ this ->once ())
106106 ->method ('getAuthenticatedUserRepositories ' )
107107 ->will ($ this ->throwException ($ exception ));
108-
108+
109109 $ viewModel = $ this ->controller ->indexAction ();
110110 $ this ->assertInstanceOf ('Zend\View\Model\ModelInterface ' , $ viewModel );
111111 $ this ->assertEquals ($ exception ->getMessage (), $ viewModel ->errorMessage );
112112 $ this ->assertEmpty ($ viewModel ->repositories );
113113 }
114-
114+
115115 public function testOrganizationActionReturnsRepositoryListOnSuccessfulSync ()
116116 {
117117 $ this ->zfcUserAuthentication ->expects ($ this ->once ())
118118 ->method ('hasIdentity ' )
119119 ->will ($ this ->returnValue (true ));
120-
120+
121121 $ routeMatch = new RouteMatch (['owner ' => 'zendframework ' ]);
122122 $ this ->controller ->getEvent ()->setRouteMatch ($ routeMatch );
123-
123+
124124 $ githubClient = $ this ->getClientMock (new Api \Repos (), [
125125 ['name ' => 'foo ' , 'fork ' => false , 'permissions ' => ['push ' => true ]]
126126 ]);
127127 $ githubResponse = new RepositoryCollection ($ githubClient ->getHttpClient (), '' );
128-
128+
129129 $ this ->repositoryRetriever ->expects ($ this ->once ())
130130 ->method ('getUserRepositories ' )
131131 ->will ($ this ->returnValue ($ githubResponse ));
132-
132+
133133 $ this ->moduleService ->expects ($ this ->once ())
134134 ->method ('isModule ' )
135135 ->will ($ this ->returnValue (true ));
136-
136+
137137 $ viewModel = $ this ->controller ->organizationAction ();
138138 $ this ->assertInstanceOf ('Zend\View\Model\ModelInterface ' , $ viewModel );
139139 $ this ->assertEmpty ($ viewModel ->errorMessage );
140140 $ this ->assertNotEmpty ($ viewModel ->repositories );
141141 }
142-
142+
143143 public function testOrganizationActionReturnsErrorMessageWhenRepositoryRetrieverThrowsEdpGithubRuntimeException ()
144144 {
145145 $ this ->zfcUserAuthentication ->expects ($ this ->once ())
146146 ->method ('hasIdentity ' )
147147 ->will ($ this ->returnValue (true ));
148-
148+
149149 $ routeMatch = new RouteMatch (['owner ' => 'zendframework ' ]);
150150 $ this ->controller ->getEvent ()->setRouteMatch ($ routeMatch );
151-
151+
152152 $ exception = new EdpGithubRuntimeException ('EdpGithub throws this exception ' );
153-
153+
154154 $ this ->repositoryRetriever ->expects ($ this ->once ())
155155 ->method ('getUserRepositories ' )
156156 ->will ($ this ->throwException ($ exception ));
157-
157+
158158 $ viewModel = $ this ->controller ->organizationAction ();
159159 $ this ->assertInstanceOf ('Zend\View\Model\ModelInterface ' , $ viewModel );
160160 $ this ->assertEquals ($ exception ->getMessage (), $ viewModel ->errorMessage );
161161 $ this ->assertEmpty ($ viewModel ->repositories );
162162 }
163-
163+
164164 /**
165165 * @param Api\AbstractApi $apiInstance
166166 * @param array $payload
0 commit comments