Skip to content

Commit 961f5d2

Browse files
committed
Add tests for get_post().
1 parent d5e6263 commit 961f5d2

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

tests/data/get_post.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SzepeViktor\PHPStan\WordPress\Tests;
6+
7+
use function PHPStan\Testing\assertType;
8+
9+
// Default output
10+
assertType('WP_Post|null', get_post(1));
11+
assertType('WP_Post|null', get_post(1,OBJECT));
12+
assertType('WP_Post|null', get_post(1,'Hello'));
13+
14+
// Unknown output
15+
assertType('array|\WP_Post|null', get_post(1,_GET['foo']));
16+
17+
// Associative array output
18+
assertType('array<string, mixed>|null', get_post(1,ARRAY_A));
19+
20+
// Numeric array output
21+
assertType('array<int, mixed>|null', get_post(1,ARRAY_N));

tests/testTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function dataFileAsserts(): iterable
1717
// path to a file with actual asserts of expected types:
1818
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_comment.php');
1919
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_object_taxonomies.php');
20+
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_post.php');
2021
yield from $this->gatherAssertTypes(__DIR__ . '/data/mysql2date.php');
2122
}
2223

0 commit comments

Comments
 (0)