Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dom_import_simplexml() #9139

Merged
merged 1 commit into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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