Skip to content

Commit f4b2246

Browse files
committed
Apply manual changes to make QA tools happy
1 parent b3c09ef commit f4b2246

35 files changed

+145
-88
lines changed

.github/workflows/analyzers.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ jobs:
2929
run: composer update --prefer-dist --no-progress --no-suggest ${{ matrix.composer-options }}
3030
- name: Run the tests
3131
run: composer run psalm
32+
continue-on-error: ${{ matrix.php-versions == '8.5' }}

.github/workflows/tests.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,3 @@ jobs:
3232
run: composer run tests
3333
- name: Check tests quality
3434
run: composer run testquality
35-
continue-on-error: ${{ matrix.php-versions == '8.4' }} # Infection is not ready yet.

infection.json.dist

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
},
77
"minMsi": 100,
88
"minCoveredMsi": 100,
9-
"phpUnit": {
10-
"customPath": ".\/tools\/phpunit.phar"
11-
},
129
"logs": {
1310
"text": ".phpunit.cache/infection.log",
1411
"html": ".phpunit.cache/infection"

phpunit.xml

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
5-
bootstrap="tests/bootstrap.php"
6-
executionOrder="random"
7-
forceCoversAnnotation="false"
8-
beStrictAboutCoversAnnotation="false"
9-
beStrictAboutOutputDuringTests="true"
10-
beStrictAboutTodoAnnotatedTests="true"
11-
verbose="true"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
5+
bootstrap="tests/bootstrap.php"
6+
executionOrder="random"
7+
beStrictAboutCoverageMetadata="false"
8+
beStrictAboutOutputDuringTests="true"
9+
displayDetailsOnTestsThatTriggerWarnings="true"
10+
failOnWarning="true"
11+
failOnPhpunitWarning="true"
1212
>
13-
<coverage cacheDirectory=".phpunit.cache/code-coverage"
14-
processUncoveredFiles="true">
15-
<include>
16-
<directory suffix=".php">src</directory>
17-
</include>
18-
<exclude>
19-
<file>src/bootstrap.php</file>
20-
</exclude>
21-
<report>
22-
<clover outputFile=".phpunit.cache/clover/clover.xml" />
23-
<html outputDirectory=".phpunit.cache/report" lowUpperBound="99" highLowerBound="99" />
24-
</report>
25-
</coverage>
26-
<testsuites>
27-
<testsuite name="default">
28-
<directory suffix="Test.php">tests/Xml</directory>
29-
</testsuite>
30-
</testsuites>
13+
<source>
14+
<include>
15+
<directory suffix=".php">src</directory>
16+
</include>
17+
<exclude>
18+
<file>src/bootstrap.php</file>
19+
</exclude>
20+
</source>
21+
22+
<coverage includeUncoveredFiles="true">
23+
<report>
24+
<clover outputFile=".phpunit.cache/clover/clover.xml"/>
25+
<html outputDirectory=".phpunit.cache/report" lowUpperBound="99" highLowerBound="99"/>
26+
</report>
27+
</coverage>
28+
29+
<testsuites>
30+
<testsuite name="default">
31+
<directory suffix="Test.php">tests/Xml</directory>
32+
</testsuite>
33+
</testsuites>
3134
</phpunit>

psalm.xml

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,13 @@
1717
>
1818
<projectFiles>
1919
<directory name="src" />
20-
<directory name="tests" />
2120
<ignoreFiles>
21+
<directory name="tests" />
2222
<directory name="vendor" />
2323
<file name="src/bootstrap.php"/>
2424
</ignoreFiles>
2525
</projectFiles>
2626
<issueHandlers>
27-
<MissingConstructor>
28-
<errorLevel type="suppress">
29-
<directory name="tests"/>
30-
</errorLevel>
31-
</MissingConstructor>
32-
<UndefinedClass>
33-
<errorLevel type="suppress">
34-
<directory name="tests"/>
35-
</errorLevel>
36-
</UndefinedClass>
37-
<MissingDependency>
38-
<errorLevel type="suppress">
39-
<directory name="tests"/>
40-
</errorLevel>
41-
</MissingDependency>
4227
<MixedArgumentTypeCoercion>
4328
<errorLevel type="suppress">
4429
<directory name="src/Xml/Encoding/Internal/Encoder/Builder" />
@@ -49,6 +34,7 @@
4934
<file name="stubs/DOM.phpstub" />
5035
<file name="stubs/XMLReader.phpstub" />
5136
<file name="stubs/XMLWriter.phpstub" />
37+
<file name="stubs/XSLTProcessor.phpstub" />
5238
</stubs>
5339
<plugins>
5440
<pluginClass class="Psl\Psalm\Plugin" />

src/Xml/Dom/Xpath/Locator/query_single.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ static function (DOMXPath $xpath) use ($query, $node): DOMNode {
4141
1,
4242
format('Expected to find only one node that matches %s. Got %s', $query, count($list))
4343
);
44+
$node = $list->item(0);
45+
Assert::notNull($node);
4446

45-
return $list->item(0);
47+
return $node;
4648
};
4749
}

