Completed
Branch master (1d7ebe)
by Wanderson
02:15
created

SessionTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 15.38 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 8
loc 52
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 4

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A testCountAlerts() 0 10 1
A testHasAlert() 0 4 1
A testHasNoAlert() 0 5 1
A testGetAlerts() 0 5 1
A testShowAnything() 8 8 1
A testShowNothing() 0 7 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 Win\Alert;
4
5
use Win\Alert\AlertError;
6
7
class SessionTest extends \PHPUnit_Framework_TestCase {
8
9
	public function setUp() {
10
		Session::clearAlerts();
11
	}
12
13
	public function testCountAlerts() {
14
		ob_start();
15
		new AlertError('My Alert 01');
16
		new AlertError('My Alert 02');
17
		$this->assertEquals(2, count(Session::getAlerts()));
18
19
		Session::clearAlerts();
20
		$this->assertEquals(0, count(Session::getAlerts()));
21
		ob_end_clean();
22
	}
23
24
	public function testHasAlert() {
25
		new AlertDefault('Test');
26
		$this->assertEquals(true, Session::hasAlert());
27
	}
28
29
	public function testHasNoAlert() {
30
		new AlertDefault('Test');
31
		Session::clearAlerts();
32
		$this->assertEquals(false, Session::hasAlert());
33
	}
34
35
	public function testGetAlerts() {
36
		$alert = new AlertError('I am the firt error');
37
		$alerts = Session::getAlerts();
38
		$this->assertEquals($alert->message, $alerts[0]->message);
39
	}
40
41 View Code Duplication
	public function testShowAnything() {
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...
42
		ob_start();
43
		new AlertError('My Error msg');
44
		Session::showAlerts();
45
		$content = ob_get_contents();
46
		ob_end_clean();
47
		$this->assertNotEmpty($content);
48
	}
49
50
	public function testShowNothing() {
51
		ob_start();
52
		Session::showAlerts();
53
		$content = ob_get_contents();
54
		ob_end_clean();
55
		$this->assertEmpty($content);
56
	}
57
58
}
59