Completed
Pull Request — master (#53)
by Helpful
02:20
created

StaticPagesQueueEventTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
/**
4
 * This is a Unittest class for EventTest
5
 * 
6
 */
7
class StaticPagesQueueEventTest extends SapphireTest {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
9
	public function setUp() {
10
		parent::setUp();
11
		StaticPagesQueueEvent::clear();
12
		Config::inst()->nest();
13
		Config::inst()->update('StaticPagesQueue', 'realtime', true);
14
	}
15
16
	public function tearDown() {
17
		Config::inst()->unnest();
18
		parent::tearDown();
19
	}
20
21
	public function testRegisterEventWithNonExistingInterface() {
22
		$this->setExpectedException('StaticPagesQueueEvent_Exception');
23
		StaticPagesQueueEvent::register_event('EventTestClassImplementator', 'apa');
24
	}
25
	
26
	public function testRegisterEventWithNonExistingEventhandler() {
27
		$this->setExpectedException('StaticPagesQueueEvent_Exception');
28
		StaticPagesQueueEvent::register_event('apa', 'TestingEventListener');
29
	}
30
	
31
	public function testRegisterEventNoImplementators() {
32
		$this->setExpectedException('StaticPagesQueueEvent_Exception');
33
		StaticPagesQueueEvent::register_event('EventTestClass', 'TestingEventListenerMissing');
34
	}
35
	
36
	public function testRegisterEvent() {
37
		 StaticPagesQueueEvent::register_event('EventTestClass', 'TestingEventListener');
38
	}
39
	
40
	public function testFireEventNoEventClassRegistered() {
41
		StaticPagesQueueEvent::trigger_events_during_testing(true);
42
		$this->setExpectedException('StaticPagesQueueEvent_Exception');
43
		StaticPagesQueueEvent::fire_event(new EventTestClass());
44
	}
45
	
46
	public function testFireEvent() {
47
		StaticPagesQueueEvent::trigger_events_during_testing(true);
48
		StaticPagesQueueEvent::register_event('EventTestClass', 'TestingEventListener');
49
		$this->assertTrue(StaticPagesQueueEvent::fire_event(new EventTestClass()));
50
		
51
	}
52
	
53
	public function testTriggerEventsDuringTesting() {
54
		StaticPagesQueueEvent::trigger_events_during_testing(false);
55
		StaticPagesQueueEvent::register_event('EventTestClass', 'TestingEventListener');
56
		$this->assertFalse(StaticPagesQueueEvent::fire_event(new EventTestClass()));
57
	}
58
}
59
60
interface TestingEventListener extends TestOnly {}
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
Each interface must be in a namespace of at least one level (a top-level vendor name)

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
61
62
class EventTestClassImplementator implements TestingEventListener {
0 ignored issues
show
Coding Style Compatibility introduced by
Each interface must be in a file by itself

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
63
	public function testingEvent() {
64
		return true;
65
	}
66
}
67
class EventTestClass extends StaticPagesQueueEvent implements TestOnly{
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
68
}
69
70
interface TestingEventListenerMissing extends TestOnly {}
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
Each interface must be in a namespace of at least one level (a top-level vendor name)

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
71