| 1 | <?php |
||
| 15 | public $attributes = []; |
||
| 16 | |||
| 17 | public function testWithout() |
||
| 18 | { |
||
| 19 | $xml = $this->toXml(); |
||
| 20 | $this->assertEquals(0, $xml->attributes->length); |
||
| 21 | } |
||
| 22 | |||
| 23 | public function testFew() |
||
| 24 | { |
||
| 25 | $this->attributes = [ |
||
| 26 | 'a' => 1, |
||
| 27 | 'b' => 2, |
||
| 28 | // This attribute must be ignored |
||
| 29 | 'array' => [1,2,3], |
||
| 30 | 'null' => null, |
||
| 31 | 'object' => (object)[1,2,3], |
||
| 32 | ]; |
||
| 33 | $xml = $this->toXml(); |
||
| 34 | $this->assertEquals(2, $xml->attributes->length); |
||
| 35 | |||
| 36 | // Removing not-convertible attribute |
||
| 37 | $attributes = array_splice($this->attributes, 0, 2); |
||
| 38 | foreach ($attributes as $name => $value) { |
||
| 39 | $this->assertEquals($value, $xml->getAttribute($name)); |
||
| 40 | } |
||
| 41 | } |
||
| 42 | |||
| 43 | |||
| 44 | public function getXmlProperties(?array $properties = null): array |
||
| 45 | { |
||
| 46 | if (empty($this->attributes)) { |
||
| 47 | return $this->traitGetXmlProperties(); |
||
| 48 | } |
||
| 49 | return array_keys($this->attributes); |
||
| 50 | } |
||
| 51 | |||
| 52 | public function __get($name) |
||
| 53 | { |
||
| 54 | $this->assertArrayHasKey($name, $this->attributes); |
||
| 55 | return $this->attributes[$name]; |
||
| 56 | } |
||
| 57 | } |
||
| 58 |