|
9 | 9 | use TheCodingMachine\Tdbm\GraphQL\Fixtures\TestSchema; |
10 | 10 | use TheCodingMachine\Tdbm\GraphQL\Registry\EmptyContainer; |
11 | 11 | use TheCodingMachine\Tdbm\GraphQL\Registry\Registry; |
| 12 | +use TheCodingMachine\Tdbm\GraphQL\Tests\Beans\Country; |
| 13 | +use TheCodingMachine\Tdbm\GraphQL\Tests\DAOs\CountryDao; |
12 | 14 | use TheCodingMachine\Tdbm\GraphQL\Tests\DAOs\UserDao; |
| 15 | +use TheCodingMachine\Tdbm\GraphQL\Tests\GraphQL\CountryType; |
13 | 16 | use TheCodingMachine\Tdbm\GraphQL\Tests\GraphQL\Generated\AbstractCountryType; |
14 | 17 | use TheCodingMachine\Tdbm\GraphQL\Tests\GraphQL\Generated\AbstractUserType; |
15 | 18 | use TheCodingMachine\Tdbm\GraphQL\Tests\GraphQL\TdbmGraphQLTypeMapper; |
16 | 19 | use TheCodingMachine\TDBM\TDBMService; |
17 | 20 | use TheCodingMachine\TDBM\Utils\DefaultNamingStrategy as TdbmDefaultNamingStrategy; |
18 | 21 | use PHPUnit\Framework\TestCase; |
| 22 | +use Youshido\GraphQL\Execution\Context\ExecutionContext; |
19 | 23 | use Youshido\GraphQL\Execution\Processor; |
| 24 | +use Youshido\GraphQL\Execution\ResolveInfo; |
| 25 | +use Youshido\GraphQL\Schema\Schema; |
20 | 26 | use Youshido\GraphQL\Type\Scalar\StringType; |
21 | 27 |
|
22 | 28 | class GraphQLTypeGeneratorTest extends TestCase |
@@ -182,4 +188,32 @@ private function recursiveDelete(string $str) : bool |
182 | 188 | } |
183 | 189 | return false; |
184 | 190 | } |
| 191 | + |
| 192 | + public function testResultIteratorType() |
| 193 | + { |
| 194 | + $type = new ResultIteratorType(new CountryType(new Registry(new EmptyContainer()))); |
| 195 | + |
| 196 | + $tdbmService = self::getTDBMService(); |
| 197 | + $countryDao = new CountryDao($tdbmService); |
| 198 | + |
| 199 | + $countries = $countryDao->findAll(); |
| 200 | + |
| 201 | + $countField = $type->getField('count'); |
| 202 | + $resolveInfo = $this->getMockBuilder(ResolveInfo::class)->disableOriginalConstructor()->getMock(); |
| 203 | + $this->assertEquals(3, $countField->resolve($countries, [], $resolveInfo)); |
| 204 | + |
| 205 | + $itemsField = $type->getField('items'); |
| 206 | + $result = $itemsField->resolve($countries, [], $resolveInfo); |
| 207 | + $this->assertCount(3, $result); |
| 208 | + $this->assertInstanceOf(Country::class, $result[0]); |
| 209 | + |
| 210 | + $result = $itemsField->resolve($countries, ['order'=>'label'], $resolveInfo); |
| 211 | + $this->assertEquals('Jamaica', $result[1]->getLabel()); |
| 212 | + |
| 213 | + $result = $itemsField->resolve($countries, ['offset'=>1, 'limit'=>1], $resolveInfo); |
| 214 | + $this->assertCount(1, $result); |
| 215 | + |
| 216 | + $this->expectException(GraphQLException::class); |
| 217 | + $result = $itemsField->resolve($countries, ['offset'=>1], $resolveInfo); |
| 218 | + } |
185 | 219 | } |
0 commit comments