Completed
Pull Request — master (#213)
by Thomas
07:42
created

ConfigReaderTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 22.81 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 1
dl 13
loc 57
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetByPathProvider() 0 5 1
A testGetByPath() 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\ConfigReader;
6
7
class ConfigReaderTest extends \PHPUnit_Framework_TestCase {
8
9
	protected $config = [
10
		"system" => [
11
			"instanceid" => "oc8v9kkjo6bh",
12
			"ldapIgnoreNamingRules" => false,
13
		],
14
		"apps" => [
15
			"backgroundjob" => [
16
				"lastjob" => "3"
17
			],
18
			"core" => [
19
				"installedat" => "1423763974.698",
20
				"lastupdatedat" => "1450277990",
21
				"lastcron" => "1444753126",
22
				"OC_Channel" => "beta",
23
			],
24
			"dav" => [
25
				"installed_version" => "0.1.3",
26
				"types" => "filesystem",
27
				"enabled" => "yes"
28
			]
29
		]
30
	];
31
32
	public function testGetByPathProvider(){
33
		return [
34
				[ 'apps.core.OC_Channel', 'beta']
35
		];
36
	}
37
38
	/**
39
	 * @dataProvider testGetByPathProvider
40
	 */
41
	public function testGetByPath($key, $expected){
42
		$occRunnerMock = $this->getOccRunnerMock(json_encode($this->config));
43
		$configReader = new ConfigReader($occRunnerMock);
44
		$configReader->init();
45
		$value = $configReader->getByPath($key);
46
		$this->assertEquals($expected, $value);
47
	}
48
49 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...
50
		$runnerMock = $this->getMockBuilder('Owncloud\Updater\Utils\OccRunner')
51
				->setMethods(['run'])
52
				->disableOriginalConstructor()
53
				->getMock()
54
		;
55
		$runnerMock
56
				->expects($this->any())
57
				->method('run')
58
				->willReturn($result)
59
		;
60
		return $runnerMock;
61
	}
62
63
}
64