|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: mounter |
|
5
|
|
|
* Date: 8/18/16 |
|
6
|
|
|
* Time: 2:17 PM |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Youshido\Tests\Performance; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
use Youshido\GraphQL\Execution\Processor; |
|
13
|
|
|
use Youshido\GraphQL\Schema\Schema; |
|
14
|
|
|
use Youshido\GraphQL\Type\ListType\ListType; |
|
15
|
|
|
use Youshido\GraphQL\Type\Object\ObjectType; |
|
16
|
|
|
use Youshido\GraphQL\Type\Scalar\IdType; |
|
17
|
|
|
use Youshido\GraphQL\Type\Scalar\StringType; |
|
18
|
|
|
|
|
19
|
|
|
class LoadTest extends \PHPUnit_Framework_TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
|
|
22
|
|
|
public function testLoad10k() |
|
23
|
|
|
{ |
|
24
|
|
|
$time = microtime(true); |
|
|
|
|
|
|
25
|
|
|
$postType = new ObjectType([ |
|
26
|
|
|
'name' => 'Post', |
|
27
|
|
|
'fields' => [ |
|
28
|
|
|
'id' => new IdType(), |
|
29
|
|
|
'title' => new StringType(), |
|
30
|
|
|
'authors' => [ |
|
31
|
|
|
'type' => new ListType(new ObjectType([ |
|
32
|
|
|
'name' => 'Author', |
|
33
|
|
|
'fields' => [ |
|
34
|
|
|
'name' => new StringType() |
|
35
|
|
|
] |
|
36
|
|
|
])) |
|
37
|
|
|
], |
|
38
|
|
|
] |
|
39
|
|
|
]); |
|
40
|
|
|
|
|
41
|
|
|
$data = []; |
|
42
|
|
|
for ($i = 1; $i <= 10000; ++$i) { |
|
43
|
|
|
$authors = []; |
|
44
|
|
|
while (count($authors) < rand(1, 4)) { |
|
45
|
|
|
$authors[] = [ |
|
46
|
|
|
'name' => 'Author ' . substr(md5(time()), 0, 4) |
|
47
|
|
|
]; |
|
48
|
|
|
} |
|
49
|
|
|
$data[] = [ |
|
50
|
|
|
'id' => $i, |
|
51
|
|
|
'title' => 'Title of ' . $i, |
|
52
|
|
|
'authors' => $authors, |
|
53
|
|
|
]; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$p = new Processor(new Schema([ |
|
|
|
|
|
|
57
|
|
|
'query' => new ObjectType([ |
|
58
|
|
|
'name' => 'RootQuery', |
|
59
|
|
|
'fields' => [ |
|
60
|
|
|
'posts' => [ |
|
61
|
|
|
'type' => new ListType($postType), |
|
62
|
|
|
'resolve' => function() use ($data) { |
|
63
|
|
|
return $data; |
|
64
|
|
|
} |
|
65
|
|
|
] |
|
66
|
|
|
], |
|
67
|
|
|
]), |
|
68
|
|
|
])); |
|
69
|
|
|
return true; |
|
70
|
|
|
$p->processPayload('{ posts { id, title, authors { name } } }'); |
|
|
|
|
|
|
71
|
|
|
$res = $p->getResponseData(); |
|
72
|
|
|
echo "Count: " . count($res['data']['posts']) . "\n"; |
|
73
|
|
|
var_dump($res['data']['posts'][0]); |
|
|
|
|
|
|
74
|
|
|
printf("Test Time: %04f\n", microtime(true) - $time); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
} |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.