src/Xml/Reader/Configurator/xsd_schema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function xsd_schema(string $schemaFile): Closure
2020
Assert::fileExists($schemaFile);
2121

2222
disallow_libxml_false_returns(
23-
$reader->setSchema($schemaFile),
23+
@$reader->setSchema($schemaFile),
2424
'Unable to apply XSD schema to the XML Reader.'
2525
);
2626

src/Xml/Xslt/Transformer/document_to_string.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ function document_to_string(Document $document): Closure
1717
{
1818
return static fn (XSLTProcessor $processor): string => disallow_issues(
1919
static function () use ($document, $processor): string {
20-
// Result can also be null ... undocumentedly!
2120
return (string) disallow_libxml_false_returns(
2221
$processor->transformToXML($document->toUnsafeDocument()),
2322
'Unable to apply the XSLT template'

stubs/XSLTProcessor.phpstub

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
class XSLTProcessor
3+
{
4+
/**
5+
* Transform to XML
6+
* @link https://php.net/manual/en/xsltprocessor.transformtoxml.php
7+
* @param DOMDocument|SimpleXMLElement $document <p>
8+
* The transformed document.
9+
* </p>
10+
* @return string|false|null The result of the transformation as a string or <b>FALSE</b> on error.
11+
*/
12+
public function transformToXml($document): string|false|null {}
13+
14+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace VeeWee\Tests\Xml\Dom\Assert;
6+
7+
use DOMNode;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use PHPUnit\Framework\TestCase;
10+
use Psl\Type\Exception\AssertException;
11+
use VeeWee\Xml\Dom\Document;
12+
use function VeeWee\Xml\Dom\Assert\assert_attribute;
13+
14+
final class AssertAttributeTest extends TestCase
15+
{
16+
#[DataProvider('provideTestCases')]
17+
public function test_it_knows_attributes(?DOMNode $node, bool $expected): void
18+
{
19+
if (!$expected) {
20+
$this->expectException(AssertException::class);
21+
}
22+
23+
$actual = assert_attribute($node);
24+
static::assertSame($node, $actual);
25+
}
26+
27+
public static function provideTestCases()
28+
{
29+
$doc = Document::fromXmlString(
30+
<<<EOXML
31+
<doc>
32+
<item attr="val">Hello</item>
33+
</doc>
34+
EOXML
35+
)->toUnsafeDocument();
36+
37+
yield [$doc, false];
38+
yield [$doc->documentElement, false];
39+
yield [$doc->documentElement->firstElementChild, false];
40+
yield [$doc->documentElement->firstElementChild->attributes->getNamedItem('attr'), true];
41+
yield [$doc->documentElement->firstElementChild->firstChild, false];
42+
yield [null, false];
43+
}
44+
}

0 commit comments

Comments
 (0)