1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 17:52:45 +01:00
psalm/tests/DateTimeTest.php

94 lines
3.0 KiB
PHP
Raw Normal View History

<?php
namespace Psalm\Tests;
use Psalm\Tests\Traits\ValidCodeAnalysisTestTrait;
class DateTimeTest extends TestCase
{
use ValidCodeAnalysisTestTrait;
public function providerValidCodeParse(): iterable
{
return [
'modify' => [
2022-10-16 13:59:15 +02:00
'code' => '<?php
function getString(): string
{
return "";
}
$datetime = new DateTime();
$dateTimeImmutable = new DateTimeImmutable();
$a = $datetime->modify(getString());
$b = $dateTimeImmutable->modify(getString());
',
'assertions' => [
'$a' => 'DateTime|false',
'$b' => 'DateTimeImmutable|false',
],
],
'modifyWithValidConstant' => [
2022-10-16 13:59:15 +02:00
'code' => '<?php
/**
* @return "+1 day"|"+2 day"
*/
function getString(): string
{
return "+1 day";
}
$datetime = new DateTime();
$dateTimeImmutable = new DateTimeImmutable();
$a = $datetime->modify(getString());
$b = $dateTimeImmutable->modify(getString());
',
'assertions' => [
'$a' => 'DateTime',
'$b' => 'DateTimeImmutable',
],
],
'modifyWithInvalidConstant' => [
2022-10-16 13:59:15 +02:00
'code' => '<?php
/**
* @return "foo"|"bar"
*/
function getString(): string
{
return "foo";
}
$datetime = new DateTime();
$dateTimeImmutable = new DateTimeImmutable();
$a = $datetime->modify(getString());
$b = $dateTimeImmutable->modify(getString());
',
'assertions' => [
'$a' => 'false',
'$b' => 'false',
],
],
'modifyWithBothConstant' => [
2022-10-16 13:59:15 +02:00
'code' => '<?php
/**
* @return "+1 day"|"bar"
*/
function getString(): string
{
return "+1 day";
}
$datetime = new DateTime();
$dateTimeImmutable = new DateTimeImmutable();
$a = $datetime->modify(getString());
$b = $dateTimeImmutable->modify(getString());
',
'assertions' => [
'$a' => 'DateTime|false',
'$b' => 'DateTimeImmutable|false',
],
],
];
}
}