Completed
Push — master ( e5e771...ea902a )
by Thomas
02:47
created

AppManagerTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 51.39 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 1
dl 37
loc 72
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testDisableApp() 6 6 1
A testEnableApp() 6 6 1
A appListProvider() 0 12 1
A testGetAllApps() 6 6 1
A testGetShippedApps() 6 6 1
A testGetAppPath() 0 7 1
A getOccRunnerMock() 13 13 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Owncloud\Updater\Tests\Utils;
4
5
use Owncloud\Updater\Utils\AppManager;
6
7
class AppManagerTest extends \PHPUnit_Framework_TestCase {
8
9 View Code Duplication
	public function testDisableApp(){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
		$appId = 'anyapp';
11
		$appManager = new AppManager($this->getOccRunnerMock(''));
12
		$result = $appManager->disableApp($appId);
13
		$this->assertTrue($result);
14
	}
15
16 View Code Duplication
	public function testEnableApp(){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
		$appId = 'anyapp';
18
		$appManager = new AppManager($this->getOccRunnerMock(''));
19
		$result = $appManager->enableApp($appId);
20
		$this->assertTrue($result);
21
	}
22
23
	public function appListProvider(){
24
		return [
25
26
					[
27
						[
28
							'enabled' => [ 'app1' => '1.0.1', 'app2' => '2.4.1' ],
29
							'disabled' => [	'dapp1' => '0.0.1',	'dapp2' => '5.1.1' ]
30
						],
31
						[ 'app1', 'app2', 'dapp1', 'dapp2'	]
32
					]
33
		];
34
	}
35
36
	/**
37
	 * @dataProvider appListProvider
38
	 */
39 View Code Duplication
	public function testGetAllApps($apps, $expected){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
		$encoded = json_encode($apps);
41
		$appManager = new AppManager($this->getOccRunnerMock($encoded));
42
		$actual = $appManager->getShippedApps();
43
		$this->assertEquals($expected, $actual);
44
	}
45
46
	/**
47
	 * @dataProvider appListProvider
48
	*/
49 View Code Duplication
	public function testGetShippedApps($apps, $expected){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
		$encoded = json_encode($apps);
51
		$appManager = new AppManager($this->getOccRunnerMock($encoded));
52
		$actual = $appManager->getShippedApps();
53
		$this->assertEquals($expected, $actual);
54
	}
55
56
	public function testGetAppPath(){
57
		$expected = '/dev/null';
58
		$appId = 'anyapp';
59
		$appManager =  new AppManager($this->getOccRunnerMock($expected));
60
		$actual = $appManager->getAppPath($appId);
61
		$this->assertEquals($expected, $actual);
62
	}
63
64 View Code Duplication
	protected function getOccRunnerMock($result){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
		$runnerMock = $this->getMockBuilder('Owncloud\Updater\Utils\OccRunner')
66
				->setMethods(['run'])
67
				->disableOriginalConstructor()
68
				->getMock()
69
		;
70
		$runnerMock
71
				->expects($this->any())
72
				->method('run')
73
				->willReturn($result)
74
		;
75
		return $runnerMock;
76
	}
77
78
}
79