root/trunk/tests/definitions/ConstructorDefinitionTestCase.php

Revision 142, 3.6 kB (checked in by mikey, 3 weeks ago)

upgrade to new namespace separator

Line 
1 <?php
2 /**
3  * Test for ConstructorDefinition.
4  *
5  * @author  Frank Kleine <mikey@xjconf.net>
6  */
7 use netWarning: Unexpected character in input:  '\' (ASCII=92) state=1 in Unknown on line 0xjconfWarning: Unexpected character in input:  '\' (ASCII=92) state=1 in Unknown on line 0definitionsWarning: Unexpected character in input:  '\' (ASCII=92) state=1 in Unknown on line 0ChildDefinition;
8 use netWarning: Unexpected character in input:  '\' (ASCII=92) state=1 in Unknown on line 0xjconfWarning: Unexpected character in input:  '\' (ASCII=92) state=1 in Unknown on line 0definitionsWarning: Unexpected character in input:  '\' (ASCII=92) state=1 in Unknown on line 0ConstructorDefinition;
9 Mock::generate('net\xjconf\Tag', 'MockTag');
10 Mock::generate('net\xjconf\definitions\Definition', 'MockDefinition');
11 /**
12  * Test for ConstructorDefinition.
13  *
14  * @package     XJConf
15  * @subpackage  test_definitions
16  */
17 class ConstructorDefinitionTestCase extends UnitTestCase
18 {
19     /**
20      * instance to test
21      *
22      * @var  ConstructorDefinition
23      */
24     protected $constructorDefinition;
25     /**
26      * a mocked tag
27      *
28      * @var  Tag
29      */
30     protected $tag;
31     
32     /**
33      * set up test resources
34      */
35     public function setUp()
36     {
37         $this->constructorDefinition = new ConstructorDefinition();
38         $this->tag                   = new MockTag();
39     }
40     
41     /**
42      * test if construction works
43      */
44     public function testConstruct()
45     {
46         $this->assertEqual($this->constructorDefinition->getName(), '__constructor');
47         $this->assertNull($this->constructorDefinition->getType());
48         $this->assertNull($this->constructorDefinition->getValueType($this->tag));
49     }
50     
51     /**
52      * test that the setter method is as expected
53      */
54     public function testSetterMethod()
55     {
56         $this->assertNull($this->constructorDefinition->getSetterMethod($this->tag));
57     }
58     
59     /**
60      * test that converting the value works as expected
61      */
62     public function testConvertValue()
63     {
64         $this->assertNull($this->constructorDefinition->convertValue($this->tag));
65     }
66     
67     /**
68      * test that the child related methods always return the same
69      */
70     public function testChildMethods()
71     {
72         
73         $child1 = new ChildDefinition('child1');
74         $child2 = new ChildDefinition('child2');
75         $mock   = new MockDefinition();
76         $this->assertFalse($this->constructorDefinition->hasChildDefinition('MockDefinition'));
77         $this->assertNull($this->constructorDefinition->getChildDefinition('MockDefinition'));
78         $this->assertEqual($this->constructorDefinition->getChildDefinitions(), array());
79         $this->assertEqual($this->constructorDefinition->getParams(), array());
80         $this->assertEqual($this->constructorDefinition->getUsedChildrenNames(), array());
81         $this->constructorDefinition->addChildDefinition($mock);
82         $this->assertTrue($this->constructorDefinition->hasChildDefinition('MockDefinition'));
83         $childDef = $this->constructorDefinition->getChildDefinition('MockDefinition');
84         $this->assertReference($childDef, $mock);
85         $this->assertEqual($this->constructorDefinition->getChildDefinitions(), array($mock));
86         $this->assertEqual($this->constructorDefinition->getParams(), array($mock));
87         $this->assertEqual($this->constructorDefinition->getUsedChildrenNames(), array());
88         $this->constructorDefinition->addChildDefinition($child1);
89         $this->constructorDefinition->addChildDefinition($child2);
90         $this->assertTrue($this->constructorDefinition->hasChildDefinition('MockDefinition'));
91         $childDef2 = $this->constructorDefinition->getChildDefinition('MockDefinition');
92         $this->assertReference($childDef2, $mock);
93         $this->assertEqual($this->constructorDefinition->getChildDefinitions(), array($mock, $child1, $child2));
94         $this->assertEqual($this->constructorDefinition->getParams(), array($mock, $child1, $child2));
95         $this->assertEqual($this->constructorDefinition->getUsedChildrenNames(), array('child1', 'child2'));
96         
97     }
98 }
99 ?>
Note: See TracBrowser for help on using the browser.