Browse Source

ProcessingInstruction 100% covered, added cache for documents

master
Dustin Wilson 2 years ago
parent
commit
e5c8d526be
  1. 38
      composer.lock
  2. 13
      lib/Document.php
  3. 21
      tests/cases/TestProcessingInstruction.php
  4. 21
      tests/cases/TestSerializer.php
  5. 4
      tests/phpunit.dist.xml

38
composer.lock

@ -1445,23 +1445,23 @@
}, },
{ {
"name": "symfony/console", "name": "symfony/console",
"version": "v5.4.0", "version": "v5.4.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/console.git", "url": "https://github.com/symfony/console.git",
"reference": "ec3661faca1d110d6c307e124b44f99ac54179e3" "reference": "9130e1a0fc93cb0faadca4ee917171bd2ca9e5f4"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/console/zipball/ec3661faca1d110d6c307e124b44f99ac54179e3", "url": "https://api.github.com/repos/symfony/console/zipball/9130e1a0fc93cb0faadca4ee917171bd2ca9e5f4",
"reference": "ec3661faca1d110d6c307e124b44f99ac54179e3", "reference": "9130e1a0fc93cb0faadca4ee917171bd2ca9e5f4",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=7.2.5", "php": ">=7.2.5",
"symfony/deprecation-contracts": "^2.1|^3", "symfony/deprecation-contracts": "^2.1|^3",
"symfony/polyfill-mbstring": "~1.0", "symfony/polyfill-mbstring": "~1.0",
"symfony/polyfill-php73": "^1.8", "symfony/polyfill-php73": "^1.9",
"symfony/polyfill-php80": "^1.16", "symfony/polyfill-php80": "^1.16",
"symfony/service-contracts": "^1.1|^2|^3", "symfony/service-contracts": "^1.1|^2|^3",
"symfony/string": "^5.1|^6.0" "symfony/string": "^5.1|^6.0"
@ -1524,7 +1524,7 @@
"terminal" "terminal"
], ],
"support": { "support": {
"source": "https://github.com/symfony/console/tree/v5.4.0" "source": "https://github.com/symfony/console/tree/v5.4.1"
}, },
"funding": [ "funding": [
{ {
@ -1540,7 +1540,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2021-11-29T15:30:56+00:00" "time": "2021-12-09T11:22:43+00:00"
}, },
{ {
"name": "symfony/deprecation-contracts", "name": "symfony/deprecation-contracts",
@ -1611,16 +1611,16 @@
}, },
{ {
"name": "symfony/http-foundation", "name": "symfony/http-foundation",
"version": "v5.4.0", "version": "v5.4.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/http-foundation.git", "url": "https://github.com/symfony/http-foundation.git",
"reference": "5ef86ac7927d2de08dc1e26eb91325f9ccbe6309" "reference": "5dad3780023a707f4c24beac7d57aead85c1ce3c"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/http-foundation/zipball/5ef86ac7927d2de08dc1e26eb91325f9ccbe6309", "url": "https://api.github.com/repos/symfony/http-foundation/zipball/5dad3780023a707f4c24beac7d57aead85c1ce3c",
"reference": "5ef86ac7927d2de08dc1e26eb91325f9ccbe6309", "reference": "5dad3780023a707f4c24beac7d57aead85c1ce3c",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1664,7 +1664,7 @@
"description": "Defines an object-oriented layer for the HTTP specification", "description": "Defines an object-oriented layer for the HTTP specification",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"support": { "support": {
"source": "https://github.com/symfony/http-foundation/tree/v5.4.0" "source": "https://github.com/symfony/http-foundation/tree/v5.4.1"
}, },
"funding": [ "funding": [
{ {
@ -1680,7 +1680,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2021-11-28T15:25:38+00:00" "time": "2021-12-09T12:46:57+00:00"
}, },
{ {
"name": "symfony/mime", "name": "symfony/mime",
@ -2564,16 +2564,16 @@
}, },
{ {
"name": "symfony/string", "name": "symfony/string",
"version": "v6.0.0", "version": "v6.0.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/string.git", "url": "https://github.com/symfony/string.git",
"reference": "ba727797426af0f587f4800566300bdc0cda0777" "reference": "0cfed595758ec6e0a25591bdc8ca733c1896af32"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/string/zipball/ba727797426af0f587f4800566300bdc0cda0777", "url": "https://api.github.com/repos/symfony/string/zipball/0cfed595758ec6e0a25591bdc8ca733c1896af32",
"reference": "ba727797426af0f587f4800566300bdc0cda0777", "reference": "0cfed595758ec6e0a25591bdc8ca733c1896af32",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2629,7 +2629,7 @@
"utf8" "utf8"
], ],
"support": { "support": {
"source": "https://github.com/symfony/string/tree/v6.0.0" "source": "https://github.com/symfony/string/tree/v6.0.1"
}, },
"funding": [ "funding": [
{ {
@ -2645,7 +2645,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2021-10-29T07:35:21+00:00" "time": "2021-12-08T15:13:44+00:00"
}, },
{ {
"name": "symfony/yaml", "name": "symfony/yaml",

13
lib/Document.php

@ -9,6 +9,7 @@ declare(strict_types=1);
namespace MensBeam\HTML\DOM; namespace MensBeam\HTML\DOM;
use MensBeam\HTML\DOM\Inner\{ use MensBeam\HTML\DOM\Inner\{
Document as InnerDocument, Document as InnerDocument,
NodeCache,
Reflection Reflection
}; };
use MensBeam\HTML\Parser; use MensBeam\HTML\Parser;
@ -22,6 +23,8 @@ use MensBeam\HTML\Parser\{
class Document extends Node implements \ArrayAccess { class Document extends Node implements \ArrayAccess {
use DocumentOrElement, NonElementParentNode, ParentNode; use DocumentOrElement, NonElementParentNode, ParentNode;
protected static ?NodeCache $cache = null;
protected string $_characterSet = 'UTF-8'; protected string $_characterSet = 'UTF-8';
protected string $_compatMode = 'CSS1Compat'; protected string $_compatMode = 'CSS1Compat';
protected string $_contentType = 'text/html'; protected string $_contentType = 'text/html';
@ -295,6 +298,16 @@ class Document extends Node implements \ArrayAccess {
} elseif ($charset !== 'UTF-8') { } elseif ($charset !== 'UTF-8') {
$this->_characterSet = Charset::fromCharset((string)$charset) ?? 'UTF-8'; $this->_characterSet = Charset::fromCharset((string)$charset) ?? 'UTF-8';
} }
// This cache is used to prevent "must not be accessed before initialization"
// errors because of PHP's garbage... garbage collection.
if (self::$cache === null) {
// Pcov for some reason doesn't mark this line as being covered when it clearly
// is...
self::$cache = new NodeCache(); //@codeCoverageIgnore
}
self::$cache->set($this, $this->innerNode);
} }

21
tests/cases/TestProcessingInstruction.php

@ -0,0 +1,21 @@
<?php
/**
* @license MIT
* Copyright 2017 Dustin Wilson, J. King, et al.
* See LICENSE and AUTHORS files for details
*/
declare(strict_types=1);
namespace MensBeam\HTML\DOM\TestCase;
use MensBeam\HTML\DOM\Document;
/** @covers \MensBeam\HTML\DOM\ProcessingInstruction */
class TestProcessingInstruction extends \PHPUnit\Framework\TestCase {
public function testProperty_target(): void {
$d = new Document();
$this->assertSame('ook', $d->createProcessingInstruction('ook', 'eek')->target);
$this->assertSame('poop💩', $d->createProcessingInstruction('poop💩', 'poop💩')->target);
}
}

21
tests/cases/TestSerializer.php

@ -0,0 +1,21 @@
<?php
/**
* @license MIT
* Copyright 2017 Dustin Wilson, J. King, et al.
* See LICENSE and AUTHORS files for details
*/
declare(strict_types=1);
namespace MensBeam\HTML\DOM\TestCase;
use MensBeam\HTML\DOM;
use MensBeam\HTML\DOM\{
Document,
DocumentFragment,
Node
};
/** @covers \MensBeam\HTML\DOM\Serializer */
class TestSerializer extends \PHPUnit\Framework\TestCase {
}

4
tests/phpunit.dist.xml

@ -31,6 +31,10 @@
<file>cases/TestNode.php</file> <file>cases/TestNode.php</file>
<file>cases/TestNonDocumentTypeChildNode.php</file> <file>cases/TestNonDocumentTypeChildNode.php</file>
<file>cases/TestParentNode.php</file> <file>cases/TestParentNode.php</file>
<file>cases/TestProcessingInstruction.php</file>
</testsuite> </testsuite>
<!--<testsuite name="Serializer">
<file>cases/TestSerializer.php</file>
</testsuite>-->
</testsuites> </testsuites>
</phpunit> </phpunit>

Loading…
Cancel
Save