Skip to content

Commit

Permalink
[TEST] Add Tests And Remove Unused Code
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasWeinert committed Oct 21, 2023
1 parent 22ae6c1 commit 2eb9fb8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/FluentDOM.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,17 @@ public static function Query(
* @throws InvalidArgumentException
* @throws OutOfBoundsException
* @throws InvalidVariableSource
* @codeCoverageIgnore
*/
public static function QueryCss(
mixed $source = NULL,
string $contentType = 'text/xml',
array $options = []
): FluentDOM\Query {
$builder = self::getXPathTransformer();
$transformer = self::getXPathTransformer();
$query = self::Query($source, $contentType, $options);
$isHtml = ($query->contentType === 'text/html');
$query->onPrepareSelector = static function($selector, $contextMode) use ($builder, $isHtml) {
return $builder->toXpath($selector, $contextMode, $isHtml);
$query->onPrepareSelector = static function($selector, $contextMode) use ($transformer, $isHtml) {
return $transformer->toXpath($selector, $contextMode, $isHtml);
};
return $query;
}
Expand Down
2 changes: 2 additions & 0 deletions src/FluentDOM/DOM/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public function removeAttributeNS(?string $namespace, string $localName): bool {
($this->getAttribute('xmlns:'.$localName) === $namespace) &&
($attribute = $this->getAttributeNodeNS($namespace, $localName))
) {
/** @noinspection PhpCastIsUnnecessaryInspection */
return (bool)parent::removeAttributeNode($attribute);
}
return (bool)parent::removeAttributeNS($namespace, $localName);
Expand Down Expand Up @@ -390,6 +391,7 @@ private function isNodeOffset(mixed $offset): bool {
* Attribute offsets are strings that can not only contains digits.
*/
private function isAttributeOffset(mixed $offset): bool {
/** @noinspection PhpCastIsUnnecessaryInspection */
return (is_string($offset) && !ctype_digit((string)$offset));
}

Expand Down
1 change: 0 additions & 1 deletion src/FluentDOM/Loader/Lazy.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public function add(string $contentType, Loadable|callable $loader): void {
$contentType = $this->normalizeContentType($contentType);
if ($loader instanceof Loadable || \is_callable($loader)) {
$this->_list[$contentType] = $loader;
return;
}
}

Expand Down
17 changes: 16 additions & 1 deletion tests/FluentDOMTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* FluentDOM
*
* @link https://thomas.weinert.info/FluentDOM/
* @copyright Copyright 2009-2021 FluentDOM Contributors
* @copyright Copyright 2009-2023 FluentDOM Contributors
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*
*/
Expand Down Expand Up @@ -31,6 +31,21 @@ public function testQueryWithNode(): void {
$this->assertXmlStringEqualsXmlString("<?xml version=\"1.0\"?>\n<test/>\n", (string)$query);
}

/**
* @group FactoryFunctions
* @covers FluentDOM
*/
public function testQueryCssWithNode(): void {
FluentDOM::registerXpathTransformer(
fn() => $this->createMock(XpathTransformer::class)
);
$document = new DOMDocument();
$document->appendChild($document->createElement('test'));
$query = FluentDOM::QueryCss($document->documentElement);
$this->assertCount(1, $query);
$this->assertXmlStringEqualsXmlString("<?xml version=\"1.0\"?>\n<test/>\n", (string)$query);
}

/**
* @group FactoryFunctions
* @covers FluentDOM
Expand Down

0 comments on commit 2eb9fb8

Please sign in to comment.