|
| 1 | +<?php |
| 2 | + |
| 3 | +use PHPUnit\Framework\TestCase; |
| 4 | +use RefactorStudio\PhpArrayToXml\PhpArrayToXml; |
| 5 | + |
| 6 | +class PhpArrayToXmlGettersSettersTest extends TestCase |
| 7 | +{ |
| 8 | + /** @covers \RefactorStudio\PhpArrayToXml\PhpArrayToXml::getDefaultRootName */ |
| 9 | + public function test_it_should_get_the_default_root_name() |
| 10 | + { |
| 11 | + $class = new PhpArrayToXml(); |
| 12 | + |
| 13 | + // Default |
| 14 | + $this->assertEquals('root', $class->getDefaultRootName()); |
| 15 | + } |
| 16 | + |
| 17 | + /** @covers \RefactorStudio\PhpArrayToXml\PhpArrayToXml::getDefaultNodeName */ |
| 18 | + public function test_it_should_get_the_default_node_name() |
| 19 | + { |
| 20 | + $class = new PhpArrayToXml(); |
| 21 | + |
| 22 | + // Default |
| 23 | + $this->assertEquals('node', $class->getDefaultNodeName()); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * @covers \RefactorStudio\PhpArrayToXml\PhpArrayToXml::setVersion |
| 28 | + * @covers \RefactorStudio\PhpArrayToXml\PhpArrayToXml::getVersion |
| 29 | + */ |
| 30 | + public function test_it_should_get_and_set_the_version() |
| 31 | + { |
| 32 | + $class = new PhpArrayToXml(); |
| 33 | + |
| 34 | + // Default |
| 35 | + $this->assertEquals('1.0', $class->getVersion()); |
| 36 | + |
| 37 | + // Custom |
| 38 | + $class->setVersion('1.1'); |
| 39 | + $this->assertEquals('1.1', $class->getVersion()); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * @covers \RefactorStudio\PhpArrayToXml\PhpArrayToXml::setEncoding |
| 44 | + * @covers \RefactorStudio\PhpArrayToXml\PhpArrayToXml::getEncoding |
| 45 | + */ |
| 46 | + public function test_it_should_get_and_set_the_encoding() |
| 47 | + { |
| 48 | + $class = new PhpArrayToXml(); |
| 49 | + |
| 50 | + // Default |
| 51 | + $this->assertEquals('UTF-8', $class->getEncoding()); |
| 52 | + |
| 53 | + // Custom |
| 54 | + $class->setEncoding('ISO-8859-1'); |
| 55 | + $this->assertEquals('ISO-8859-1', $class->getEncoding()); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * @covers \RefactorStudio\PhpArrayToXml\PhpArrayToXml::setFormatOutput |
| 60 | + * @covers \RefactorStudio\PhpArrayToXml\PhpArrayToXml::getFormatOutput |
| 61 | + */ |
| 62 | + public function test_it_should_get_and_set_the_format_output() |
| 63 | + { |
| 64 | + $class = new PhpArrayToXml(); |
| 65 | + |
| 66 | + // Default |
| 67 | + $this->assertEquals(false, $class->getFormatOutput()); |
| 68 | + |
| 69 | + // Custom |
| 70 | + $class->setFormatOutput(true); |
| 71 | + $this->assertEquals(true, $class->getFormatOutput()); |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * @covers \RefactorStudio\PhpArrayToXml\PhpArrayToXml::setCustomRootName |
| 76 | + * @covers \RefactorStudio\PhpArrayToXml\PhpArrayToXml::getCustomRootName |
| 77 | + */ |
| 78 | + public function test_it_should_get_and_set_the_custom_root_name() |
| 79 | + { |
| 80 | + $class = new PhpArrayToXml(); |
| 81 | + |
| 82 | + // Default |
| 83 | + $this->assertEquals(null, $class->getCustomRootName()); |
| 84 | + |
| 85 | + // Custom |
| 86 | + $class->setCustomRootName('MyCustomRootName'); |
| 87 | + $this->assertEquals('MyCustomRootName', $class->getCustomRootName()); |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * @covers \RefactorStudio\PhpArrayToXml\PhpArrayToXml::setCustomNodeName |
| 92 | + * @covers \RefactorStudio\PhpArrayToXml\PhpArrayToXml::getCustomNodeName |
| 93 | + */ |
| 94 | + public function test_it_should_get_and_set_the_custom_node_name() |
| 95 | + { |
| 96 | + $class = new PhpArrayToXml(); |
| 97 | + |
| 98 | + // Default |
| 99 | + $this->assertEquals(null, $class->getCustomNodeName()); |
| 100 | + |
| 101 | + // Custom |
| 102 | + $class->setCustomNodeName('MyCustomNodeName'); |
| 103 | + $this->assertEquals('MyCustomNodeName', $class->getCustomNodeName()); |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * @covers \RefactorStudio\PhpArrayToXml\PhpArrayToXml::setCustomNodeName |
| 108 | + */ |
| 109 | + public function test_it_should_give_an_exception_when_setting_an_invalid_custom_node_name() |
| 110 | + { |
| 111 | + $this->expectException(Exception::class); |
| 112 | + |
| 113 | + $class = new PhpArrayToXml(); |
| 114 | + $class->setCustomNodeName(123); |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * @covers \RefactorStudio\PhpArrayToXml\PhpArrayToXml::setCustomRootName |
| 119 | + */ |
| 120 | + public function test_it_should_give_an_exception_when_setting_an_invalid_custom_root_name() |
| 121 | + { |
| 122 | + $this->expectException(Exception::class); |
| 123 | + |
| 124 | + $class = new PhpArrayToXml(); |
| 125 | + $class->setCustomRootName(123); |
| 126 | + } |
| 127 | + |
| 128 | + /** |
| 129 | + * @covers \RefactorStudio\PhpArrayToXml\PhpArrayToXml::setSeparator |
| 130 | + * @covers \RefactorStudio\PhpArrayToXml\PhpArrayToXml::getSeparator |
| 131 | + */ |
| 132 | + public function test_it_should_get_and_set_the_separator() |
| 133 | + { |
| 134 | + $class = new PhpArrayToXml(); |
| 135 | + |
| 136 | + // Default |
| 137 | + $this->assertEquals('_', $class->getSeparator()); |
| 138 | + |
| 139 | + // Custom |
| 140 | + $class->setSeparator('-'); |
| 141 | + $this->assertEquals('-', $class->getSeparator()); |
| 142 | + } |
| 143 | + |
| 144 | + /** |
| 145 | + * @covers \RefactorStudio\PhpArrayToXml\PhpArrayToXml::setMethodTransformKeys |
| 146 | + * @covers \RefactorStudio\PhpArrayToXml\PhpArrayToXml::getMethodTransformKeys |
| 147 | + */ |
| 148 | + public function test_it_should_get_and_set_the_key_transform_method() |
| 149 | + { |
| 150 | + $class = new PhpArrayToXml(); |
| 151 | + |
| 152 | + // Default |
| 153 | + $this->assertEquals(null, $class->getMethodTransformKeys()); |
| 154 | + |
| 155 | + // Custom |
| 156 | + $class->setMethodTransformKeys(PhpArrayToXml::LOWERCASE); |
| 157 | + $this->assertEquals(PhpArrayToXml::LOWERCASE, $class->getMethodTransformKeys()); |
| 158 | + |
| 159 | + $class->setMethodTransformKeys(PhpArrayToXml::UPPERCASE); |
| 160 | + $this->assertEquals(PhpArrayToXml::UPPERCASE, $class->getMethodTransformKeys()); |
| 161 | + |
| 162 | + $class->setMethodTransformKeys(null); |
| 163 | + $this->assertEquals(null, $class->getMethodTransformKeys()); |
| 164 | + } |
| 165 | +} |
0 commit comments