-
Notifications
You must be signed in to change notification settings - Fork 457
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch refs/heads/1.11.x into 1.12.x
- Loading branch information
Showing
6 changed files
with
240 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
tests/PHPStan/Type/Php/CurlInitReturnTypeExtensionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Type\Php; | ||
|
||
use PHPStan\Testing\TypeInferenceTestCase; | ||
use const PHP_VERSION_ID; | ||
|
||
class CurlInitReturnTypeExtensionTest extends TypeInferenceTestCase | ||
{ | ||
|
||
public static function dataFileAsserts(): iterable | ||
{ | ||
if (PHP_VERSION_ID < 80000) { | ||
yield from self::gatherAssertTypes(__DIR__ . '/data/curl-init-php-7.php'); | ||
} else { | ||
yield from self::gatherAssertTypes(__DIR__ . '/data/curl-init-php-8.php'); | ||
} | ||
} | ||
|
||
/** | ||
* @dataProvider dataFileAsserts | ||
*/ | ||
public function testFileAsserts( | ||
string $assertType, | ||
string $file, | ||
mixed ...$args, | ||
): void | ||
{ | ||
$this->assertFileAsserts($assertType, $file, ...$args); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace CurlInitReturnTypeExtensionTestPhp7; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
function (string $unknownString) { | ||
assertType('resource', curl_init()); | ||
assertType('resource', curl_init('https://phpstan.org')); | ||
assertType('resource|false', curl_init($unknownString)); | ||
assertType('resource', curl_init(null)); | ||
assertType('resource', curl_init('')); | ||
assertType('resource|false', curl_init(':')); | ||
assertType('resource|false', curl_init('file://host/text.txt')); | ||
assertType('resource|false', curl_init('FIle://host/text.txt')); | ||
assertType('resource', curl_init('host/text.txt')); | ||
assertType('false', curl_init("\0")); | ||
assertType('false', curl_init("https://phpstan.org\0")); | ||
|
||
$url = 'https://phpstan.org'; | ||
if (rand(0,1)) $url = null; | ||
assertType('resource', curl_init($url)); | ||
|
||
$url = 'https://phpstan.org'; | ||
if (rand(0,1)) $url = 'https://phpstan.org/try'; | ||
assertType('resource', curl_init($url)); | ||
|
||
$url = 'https://phpstan.org'; | ||
if (rand(0,1)) $url = "\0"; | ||
assertType('resource|false', curl_init($url)); | ||
|
||
$url = 'https://phpstan.org'; | ||
if (rand(0,1)) $url = "https://phpstan.org\0"; | ||
assertType('resource|false', curl_init($url)); | ||
|
||
$url = 'https://phpstan.org'; | ||
if (rand(0,1)) $url = $unknownString; | ||
assertType('resource|false', curl_init($url)); | ||
|
||
$url = 'https://phpstan.org'; | ||
if (rand(0,1)) $url = ':'; | ||
assertType('resource|false', curl_init($url)); | ||
|
||
$url = 'https://phpstan.org'; | ||
if (rand(0,1)) $url = 'file://host/text.txt'; | ||
assertType('resource|false', curl_init($url)); | ||
|
||
$url = 'https://phpstan.org'; | ||
if (rand(0,1)) $url = 'FIle://host/text.txt'; | ||
assertType('resource|false', curl_init($url)); | ||
|
||
$url = 'https://phpstan.org'; | ||
if (rand(0,1)) $url = 'host/text.txt'; | ||
assertType('resource', curl_init($url)); | ||
|
||
$url = 'https://phpstan.org'; | ||
if (rand(0,1)) $url = 'file://host/text.txt'; | ||
if (rand(0,1)) $url = null; | ||
assertType('resource|false', curl_init($url)); | ||
|
||
$url = 'https://phpstan.org'; | ||
if (rand(0,1)) $url = null; | ||
if (rand(0,1)) $url = $unknownString; | ||
assertType('resource|false', curl_init($url)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace CurlInitReturnTypeExtensionTestPhp8; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
function (string $unknownString) { | ||
assertType('CurlHandle', curl_init()); | ||
assertType('CurlHandle', curl_init('https://phpstan.org')); | ||
assertType('CurlHandle|false', curl_init($unknownString)); | ||
assertType('CurlHandle', curl_init(null)); | ||
assertType('CurlHandle', curl_init('')); | ||
assertType('CurlHandle', curl_init(':')); | ||
assertType('CurlHandle', curl_init('file://host/text.txt')); | ||
assertType('CurlHandle', curl_init('FIle://host/text.txt')); | ||
assertType('CurlHandle', curl_init('host/text.txt')); | ||
assertType('*NEVER*', curl_init("\0")); | ||
assertType('*NEVER*', curl_init("https://phpstan.org\0")); | ||
|
||
$url = 'https://phpstan.org'; | ||
if (rand(0,1)) $url = null; | ||
assertType('CurlHandle', curl_init($url)); | ||
|
||
$url = 'https://phpstan.org'; | ||
if (rand(0,1)) $url = 'https://phpstan.org/try'; | ||
assertType('CurlHandle', curl_init($url)); | ||
|
||
$url = 'https://phpstan.org'; | ||
if (rand(0,1)) $url = "\0"; | ||
assertType('CurlHandle', curl_init($url)); | ||
|
||
$url = 'https://phpstan.org'; | ||
if (rand(0,1)) $url = "https://phpstan.org\0"; | ||
assertType('CurlHandle', curl_init($url)); | ||
|
||
$url = 'https://phpstan.org'; | ||
if (rand(0,1)) $url = $unknownString; | ||
assertType('CurlHandle|false', curl_init($url)); | ||
|
||
$url = 'https://phpstan.org'; | ||
if (rand(0,1)) $url .= $unknownString; | ||
assertType('CurlHandle|false', curl_init($url)); | ||
|
||
$url = 'https://phpstan.org'; | ||
if (rand(0,1)) $url = ':'; | ||
assertType('CurlHandle', curl_init($url)); | ||
|
||
$url = 'https://phpstan.org'; | ||
if (rand(0,1)) $url = 'file://host/text.txt'; | ||
assertType('CurlHandle', curl_init($url)); | ||
|
||
$url = 'https://phpstan.org'; | ||
if (rand(0,1)) $url = 'FIle://host/text.txt'; | ||
assertType('CurlHandle', curl_init($url)); | ||
|
||
$url = 'https://phpstan.org'; | ||
if (rand(0,1)) $url = 'host/text.txt'; | ||
assertType('CurlHandle', curl_init($url)); | ||
|
||
$url = 'https://phpstan.org'; | ||
if (rand(0,1)) $url = 'file://host/text.txt'; | ||
if (rand(0,1)) $url = null; | ||
assertType('CurlHandle', curl_init($url)); | ||
|
||
$url = 'https://phpstan.org'; | ||
if (rand(0,1)) $url = null; | ||
if (rand(0,1)) $url = $unknownString; | ||
assertType('CurlHandle|false', curl_init($url)); | ||
}; |