-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
257 additions
and
128 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VeeWee\Xml\Dom\Configurator; | ||
|
||
use Closure; | ||
use VeeWee\Xml\Dom\Document; | ||
|
||
/** | ||
* @param callable(): \Dom\XMLDocument $loader | ||
* | ||
* @return Closure(\Dom\XMLDocument): \Dom\XMLDocument | ||
*/ | ||
function loader(callable $loader): Closure | ||
{ | ||
return static function () use ($loader): \Dom\XMLDocument { | ||
return Document::fromLoader($loader)->toUnsafeDocument(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VeeWee\Tests\Xml\Dom\Assert; | ||
|
||
use \DOM\Node; | ||
use PHPUnit\Framework\TestCase; | ||
use Psl\Type\Exception\AssertException; | ||
use VeeWee\Xml\Dom\Document; | ||
use function VeeWee\Xml\Dom\Assert\assert_attribute; | ||
|
||
final class AssertAttributeTest extends TestCase | ||
{ | ||
/** | ||
* | ||
* @dataProvider provideTestCases | ||
*/ | ||
public function test_it_knows_attributes(?\DOM\Node $node, bool $expected): void | ||
{ | ||
if (!$expected) { | ||
$this->expectException(AssertException::class); | ||
} | ||
|
||
$actual = assert_attribute($node); | ||
static::assertSame($node, $actual); | ||
} | ||
|
||
public static function provideTestCases() | ||
{ | ||
$doc = Document::fromXmlString( | ||
<<<EOXML | ||
<doc> | ||
<item attr="val" xmlns:foo="http://foo" xmlns="http://x">Hello</item> | ||
</doc> | ||
EOXML | ||
)->toUnsafeDocument(); | ||
|
||
yield [$doc, false]; | ||
yield [$doc->documentElement, false]; | ||
yield [$doc->documentElement->firstElementChild, false]; | ||
yield [$doc->documentElement->firstElementChild->attributes->getNamedItem('attr'), true]; | ||
yield [$doc->documentElement->firstElementChild->attributes->getNamedItem('xmlns:foo'), true]; | ||
yield [$doc->documentElement->firstElementChild->attributes->getNamedItem('xmlns'), true]; | ||
yield [$doc->documentElement->firstElementChild->firstChild, false]; | ||
yield [null, false]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VeeWee\Tests\Xml\Dom\Configurator; | ||
|
||
use Exception; | ||
use PHPUnit\Framework\TestCase; | ||
use VeeWee\Xml\Dom\Document; | ||
use function VeeWee\Xml\Dom\Configurator\loader; | ||
|
||
final class LoaderTest extends TestCase | ||
{ | ||
public function test_it_can_load_xml(): void | ||
{ | ||
$doc = \Dom\XMLDocument::createEmpty(); | ||
$xml = '<hello />'; | ||
|
||
$loader = loader(static function () use ($xml): \Dom\XMLDocument { | ||
return Document::fromXmlString($xml)->toUnsafeDocument(); | ||
}); | ||
|
||
$result = $loader($doc); | ||
static::assertNotSame($doc, $result); | ||
static::assertXmlStringEqualsXmlString($xml, $result->saveXML()); | ||
} | ||
|
||
|
||
public function test_it_can_mark_xml_loading_as_failed(): void | ||
{ | ||
$doc = \Dom\XMLDocument::createEmpty(); | ||
$exception = new Exception('Could not load the XML document'); | ||
$loader = loader(static function () use ($exception): never { | ||
throw $exception; | ||
}); | ||
|
||
$this->expectExceptionObject($exception); | ||
$loader($doc); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters