1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
namespace Fwk\Events; |
4
|
|
|
|
5
|
|
|
if(!class_exists('\Fwk\Events\Event')) |
|
|
|
|
6
|
|
|
require_once __DIR__ .'/../src/Event.php'; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Test class for Event. |
10
|
|
|
* Generated by PHPUnit on 2010-12-22 at 14:22:34. |
11
|
|
|
*/ |
12
|
|
|
class EventTest extends \PHPUnit_Framework_TestCase { |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var Event |
16
|
|
|
*/ |
17
|
|
|
protected $object; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Sets up the fixture, for example, opens a network connection. |
21
|
|
|
* This method is called before a test is executed. |
22
|
|
|
*/ |
23
|
|
|
protected function setUp() |
24
|
|
|
{ |
25
|
|
|
$this->object = new Event('test.event', array('test' => 'testValue')); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @todo Implement testGetName(). |
30
|
|
|
*/ |
31
|
|
|
public function testGetName() |
32
|
|
|
{ |
33
|
|
|
$this->assertEquals('test.event', $this->object->getName()); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
*/ |
38
|
|
|
public function testGetData() |
39
|
|
|
{ |
40
|
|
|
$this->assertTrue(is_array($this->object->getData())); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
*/ |
45
|
|
|
public function testSetProcessed() |
46
|
|
|
{ |
47
|
|
|
$this->assertFalse($this->object->isProcessed()); |
48
|
|
|
$this->object->setProcessed(true); |
49
|
|
|
$this->assertTrue($this->object->isProcessed()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testDataAsObjectProperties() |
53
|
|
|
{ |
54
|
|
|
$this->assertFalse(isset($this->object->test2)); |
55
|
|
|
$this->assertTrue(isset($this->object->test)); |
56
|
|
|
$this->assertEquals('testValue', $this->object->test); |
|
|
|
|
57
|
|
|
$this->assertFalse($this->object->__isset('test2')); |
58
|
|
|
$this->assertTrue($this->object->__isset('test')); |
59
|
|
|
$this->assertEquals('testValue', $this->object->__get('test')); |
60
|
|
|
$this->object->__set('test2', 'testValue2'); |
61
|
|
|
$this->assertTrue($this->object->__isset('test2')); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.