mirror of
https://github.com/retailcrm/graphql-php.git
synced 2025-02-14 11:33:13 +03:00
Add Mutation Promise tests
This commit is contained in:
parent
2ad79adf0c
commit
7f1e9d051b
@ -1,16 +1,29 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace GraphQL\Tests\Executor;
|
namespace GraphQL\Tests\Executor;
|
||||||
|
|
||||||
|
use GraphQL\Executor\ExecutionResult;
|
||||||
use GraphQL\Executor\Executor;
|
use GraphQL\Executor\Executor;
|
||||||
use GraphQL\Error\FormattedError;
|
use GraphQL\Error\FormattedError;
|
||||||
|
use GraphQL\Executor\Promise\Adapter\ReactPromiseAdapter;
|
||||||
use GraphQL\Language\Parser;
|
use GraphQL\Language\Parser;
|
||||||
use GraphQL\Language\SourceLocation;
|
use GraphQL\Language\SourceLocation;
|
||||||
use GraphQL\Schema;
|
use GraphQL\Schema;
|
||||||
use GraphQL\Type\Definition\ObjectType;
|
use GraphQL\Type\Definition\ObjectType;
|
||||||
use GraphQL\Type\Definition\Type;
|
use GraphQL\Type\Definition\Type;
|
||||||
|
use React\Promise\Promise;
|
||||||
|
|
||||||
class MutationsTest extends \PHPUnit_Framework_TestCase
|
class MutationsTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
public static function setUpBeforeClass()
|
||||||
|
{
|
||||||
|
Executor::setPromiseAdapter(new ReactPromiseAdapter());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function tearDownAfterClass()
|
||||||
|
{
|
||||||
|
Executor::setPromiseAdapter(null);
|
||||||
|
}
|
||||||
|
|
||||||
// Execute: Handles mutation execution ordering
|
// Execute: Handles mutation execution ordering
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,7 +69,7 @@ class MutationsTest extends \PHPUnit_Framework_TestCase
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
$this->assertEquals($expected, $mutationResult->toArray());
|
$this->assertEquals($expected, self::awaitPromise($mutationResult));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -114,7 +127,20 @@ class MutationsTest extends \PHPUnit_Framework_TestCase
|
|||||||
)
|
)
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
$this->assertArraySubset($expected, $mutationResult->toArray());
|
$this->assertArraySubset($expected, self::awaitPromise($mutationResult));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \GraphQL\Executor\Promise\Promise $promise
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private static function awaitPromise($promise)
|
||||||
|
{
|
||||||
|
$results = null;
|
||||||
|
$promise->then(function (ExecutionResult $executionResult) use (&$results) {
|
||||||
|
$results = $executionResult->toArray();
|
||||||
|
});
|
||||||
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function schema()
|
private function schema()
|
||||||
@ -200,12 +226,14 @@ class Root {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $newNumber
|
* @param $newNumber
|
||||||
* @return NumberHolder
|
*
|
||||||
|
* @return Promise
|
||||||
*/
|
*/
|
||||||
public function promiseToChangeTheNumber($newNumber)
|
public function promiseToChangeTheNumber($newNumber)
|
||||||
{
|
{
|
||||||
// No promises
|
return new Promise(function (callable $resolve) use ($newNumber) {
|
||||||
return $this->immediatelyChangeTheNumber($newNumber);
|
return $resolve($this->immediatelyChangeTheNumber($newNumber));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -217,11 +245,12 @@ class Root {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws \Exception
|
* @return Promise
|
||||||
*/
|
*/
|
||||||
public function promiseAndFailToChangeTheNumber()
|
public function promiseAndFailToChangeTheNumber()
|
||||||
{
|
{
|
||||||
// No promises
|
return new Promise(function (callable $resolve, callable $reject) {
|
||||||
throw new \Exception("Cannot change the number");
|
return $reject(new \Exception("Cannot change the number"));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user