Skip to content

Commit

Permalink
add trait unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
boxblinkracer committed Dec 23, 2023
1 parent 083059d commit 0e13331
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions tests/phpunit/Traits/XmlTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace phpunit\Traits;

use PHPUnit\Framework\TestCase;
use PHPUnuhi\Traits\XmlTrait;
use SimpleXMLElement;

class XmlTraitTest extends TestCase
{
use XmlTrait;


/**
* @return void
*/
public function testGetAttribute(): void
{
$xmlNode = new SimpleXMLElement('<root attr1="value1" attr2="value2"/>');

$attr = $this->getAttribute('attr1', $xmlNode);

$this->assertEquals('attr1', $attr->getName());
$this->assertEquals('value1', $attr->getValue());
}

/**
* @return void
*/
public function testGetAttributeNotFoundLeadsToEmpty(): void
{
$xmlNode = new SimpleXMLElement('<root attr1="value1" attr2="value2"/>');

$attr = $this->getAttribute('notExisting', $xmlNode);

$this->assertEquals('notExisting', $attr->getName());
$this->assertEquals('', $attr->getValue());
}

/**
* @return void
*/
public function testGetAttributes(): void
{
$xmlNode = new SimpleXMLElement('<root attr1="value1" attr2="value2"/>');

$attributes = $this->getAttributes($xmlNode);

$this->assertCount(2, $attributes);

$this->assertEquals('attr1', $attributes[0]->getName());
$this->assertEquals('value1', $attributes[0]->getValue());

$this->assertEquals('attr2', $attributes[1]->getName());
$this->assertEquals('value2', $attributes[1]->getValue());
}
}

0 comments on commit 0e13331

Please sign in to comment.