Completed
Push — master ( 761398...5ee568 )
by Julien
02:37
created

EventTest::testSetProcessed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 12 and the first side effect is on line 5.

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.

Loading history...
2
3
namespace Fwk\Events;
4
5
if(!class_exists('\Fwk\Events\Event'))
0 ignored issues
show
Coding Style introduced by
Please always use braces to surround the code block of IF statements.
Loading history...
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);
0 ignored issues
show
Documentation introduced by
The property test does not exist on object<Fwk\Events\Event>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
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