Skip to content

Commit

Permalink
Merge pull request #9139 from jack-worman/Fix_dom_import_simplexml
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed Jan 19, 2023
2 parents 396e7fc + 787b9ae commit 5d6dff9
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
4 changes: 0 additions & 4 deletions stubs/extensions/dom.phpstub
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ const DOM_NAMESPACE_ERR = 14;
const DOM_INVALID_ACCESS_ERR = 15;
const DOM_VALIDATION_ERR = 16;

function dom_import_simplexml(object $node): ?DOMElement {}
/** @php-from 8.0 */
function dom_import_simplexml(object $node): DOMElement {}

final class DOMException extends Exception
{
public int $code;
Expand Down
51 changes: 51 additions & 0 deletions tests/ExtLibxmlStubTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

namespace Psalm\Tests;

use Psalm\Tests\Traits\InvalidCodeAnalysisTestTrait;
use Psalm\Tests\Traits\ValidCodeAnalysisTestTrait;

class ExtLibxmlStubTest extends TestCase
{
use ValidCodeAnalysisTestTrait;
use InvalidCodeAnalysisTestTrait;

public function providerValidCodeParse(): iterable
{
return [
'dom_import_simplexml, php >=8.0' => [
'code' => <<<'PHP'
<?php
$x = dom_import_simplexml(new SimpleXMLElement(''));
PHP,
'assertions' => ['$x===' => 'DOMElement'],
'ignored_issues' => [],
'php_version' => '8.0',
],
'dom_import_simplexml, php <8.0' => [
'code' => <<<'PHP'
<?php
$x = dom_import_simplexml(new SimpleXMLElement(''));
PHP,
'assertions' => ['$x===' => 'DOMElement|null'],
'ignored_issues' => [],
'php_version' => '7.4',
],
];
}

public function providerInvalidCodeParse(): iterable
{
return [
'dom_import_simplexml, $node arg' => [
'code' => <<<'PHP'
<?php
$x = dom_import_simplexml(new \stdClass());
PHP,
'error_message' => 'InvalidArgument',
],
];
}
}
10 changes: 9 additions & 1 deletion tests/Traits/InvalidCodeAnalysisTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@
trait InvalidCodeAnalysisTestTrait
{
/**
* @return iterable<string,array{code:string,error_message:string,ignored_issues?:list<string>,php_version?:string}>
* @return iterable<
* string,
* array{
* code: string,
* error_message: string,
* ignored_issues?: list<string>,
* php_version?: string,
* }
* >
*/
abstract public function providerInvalidCodeParse(): iterable;

Expand Down

0 comments on commit 5d6dff9

Please sign in to comment.