Completed
Push — master ( bb7259...dc298a )
by Sam
03:00
created

ValidatorTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 111
Duplicated Lines 14.41 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 1
cbo 3
dl 16
loc 111
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testMandatoryValues() 0 9 1
A testDatabasePath() 8 8 1
A testLogPath() 8 8 1
A testUpdateInterval() 0 8 1
A testListenPort() 0 8 1
A updateIntervalProvider() 0 8 1
A listenPortProvider() 0 9 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 Jalle19\StatusManager\Test\Configuration;
4
5
use Jalle19\StatusManager\Configuration\Validator;
6
7
/**
8
 * Class ValidatorTest
9
 * @package   Jalle19\StatusManager\Test\Configuration
10
 * @copyright Copyright &copy; Sam Stenvall 2016-
11
 * @license   https://www.gnu.org/licenses/gpl.html The GNU General Public License v2.0
12
 */
13
class ValidatorTest extends \PHPUnit_Framework_TestCase
14
{
15
	
16
	use BasicConfigurationTrait;
17
18
	/**
19
	 * @expectedException \Jalle19\StatusManager\Exception\InvalidConfigurationException
20
	 * @expectedExceptionMessageRegExp *Mandatory*
21
	 */
22
	public function testMandatoryValues()
23
	{
24
		$configuration = [
25
26
		];
27
28
		$validator = new Validator($configuration);
29
		$validator->validate();
30
	}
31
32
33
	/**
34
	 * @expectedException \Jalle19\StatusManager\Exception\InvalidConfigurationException
35
	 * @expectedExceptionMessageRegExp *The database path*
36
	 */
37 View Code Duplication
	public function testDatabasePath()
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...
38
	{
39
		$configuration                  = $this->getBaseConfiguration();
40
		$configuration['database_path'] = '/tmp/does/not/exist';
41
42
		$validator = new Validator($configuration);
43
		$validator->validate();
44
	}
45
46
47
	/**
48
	 * @expectedException \Jalle19\StatusManager\Exception\InvalidConfigurationException
49
	 * @expectedExceptionMessageRegExp *The log path*
50
	 */
51 View Code Duplication
	public function testLogPath()
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...
52
	{
53
		$configuration             = $this->getBaseConfiguration();
54
		$configuration['log_path'] = '/tmp/does/not/exist';
55
56
		$validator = new Validator($configuration);
57
		$validator->validate();
58
	}
59
60
61
	/**
62
	 * @dataProvider                   updateIntervalProvider
63
	 *
64
	 * @param mixed $updateInterval
65
	 *
66
	 * @expectedException \Jalle19\StatusManager\Exception\InvalidConfigurationException
67
	 * @expectedExceptionMessageRegExp *Update interval cannot*
68
	 */
69
	public function testUpdateInterval($updateInterval)
70
	{
71
		$configuration                    = $this->getBaseConfiguration();
72
		$configuration['update_interval'] = $updateInterval;
73
74
		$validator = new Validator($configuration);
75
		$validator->validate();
76
	}
77
78
79
	/**
80
	 * @dataProvider                   listenPortProvider
81
	 *
82
	 * @param int $listenPort
83
	 *
84
	 * @expectedException \Jalle19\StatusManager\Exception\InvalidConfigurationException
85
	 * @expectedExceptionMessageRegExp *Listen port must be between*
86
	 */
87
	public function testListenPort($listenPort)
88
	{
89
		$configuration                = $this->getBaseConfiguration();
90
		$configuration['listen_port'] = $listenPort;
91
92
		$validator = new Validator($configuration);
93
		$validator->validate();
94
	}
95
96
97
	/**
98
	 * @return array
99
	 */
100
	public function updateIntervalProvider()
101
	{
102
		return [
103
			[0],
104
			[0.5],
105
			[0.99],
106
		];
107
	}
108
109
110
	/**
111
	 * @return array
112
	 */
113
	public function listenPortProvider()
114
	{
115
		return [
116
			[-1],
117
			[0],
118
			[65536],
119
			[100000],
120
		];
121
	}
122
123
}
124