Passed
Branch master (71c281)
by Wanderson
01:19
created

AlertTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 54.55 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 24
loc 44
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 4

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 AlertTest extends \PHPUnit_Framework_TestCase {
8
9
	public function testGetMessage() {
10
		$instance = new AlertError('My Alert');
11
		$this->assertEquals('My Alert', $instance->message);
12
		$this->assertEquals('My Alert', $instance);
13
	}
14
15
	public function testGetType() {
16
		$instance = new AlertError('My Error msg');
17
		$this->assertEquals('danger', $instance->type);
18
19
		$instance2 = new AlertSuccess('My Success msg');
20
		$this->assertEquals('success', $instance2->type);
21
	}
22
23
	public function testLoad() {
24
		ob_start();
25
		$alert = new AlertError('My Error msg');
26
		$alert->load();
27
		$content = ob_get_contents();
28
		ob_end_clean();
29
		$this->assertNotEmpty($content);
30
	}
31
32
	public function testCreateAlertWithError() {
33
		ob_start();
34
		Session::showAlerts();
35
		$alert = Alert::create('This is a error', 'Congratulations');
36
		$this->assertTrue($alert instanceof AlertError);
37
		$this->assertEquals('This is a error', $alert->message);
38
		ob_end_clean();
39
	}
40
41
	public function testCreateNoError() {
42
		ob_start();
43
		Session::showAlerts();
44
		$alert = Alert::create(null, 'Congratulations');
45
		$this->assertTrue($alert instanceof AlertSuccess);
46
		$this->assertEquals('Congratulations', $alert->message);
47
		ob_end_clean();
48
	}
49
50
}
51