Skip to content

Commit

Permalink
Merge pull request #82 from herndlm/feature/add-shortcode-atts-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
szepeviktor authored Nov 17, 2021
2 parents eacbcbd + 3d0f201 commit a90b660
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/DynamicReturnTypeExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_object_taxonomies.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/get_post.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/mysql2date.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/shortcode_atts.php');
}

/**
Expand Down
17 changes: 17 additions & 0 deletions tests/data/shortcode_atts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace SzepeViktor\PHPStan\WordPress\Tests;

use function PHPStan\Testing\assertType;

$atts = $_GET['atts'] ?? [];

// shortcode_atts filters atts by returning all atts that are occurring in the pairs
// As atts are supposed to be strings the function is expected to return the pair type or a string

assertType('array{}', shortcode_atts([], $atts));
assertType('array{foo: string, bar: string}', shortcode_atts(['foo' => '', 'bar' => ''], $atts));
assertType('array{foo: string, bar: 19|string}', shortcode_atts(['foo' => 'foo-value', 'bar' => 19], $atts));
assertType('array{foo: string|null, bar: 17|string, baz: string}', shortcode_atts(['foo' => null, 'bar' => 17, 'baz' => ''], $atts));

0 comments on commit a90b660

Please sign in to comment.