| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 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 0FactoryMethodDefinition; |
|---|
| 9 |
Mock::generate('net\xjconf\Tag', 'MockTag'); |
|---|
| 10 |
Mock::generate('net\xjconf\definitions\Definition', 'MockDefinition'); |
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
class FactoryMethodDefinitionTestCase extends UnitTestCase |
|---|
| 18 |
{ |
|---|
| 19 |
|
|---|
| 20 |
* instance to test |
|---|
| 21 |
* |
|---|
| 22 |
* @var FactoryMethod |
|---|
| 23 |
*/ |
|---|
| 24 |
protected $factoryMethodDefinition; |
|---|
| 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->factoryMethodDefinition = new FactoryMethodDefinition('test'); |
|---|
| 38 |
$this->tag = new MockTag(); |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
* test if construction works |
|---|
| 43 |
*/ |
|---|
| 44 |
public function testConstruct() |
|---|
| 45 |
{ |
|---|
| 46 |
$this->assertEqual($this->factoryMethodDefinition->getName(), 'test'); |
|---|
| 47 |
$this->assertNull($this->factoryMethodDefinition->getType()); |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
* test that the setter method is as expected |
|---|
| 52 |
*/ |
|---|
| 53 |
public function testSetterMethod() |
|---|
| 54 |
{ |
|---|
| 55 |
$this->expectException('net\xjconf\exceptions\UnsupportedOperationException'); |
|---|
| 56 |
$this->factoryMethodDefinition->getSetterMethod($this->tag); |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
* test that converting the value works as expected |
|---|
| 61 |
*/ |
|---|
| 62 |
public function testConvertValue() |
|---|
| 63 |
{ |
|---|
| 64 |
$this->expectException('net\xjconf\exceptions\UnsupportedOperationException'); |
|---|
| 65 |
$this->factoryMethodDefinition->convertValue($this->tag); |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
* test that the child related methods always return the same |
|---|
| 70 |
*/ |
|---|
| 71 |
public function testChildMethods() |
|---|
| 72 |
{ |
|---|
| 73 |
$child1 = new ChildDefinition('child1'); |
|---|
| 74 |
$child2 = new ChildDefinition('child2'); |
|---|
| 75 |
$mock = new MockDefinition(); |
|---|
| 76 |
$this->assertFalse($this->factoryMethodDefinition->hasChildDefinition('MockDefinition')); |
|---|
| 77 |
$this->assertNull($this->factoryMethodDefinition->getChildDefinition('MockDefinition')); |
|---|
| 78 |
$this->assertEqual($this->factoryMethodDefinition->getChildDefinitions(), array()); |
|---|
| 79 |
$this->assertEqual($this->factoryMethodDefinition->getParams(), array()); |
|---|
| 80 |
$this->assertEqual($this->factoryMethodDefinition->getUsedChildrenNames(), array()); |
|---|
| 81 |
$this->factoryMethodDefinition->addChildDefinition($mock); |
|---|
| 82 |
$this->assertTrue($this->factoryMethodDefinition->hasChildDefinition('MockDefinition')); |
|---|
| 83 |
$childDef = $this->factoryMethodDefinition->getChildDefinition('MockDefinition'); |
|---|
| 84 |
$this->assertReference($childDef, $mock); |
|---|
| 85 |
$this->assertEqual($this->factoryMethodDefinition->getChildDefinitions(), array($mock)); |
|---|
| 86 |
$this->assertEqual($this->factoryMethodDefinition->getParams(), array($mock)); |
|---|
| 87 |
$this->assertEqual($this->factoryMethodDefinition->getUsedChildrenNames(), array()); |
|---|
| 88 |
$this->factoryMethodDefinition->addChildDefinition($child1); |
|---|
| 89 |
$this->factoryMethodDefinition->addChildDefinition($child2); |
|---|
| 90 |
$this->assertTrue($this->factoryMethodDefinition->hasChildDefinition('MockDefinition')); |
|---|
| 91 |
$childDef2 = $this->factoryMethodDefinition->getChildDefinition('MockDefinition'); |
|---|
| 92 |
$this->assertReference($childDef2, $mock); |
|---|
| 93 |
$this->assertEqual($this->factoryMethodDefinition->getChildDefinitions(), array($mock, $child1, $child2)); |
|---|
| 94 |
$this->assertEqual($this->factoryMethodDefinition->getParams(), array($mock, $child1, $child2)); |
|---|
| 95 |
$this->assertEqual($this->factoryMethodDefinition->getUsedChildrenNames(), array('child1', 'child2')); |
|---|
| 96 |
} |
|---|
| 97 |
} |
|---|
| 98 |
?> |
|---|