Skip to content

Commit

Permalink
PHPLIB-951: Assert operation before argument validation (#999)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jmikola committed Nov 1, 2022
1 parent 5a3d371 commit a7b1567
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/UnifiedSpecTests/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use function array_key_exists;
use function array_keys;
use function implode;
use function PHPUnit\Framework\assertArrayHasKey;
use function PHPUnit\Framework\assertContains;
use function PHPUnit\Framework\assertEmpty;
use function PHPUnit\Framework\assertIsArray;
Expand Down Expand Up @@ -141,6 +142,8 @@ public static function assertHasOnlyKeys($arrayOrObject, array $keys): void

public static function assertArgumentsBySchema(string $executingObjectName, string $operation, array $args): void
{
assertArrayHasKey($executingObjectName, self::$args);
assertArrayHasKey($operation, self::$args[$executingObjectName]);
self::assertHasOnlyKeys($args, self::$args[$executingObjectName][$operation]);
}

Expand Down

0 comments on commit a7b1567

Please sign in to comment.