ProcessingInstruction 100% covered, added cache for documents
This commit is contained in:
parent
6eb07562da
commit
e5c8d526be
5 changed files with 78 additions and 19 deletions
38
composer.lock
generated
38
composer.lock
generated
|
@ -1445,23 +1445,23 @@
|
|||
},
|
||||
{
|
||||
"name": "symfony/console",
|
||||
"version": "v5.4.0",
|
||||
"version": "v5.4.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/console.git",
|
||||
"reference": "ec3661faca1d110d6c307e124b44f99ac54179e3"
|
||||
"reference": "9130e1a0fc93cb0faadca4ee917171bd2ca9e5f4"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/console/zipball/ec3661faca1d110d6c307e124b44f99ac54179e3",
|
||||
"reference": "ec3661faca1d110d6c307e124b44f99ac54179e3",
|
||||
"url": "https://api.github.com/repos/symfony/console/zipball/9130e1a0fc93cb0faadca4ee917171bd2ca9e5f4",
|
||||
"reference": "9130e1a0fc93cb0faadca4ee917171bd2ca9e5f4",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.2.5",
|
||||
"symfony/deprecation-contracts": "^2.1|^3",
|
||||
"symfony/polyfill-mbstring": "~1.0",
|
||||
"symfony/polyfill-php73": "^1.8",
|
||||
"symfony/polyfill-php73": "^1.9",
|
||||
"symfony/polyfill-php80": "^1.16",
|
||||
"symfony/service-contracts": "^1.1|^2|^3",
|
||||
"symfony/string": "^5.1|^6.0"
|
||||
|
@ -1524,7 +1524,7 @@
|
|||
"terminal"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/console/tree/v5.4.0"
|
||||
"source": "https://github.com/symfony/console/tree/v5.4.1"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -1540,7 +1540,7 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2021-11-29T15:30:56+00:00"
|
||||
"time": "2021-12-09T11:22:43+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/deprecation-contracts",
|
||||
|
@ -1611,16 +1611,16 @@
|
|||
},
|
||||
{
|
||||
"name": "symfony/http-foundation",
|
||||
"version": "v5.4.0",
|
||||
"version": "v5.4.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/http-foundation.git",
|
||||
"reference": "5ef86ac7927d2de08dc1e26eb91325f9ccbe6309"
|
||||
"reference": "5dad3780023a707f4c24beac7d57aead85c1ce3c"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/http-foundation/zipball/5ef86ac7927d2de08dc1e26eb91325f9ccbe6309",
|
||||
"reference": "5ef86ac7927d2de08dc1e26eb91325f9ccbe6309",
|
||||
"url": "https://api.github.com/repos/symfony/http-foundation/zipball/5dad3780023a707f4c24beac7d57aead85c1ce3c",
|
||||
"reference": "5dad3780023a707f4c24beac7d57aead85c1ce3c",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1664,7 +1664,7 @@
|
|||
"description": "Defines an object-oriented layer for the HTTP specification",
|
||||
"homepage": "https://symfony.com",
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/http-foundation/tree/v5.4.0"
|
||||
"source": "https://github.com/symfony/http-foundation/tree/v5.4.1"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -1680,7 +1680,7 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2021-11-28T15:25:38+00:00"
|
||||
"time": "2021-12-09T12:46:57+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/mime",
|
||||
|
@ -2564,16 +2564,16 @@
|
|||
},
|
||||
{
|
||||
"name": "symfony/string",
|
||||
"version": "v6.0.0",
|
||||
"version": "v6.0.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/string.git",
|
||||
"reference": "ba727797426af0f587f4800566300bdc0cda0777"
|
||||
"reference": "0cfed595758ec6e0a25591bdc8ca733c1896af32"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/string/zipball/ba727797426af0f587f4800566300bdc0cda0777",
|
||||
"reference": "ba727797426af0f587f4800566300bdc0cda0777",
|
||||
"url": "https://api.github.com/repos/symfony/string/zipball/0cfed595758ec6e0a25591bdc8ca733c1896af32",
|
||||
"reference": "0cfed595758ec6e0a25591bdc8ca733c1896af32",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -2629,7 +2629,7 @@
|
|||
"utf8"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/string/tree/v6.0.0"
|
||||
"source": "https://github.com/symfony/string/tree/v6.0.1"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -2645,7 +2645,7 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2021-10-29T07:35:21+00:00"
|
||||
"time": "2021-12-08T15:13:44+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/yaml",
|
||||
|
|
|
@ -9,6 +9,7 @@ declare(strict_types=1);
|
|||
namespace MensBeam\HTML\DOM;
|
||||
use MensBeam\HTML\DOM\Inner\{
|
||||
Document as InnerDocument,
|
||||
NodeCache,
|
||||
Reflection
|
||||
};
|
||||
use MensBeam\HTML\Parser;
|
||||
|
@ -22,6 +23,8 @@ use MensBeam\HTML\Parser\{
|
|||
class Document extends Node implements \ArrayAccess {
|
||||
use DocumentOrElement, NonElementParentNode, ParentNode;
|
||||
|
||||
|
||||
protected static ?NodeCache $cache = null;
|
||||
protected string $_characterSet = 'UTF-8';
|
||||
protected string $_compatMode = 'CSS1Compat';
|
||||
protected string $_contentType = 'text/html';
|
||||
|
@ -295,6 +298,16 @@ class Document extends Node implements \ArrayAccess {
|
|||
} elseif ($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
Normal file
21
tests/cases/TestProcessingInstruction.php
Normal file
|
@ -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
Normal file
21
tests/cases/TestSerializer.php
Normal file
|
@ -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 {
|
||||
}
|
|
@ -31,6 +31,10 @@
|
|||
<file>cases/TestNode.php</file>
|
||||
<file>cases/TestNonDocumentTypeChildNode.php</file>
|
||||
<file>cases/TestParentNode.php</file>
|
||||
<file>cases/TestProcessingInstruction.php</file>
|
||||
</testsuite>
|
||||
<!--<testsuite name="Serializer">
|
||||
<file>cases/TestSerializer.php</file>
|
||||
</testsuite>-->
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
|
|
Loading…
Reference in a new issue