diff --git a/README.md b/README.md index 0bac947..dd65519 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ This extension specifies types of values passed to: * `Assert::integer` * `Assert::string` +* `Assert::stringNotEmpty` * `Assert::float` * `Assert::numeric` * `Assert::boolean` diff --git a/src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php b/src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php index 90638cf..01b64cc 100644 --- a/src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php +++ b/src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php @@ -180,6 +180,12 @@ private static function getExpressionResolvers(): array [$value] ); }, + 'stringNotEmpty' => function (Scope $scope, Arg $value): ?\PhpParser\Node\Expr { + return new \PhpParser\Node\Expr\FuncCall( + new \PhpParser\Node\Name('is_string'), + [$value] + ); + }, 'float' => function (Scope $scope, Arg $value): ?\PhpParser\Node\Expr { return new \PhpParser\Node\Expr\FuncCall( new \PhpParser\Node\Name('is_float'), diff --git a/tests/Type/WebMozartAssert/AssertTypeSpecifyingExtensionTest.php b/tests/Type/WebMozartAssert/AssertTypeSpecifyingExtensionTest.php index 94434f6..b4df375 100644 --- a/tests/Type/WebMozartAssert/AssertTypeSpecifyingExtensionTest.php +++ b/tests/Type/WebMozartAssert/AssertTypeSpecifyingExtensionTest.php @@ -145,6 +145,10 @@ public function testExtension(): void 'Variable $ab is: array', 113, ], + [ + 'Variable $ac is: string', + 116, + ], ]); } diff --git a/tests/Type/WebMozartAssert/data/data.php b/tests/Type/WebMozartAssert/data/data.php index 080e119..b6288f5 100644 --- a/tests/Type/WebMozartAssert/data/data.php +++ b/tests/Type/WebMozartAssert/data/data.php @@ -7,7 +7,7 @@ class Foo { - public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k, $l, $m, $n, $o, $p, $r, $s, ?int $t, ?int $u, $x, $aa, array $ab) + public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k, $l, $m, $n, $o, $p, $r, $s, ?int $t, ?int $u, $x, $aa, array $ab, $ac) { $a; @@ -111,6 +111,9 @@ public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k, Assert::allSubclassOf($ab, self::class); $ab; + + Assert::stringNotEmpty($ac); + $ac; } }