Skip to content

Commit

Permalink
Elements with attributes, but without values are no longer ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
milos-pejanovic-devtech committed Oct 25, 2016
1 parent 43caf90 commit 7209ed1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Mapper/XmlModelMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ protected function domNodeToObject(\DOMNode $domElement) {
$object = new \stdClass();
$result = null;

$this->mapAttributes($domElement, $object);
$this->mapNamespaces($domElement, $object);
$result = $this->mapAttributes($domElement, $object);
$result = $this->mapNamespaces($domElement, $object);

for($i = 0; $i < $domElement->childNodes->length; $i++) {
$element = $domElement->childNodes->item($i);
Expand Down Expand Up @@ -125,6 +125,8 @@ protected function mapAttributes(\DOMNode $domElement, $object) {
$value = $domElement->attributes->item($i)->nodeValue;
$object->$attributesKey[$key] = $value;
}

return $object;
}

/**
Expand All @@ -142,6 +144,8 @@ protected function mapNamespaces(\DOMNode $domElement, $object) {
foreach($newNamespaces as $key => $value) {
$object->$attributesKey[$key] = $value;
}

return $object;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/Mapper/XmlModelMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public function validValues() {
$model->xml = new XmlTestModel();
$model->xml->attributeTest = 'attribute';
$model->xml->value = 'nodeValue';
$model->xmlWithoutValue = new XmlTestWithoutValue();
$model->xmlWithoutValue->attributeTest = 'attribute';

$xml = Xml::loadFromFile(__DIR__ . '/xml/valid_testModel.xml');

Expand Down
1 change: 1 addition & 0 deletions tests/Mapper/xml/valid_testModel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,5 @@
<alwaysRequiredBoolean>false</alwaysRequiredBoolean>
<multipleRequiredInteger>5</multipleRequiredInteger>
<xml attributeTest="attribute">nodeValue</xml>
<xmlWithoutValue attributeTest="attribute"/>
</testModel>
5 changes: 5 additions & 0 deletions tests/TestModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,9 @@ class TestModel {
* @var XmlTestModel
*/
public $xml;

/**
* @var XmlTestWithoutValue
*/
public $xmlWithoutValue;
}
22 changes: 22 additions & 0 deletions tests/XmlTestWithoutValue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/**
* Created by PhpStorm.
* User: milos.pejanovic
* Date: 7/31/2016
* Time: 9:49 AM
*/
use Traits\MappableTrait;
use Traits\ConvertibleTrait;
use Traits\ValidatableTrait;

class XmlTestWithoutValue {
use MappableTrait;
use ConvertibleTrait;
use ValidatableTrait;

/**
* @xmlAttribute
*/
public $attributeTest;
}

0 comments on commit 7209ed1

Please sign in to comment.