Completed
Branch master (5105da)
by Stefano
02:21
created

EventTest::testSimple()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 74
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 74
rs 9.0335
c 1
b 0
f 1
cc 2
eloc 37
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
4
class EventTest extends PHPUnit_Framework_TestCase {
5
6
    public function testSimple(){
7
				$value = 0;
8
9
    		Event::on('test.event.alpha',function($override=null) use (&$value) {
10
				  $value = $override ?: 'alpha';
11
				});
12
13
				Event::trigger('test.event.alpha');
14
        $this->assertEquals('alpha',$value);
15
16
				Event::trigger('test.event.alpha',1234);
17
        $this->assertEquals(1234,$value);
18
19
				Event::on('test.event.alpha',function() use (&$value) {
20
				    $value .= '2';
21
				});
22
23
				Event::trigger('test.event.alpha');
24
				$this->assertEquals('alpha2',$value);
25
26
27
				/*********************************************************/
28
				$value = 123;
29
				Event::off('test.event.alpha');
30
				Event::trigger('test.event.alpha');
31
				//test($value == 123,'Event','Remove all triggers.');
32
				$this->assertEquals(123,$value);
33
34
35
				/*********************************************************/
36
				$value = 1;
37
				Event::on('test.event',function() use (&$value) {
38
				    $value *= 2;
39
				});
40
41
				Event::triggerOnce('test.event');
42
				Event::triggerOnce('test.event');
43
				//test($value == 2,'Event','Trigger Once.');
44
				$this->assertEquals(2,$value);
45
46
47
				/*********************************************************/
48
				$value = 0;
49
50
				Event::single('test.event',function() use (&$value) {
51
				    $value += 1;
52
				});
53
54
				// This must override the +=1
55
				Event::single('test.event',function() use (&$value) {
56
				    $value += 2;
57
				});
58
59
				Event::trigger('test.event');
60
				//test($value == 2,'Event','Single handler.');
61
				$this->assertEquals(2,$value);
62
63
				/*********************************************************/
64
				$value = 0;
65
				Event::off('test.event');
66
67
				Event::on('test.event',function() use (&$value) {
68
				    $value += 1;
69
				});
70
71
				Event::alias('test.event','the.dude');
72
73
				Event::trigger('test.event');
74
				Event::trigger('the.dude');
75
				//test($value == 2,'Event','Alias.');
76
				$this->assertEquals(2,$value);
77
78
79
    }
80
81
82
}
83
84
85