Skip to content

Commit a7b1567

Browse files
authored
PHPLIB-951: Assert operation before argument validation (#999)
This prevents a potential PHP warning for accessing a nonexistent array key if the operation doesn't exist, which was responsible for some Astrolabe test failures. Since assertArgumentsBySchema() is called before the switch statement in Operation execute methods, we don't yet know that the operation exists. With this change, we should never hit default cases in those switch statements; however, they can remain in place for now.
1 parent 5a3d371 commit a7b1567

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

tests/UnifiedSpecTests/Util.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use function array_key_exists;
2121
use function array_keys;
2222
use function implode;
23+
use function PHPUnit\Framework\assertArrayHasKey;
2324
use function PHPUnit\Framework\assertContains;
2425
use function PHPUnit\Framework\assertEmpty;
2526
use function PHPUnit\Framework\assertIsArray;
@@ -141,6 +142,8 @@ public static function assertHasOnlyKeys($arrayOrObject, array $keys): void
141142

142143
public static function assertArgumentsBySchema(string $executingObjectName, string $operation, array $args): void
143144
{
145+
assertArrayHasKey($executingObjectName, self::$args);
146+
assertArrayHasKey($operation, self::$args[$executingObjectName]);
144147
self::assertHasOnlyKeys($args, self::$args[$executingObjectName][$operation]);
145148
}
146149

0 commit comments

Comments
 (0)