
<pre class="wp-block-syntaxhighlighter-code">
<?php
namespace Modules\ThemeStore\Tests\Functional\GraphQl;
use Nuwave\Lighthouse\Testing\MakesGraphQLRequests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Nuwave\Lighthouse\Testing\ClearsSchemaCache;
use Tests\CreatesApplication;
class OnlineStoreThemeGraphQlApiTest extends BaseTestCase
{
use CreatesApplication,
ClearsSchemaCache,
MakesGraphQLRequests;
public function testGetThemeById(): void
{
$response = $this->graphQL('
{
query GetThemeById($id: ID!) {
onlineStoreTheme(themeId: $id) {
id
editable
createdAt
name
}
}
}
',
[
'id' => 'vogue',
]
);
$response->assertJson([
'data' => [
'onlineStoreTheme' => [
'id' => 'vogue'
],
],
]);
}
protected function setUp(): void
{
parent::setUp();
$this->bootClearsSchemaCache();
}
}
</pre>

PS E:\wwwroot\object> ./vendor/bin/phpunit .\Modules\ThemeStore\Tests\Functional\GraphQl\OnlineStoreThemeGraphQlApiTest.php
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.
F 1 / 1 (100%)
Time: 919 ms, Memory: 56.00 MB
There was 1 failure:
1) Modules\ThemeStore\Tests\Functional\GraphQl\OnlineStoreThemeGraphQlApiTest::testGetThemeById
Unable to find JSON:
[{
"data": {
"onlineStoreTheme": {
"id": "vogue"
}
}
}]
within response JSON:
[{
"errors": [
{
"message": "Syntax Error: Expected Name, found $",
"extensions": {
"category": "graphql"
},
"locations": [
{
"line": 3,
"column": 36
}
]
}
]
}].
Failed asserting that an array has the subset Array &0 (
'data' => Array &1 (
'onlineStoreTheme' => Array &2 (
'id' => 'vogue'
)
)
).
--- Expected
+++ Actual
@@ @@
),
),
),
- 'data' =>
- array (
- 'onlineStoreTheme' =>
- array (
- 'id' => 'vogue',
- ),
- ),
)
E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Assert.php:108
E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Foundation\Testing\TestResponse.php:479
E:\wwwroot\object\Modules\ThemeStore\Tests\Functional\GraphQl\OnlineStoreThemeGraphQlApiTest.php:38
phpvfscomposer://E:\wwwroot\object\vendor\phpunit\phpunit\phpunit:60
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
PS E:\wwwroot\object>
<pre class="wp-block-syntaxhighlighter-code">
<?php
namespace Tests\Feature;
use Nuwave\Lighthouse\Testing\MakesGraphQLRequests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Nuwave\Lighthouse\Testing\ClearsSchemaCache;
use Tests\CreatesApplication;
use App\Models\Post;
class PostsGraphQlApiTest extends BaseTestCase
{
use CreatesApplication,
ClearsSchemaCache,
MakesGraphQLRequests;
public function testQueriesPosts(): void
{
$post = Post::factory()->create();
$response = $this->graphQL('
{
posts {
id
title
content
}
}
');
$response->assertJson([
'data' => [
'posts' => [
[
'id' => $post->id,
'title' => $post->title,
'content' => $post->content,
]
],
],
]);
}
protected function setUp(): void
{
parent::setUp();
$this->bootClearsSchemaCache();
}
}
</pre>

{
"id": "104",
"title": "Tenetur id labore dolores aperiam.",
it vel ut corrupti repellat quaerat. Et eos exercitationem voluptatem ut."
},
{
"id": "105",
"title": "Incidunt nulla libero officia aliquam dolor ut.",
"content": "Molestiae harum velit numquam atque qui consequatur quam. Et sequi voluptatem sunt. Nemo et quo quod consequuntur. Quis eos consequatur recusandae in doloribus rerum odit odio."
}
]
}
}].
Failed asserting that an array has the subset Array &0 (
'data' => Array &1 (
'posts' => Array &2 (
0 => Array &3 (
'id' => 105
'title' => 'Incidunt nulla libero officia aliquam dolor ut.'
'content' => 'Molestiae harum velit numquam atque qui consequatur quam. Et sequi voluptatem sunt. Nemo et quo quod consequuntur. Quis eos consequatur recusandae in doloribus rerum odit odio.'
)
)
)
).
--- Expected
+++ Actual
array (
0 =>
array (
- 'id' => 105,
- 'title' => 'Incidunt nulla libero officia aliquam dolor ut.',
- 'content' => 'Molestiae harum velit numquam atque qui consequatur quam. Et sequi voluptatem sunt. Nemo et quo quod consequuntur. Quis eos consequatur recusandae in doloribus rerum odit odio.',
+ 'id' => '1',
+ 'title' => 'Optio earum deserunt fuga qui quia hic.',
+ 'content' => 'Fuga molestiae quis sit quis maiores et. Amet eveniet sint quidem deleniti voluptas necessitatibus. Aut aut voluptatibus ut maiores doloremque eos totam.',
),
1 =>
array (
E:\wwwroot\lighthouse-tutorial\vendor\laravel\framework\src\Illuminate\Testing\Constraints\ArraySubset.php:85
E:\wwwroot\lighthouse-tutorial\vendor\laravel\framework\src\Illuminate\Testing\Assert.php:40
E:\wwwroot\lighthouse-tutorial\vendor\laravel\framework\src\Illuminate\Testing\AssertableJsonString.php:273
E:\wwwroot\lighthouse-tutorial\vendor\laravel\framework\src\Illuminate\Testing\TestResponse.php:695
E:\wwwroot\lighthouse-tutorial\tests\Feature\PostsGraphQlApiTest.php:36
phpvfscomposer://E:\wwwroot\lighthouse-tutorial\vendor\phpunit\phpunit\phpunit:97
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.

<pre class="wp-block-syntaxhighlighter-code">
<?php
namespace Tests\Feature;
use Nuwave\Lighthouse\Testing\MakesGraphQLRequests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Nuwave\Lighthouse\Testing\ClearsSchemaCache;
use Tests\CreatesApplication;
use App\Models\Post;
class PostsGraphQlApiTest extends BaseTestCase
{
use CreatesApplication,
ClearsSchemaCache,
MakesGraphQLRequests;
public function testQueriesPosts(): void
{
$post = Post::factory()->create();
$response = $this->graphQL('
{
posts {
id
title
content
}
}
');
$responsePosts = $response->json("data.posts");
$lastKey = array_key_last($responsePosts);
$response->assertJson([
'data' => [
'posts' => [
$lastKey => [
'id' => $post->id,
'title' => $post->title,
'content' => $post->content,
]
],
],
]);
}
protected function setUp(): void
{
parent::setUp();
$this->bootClearsSchemaCache();
}
}
</pre>
PS E:\wwwroot\lighthouse-tutorial> ./vendor/bin/phpunit .\tests\Feature\PostsGraphQlApiTest.php
PHPUnit 9.5.11 by Sebastian Bergmann and contributors.
. 1 / 1 (100%)
Time: 00:00.434, Memory: 38.00 MB
OK (1 test, 1 assertion)
PS E:\wwwroot\lighthouse-tutorial>
PS E:\wwwroot\lighthouse-tutorial> ./vendor/bin/phpunit .\tests\Feature\UsersGraphQlApiTest.php
PHPUnit 9.5.11 by Sebastian Bergmann and contributors.
Illuminate\Testing\TestResponse Object
(
[baseResponse] => Illuminate\Http\Response Object
(
[headers] => Symfony\Component\HttpFoundation\ResponseHeaderBag Object
(
[computedCacheControl:protected] => Array
(
[no-cache] => 1
[private] => 1
)
[cookies:protected] => Array
(
)
[headerNames:protected] => Array
(
[cache-control] => Cache-Control
[date] => Date
[content-type] => Content-Type
)
[headers:protected] => Array
(
[cache-control] => Array
(
[0] => no-cache, private
)
[date] => Array
(
[0] => Thu, 20 Jan 2022 06:33:46 GMT
)
[content-type] => Array
(
[0] => application/json
)
)
[cacheControl:protected] => Array
(
)
)
[content:protected] => {"errors":[{"message":"Syntax Error: Expected Name, found $","extensions":{"category":"graphql"},"locations":[{"line":3,"column":36}]}]}
[version:protected] => 1.1
[statusCode:protected] => 200
[statusText:protected] => OK
[charset:protected] =>
[original] => Array
(
[errors] => Array
(
[0] => Array
(
[message] => Syntax Error: Expected Name, found $
[extensions] => Array
(
[category] => graphql
)
[locations] => Array
(
[0] => Array
(
[line] => 3
[column] => 36
)
)
)
)
)
[exception] =>
)
[exceptions:protected] => Illuminate\Testing\LoggedExceptionCollection Object
(
[items:protected] => Array
(
)
[escapeWhenCastingToString:protected] =>
)
[streamedContent:protected] =>
)
PS E:\wwwroot\lighthouse-tutorial>

public function testGetThemeById(): void
{
$response = $this->graphQL('
query GetThemeById($id: ID!) {
onlineStoreTheme(themeId: $id) {
id
editable
createdAt
name
}
}
',
[
'id' => 'vogue',
]
);
$response->assertJson([
'data' => [
'onlineStoreTheme' => [
'id' => 'vogue'
],
],
]);
}

PS E:\wwwroot\object> ./vendor/bin/phpunit .\Modules\ThemeStore\Tests\Functional\GraphQl\OnlineStoreThemeGraphQlApiTest.php
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.
. 1 / 1 (100%)
Time: 1.69 seconds, Memory: 60.00 MB
OK (1 test, 1 assertion)
PS E:\wwwroot\object>
PHP / Laravel / Yii2 老项目维护与长期技术支持
如果你的 PHP / Laravel / Yii2 项目已经上线,但遇到原开发离职、Bug 长期无人修复、接口不稳定、性能下降、代码难以接手等问题,可以联系我做一次远程技术排查。
适合以下情况:
✅ 老旧 PHP 系统无人维护
✅ Laravel / Yii2 项目 Bug 修复
✅ 后台管理系统小功能迭代
✅ RESTful API 接口排查
✅ MySQL / Redis / Nginx 性能问题
✅ 长期远程兼职维护
可先从一次小问题开始:
✅ 线上报错排查
✅ 接口异常分析
✅ 慢查询与性能瓶颈定位
✅ 代码结构初步评估
✅ 部署环境与日志检查
如需咨询,请联系我,并注明:PHP 维护咨询。
联系方式:
Telegram:@shuijingwan
微信:13980074657
邮箱:shuijingwanwq@gmail.com

发表回复