mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-23 05:16:05 +03:00
Merge pull request #89 from aldumas/assign_fix
Fixed Utils::assign() bug relating to detecting missing required keys
This commit is contained in:
commit
0bd7c9d405
@ -25,7 +25,7 @@ class Utils
|
|||||||
public static function assign($obj, array $vars, array $requiredKeys = [])
|
public static function assign($obj, array $vars, array $requiredKeys = [])
|
||||||
{
|
{
|
||||||
foreach ($requiredKeys as $key) {
|
foreach ($requiredKeys as $key) {
|
||||||
if (!isset($key, $vars)) {
|
if (!isset($vars[$key])) {
|
||||||
throw new InvalidArgumentException("Key {$key} is expected to be set and not to be null");
|
throw new InvalidArgumentException("Key {$key} is expected to be set and not to be null");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
22
tests/UtilsTest.php
Normal file
22
tests/UtilsTest.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
namespace GraphQL\Tests;
|
||||||
|
|
||||||
|
use GraphQL\Utils;
|
||||||
|
|
||||||
|
class UtilsTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testAssignThrowsExceptionOnMissingRequiredKey()
|
||||||
|
{
|
||||||
|
$object = new \stdClass();
|
||||||
|
$object->requiredKey = 'value';
|
||||||
|
|
||||||
|
try {
|
||||||
|
Utils::assign($object, [], ['requiredKey']);
|
||||||
|
$this->fail('Expected exception not thrown');
|
||||||
|
} catch (\InvalidArgumentException $e) {
|
||||||
|
$this->assertEquals(
|
||||||
|
"Key requiredKey is expected to be set and not to be null",
|
||||||
|
$e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user