Skip to content

Commit a90b660

Browse files
authored
Merge pull request #82 from herndlm/feature/add-shortcode-atts-tests
2 parents eacbcbd + 3d0f201 commit a90b660

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

tests/DynamicReturnTypeExtensionTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function dataFileAsserts(): iterable
2020
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_object_taxonomies.php');
2121
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_post.php');
2222
yield from $this->gatherAssertTypes(__DIR__ . '/data/mysql2date.php');
23+
yield from $this->gatherAssertTypes(__DIR__ . '/data/shortcode_atts.php');
2324
}
2425

2526
/**

tests/data/shortcode_atts.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SzepeViktor\PHPStan\WordPress\Tests;
6+
7+
use function PHPStan\Testing\assertType;
8+
9+
$atts = $_GET['atts'] ?? [];
10+
11+
// shortcode_atts filters atts by returning all atts that are occurring in the pairs
12+
// As atts are supposed to be strings the function is expected to return the pair type or a string
13+
14+
assertType('array{}', shortcode_atts([], $atts));
15+
assertType('array{foo: string, bar: string}', shortcode_atts(['foo' => '', 'bar' => ''], $atts));
16+
assertType('array{foo: string, bar: 19|string}', shortcode_atts(['foo' => 'foo-value', 'bar' => 19], $atts));
17+
assertType('array{foo: string|null, bar: 17|string, baz: string}', shortcode_atts(['foo' => null, 'bar' => 17, 'baz' => ''], $atts));

0 commit comments

Comments
 (0)