99
1010class MarketServiceTest extends TestCase {
1111
12+ /** @var MarketService */
1213 private $ marketService ;
14+ /** @var boolean */
1315 private $ hasInternetConnection ;
16+ /** @var IAppManager | PHPUnit_Framework_MockObject_MockObject */
17+ private $ appManager ;
1418
1519 public function setUp (){
1620 $ this ->hasInternetConnection = true ;
17- $ appManagerMock = $ this ->getMockBuilder (IAppManager::class)->getMock ();
18- $ appManagerMock ->method ('getAllApps ' )->will ($ this ->returnValue ([]));
19-
21+ $ this ->appManager = $ this ->createMock (IAppManager::class);
22+ $ this ->appManager ->method ('getAllApps ' )->willReturn ([]);
23+
24+ /** @var IConfig | PHPUnit_Framework_MockObject_MockObject $configMock */
2025 $ configMock = $ this ->getConfigMock ();
21- $ cacheFactoryMock = $ this ->getMockBuilder (ICacheFactory::class)->getMock ();
22- $ l10nMock = $ this ->getMockBuilder (IL10N ::class)->getMock ();
26+ /** @var ICacheFactory | PHPUnit_Framework_MockObject_MockObject $cacheFactoryMock */
27+ $ cacheFactoryMock = $ this ->createMock (ICacheFactory::class);
28+ /** @var IL10N | PHPUnit_Framework_MockObject_MockObject $l10nMock */
29+ $ l10nMock = $ this ->createMock (IL10N ::class);
2330 $ this ->marketService = new MarketService (
24- $ appManagerMock ,
31+ $ this -> appManager ,
2532 $ configMock ,
2633 $ cacheFactoryMock ,
2734 $ l10nMock
@@ -33,6 +40,7 @@ public function setUp(){
3340 */
3441 public function testInstallWithInternetConnectionDisabled (){
3542 $ this ->hasInternetConnection = false ;
43+ $ this ->appManager ->method ('canInstall ' )->willReturn (true );
3644 $ this ->marketService ->installApp ('fubar ' );
3745 }
3846
@@ -41,8 +49,28 @@ public function testInstallWithInternetConnectionDisabled(){
4149 */
4250 public function testUpdateWithInternetConnectionDisabled (){
4351 $ this ->hasInternetConnection = false ;
52+ $ this ->appManager ->method ('canInstall ' )->willReturn (true );
4453 $ this ->marketService ->updateApp ('files ' );
4554 }
55+
56+ /**
57+ * @dataProvider providesMarketMethods
58+ * @expectedException \Exception
59+ * @expectedExceptionMessage Installing apps is not supported because the app folder is not writable.
60+ */
61+ public function testInstallNotPossible ($ method ) {
62+ $ this ->appManager ->method ('canInstall ' )->willReturn (false );
63+
64+ $ this ->marketService ->$ method ('test ' );
65+ }
66+
67+ public function providesMarketMethods () {
68+ return [
69+ ['installApp ' ],
70+ ['uninstallApp ' ],
71+ ['updateApp ' ]
72+ ];
73+ }
4674
4775 public function getSystemValue ($ configKey , $ default = null ){
4876 if ($ configKey ==='has_internet_connection ' ){
@@ -52,30 +80,7 @@ public function getSystemValue($configKey, $default = null){
5280 }
5381
5482 private function getConfigMock (){
55- $ config = $ this ->getMockBuilder (IConfig::class)
56- ->setMethods ([
57- 'getSystemValue ' ,
58- 'setSystemValue ' ,
59- 'getSystemValues ' ,
60- 'setSystemValues ' ,
61- 'getFilteredSystemValue ' ,
62- 'deleteSystemValue ' ,
63- 'getAppKeys ' ,
64- 'setAppValue ' ,
65- 'getAppValue ' ,
66- 'deleteAppValue ' ,
67- 'deleteAppValues ' ,
68- 'setUserValue ' ,
69- 'getUserValue ' ,
70- 'getUserValueForUsers ' ,
71- 'getUserKeys ' ,
72- 'deleteUserValue ' ,
73- 'deleteAllUserValues ' ,
74- 'deleteAppFromAllUsers ' ,
75- 'getUsersForUserValue ' ,
76- ])
77- ->getMock ();
78-
83+ $ config = $ this ->createMock (IConfig::class);
7984 $ config ->method ('getSystemValue ' )
8085 ->will ($ this ->returnCallback ([$ this , 'getSystemValue ' ]));
8186 return $ config ;
0 commit comments