1<?php
2
3
4
5/**
6 * Test class for PropertyPopulator.
7 * @group Core
8 */
9class PropertyPopulatorTest extends PHPUnit_Framework_TestCase {
10
11    /**
12     * @var PropertyPopulator
13     */
14    protected $object;
15
16    /**
17     * Sets up the fixture, for example, opens a network connection.
18     * This method is called before a test is executed.
19     */
20    protected function setUp() {
21    }
22
23    /**
24     * Tears down the fixture, for example, closes a network connection.
25     * This method is called after a test is executed.
26     */
27    protected function tearDown() {
28
29    }
30
31    public function testPopulateFromArray() {
32        $object = new PropertyPopulableClass();
33
34        $this->assertNull($object->getName());
35        $this->assertNull($object->getValue());
36        $this->assertFalse($object->isActive());
37
38        $object->populateFromArray(array(
39            'name' => 'Project 1',
40            'value' => 50000,
41            'isActive' => true,
42        ));
43
44        $this->assertEquals('Project 1', $object->getName());
45        $this->assertEquals(50000, $object->getValue());
46        $this->assertTrue($object->isActive());
47    }
48
49}
50
51class PropertyPopulableClass implements PopulatableFromArray {
52
53    protected $name;
54    protected $value;
55    protected $isActive;
56
57    function getName() {
58        return $this->name;
59    }
60
61    public function setName($name) {
62        $this->name = $name;
63    }
64
65    public function getValue() {
66        return $this->value;
67    }
68
69    public function setValue($value) {
70        $this->value = $value;
71    }
72
73    public function isActive($isActive = null) {
74        if (is_null($isActive)) {
75            return (bool) $this->isActive;
76        } else {
77            $this->isActive = (bool) $isActive;
78        }
79    }
80
81    public function populateFromArray(array $properties) {
82        PropertyPopulator::populateFromArray($this, $properties);
83    }
84
85}
86
87?>
88