##/tests/TestCase.phpに下記を追加
tests/TestCase.php
<?php
namespace Tests;
use Nuwave\Lighthouse\Testing\MakesGraphQLRequests; // 追加
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
use MakesGraphQLRequests; // 追加
}
##phpunit.xmlに下記を追加
phpunit.xml
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<!-- 下記の三行を追加 -->
<testsuite name="Graghql">
<directory suffix="Test.php">./tests/Graghql</directory>
</testsuite>
</testsuites>
上記でtests/Graghqlの中を見るようになります。
tests/Graghql/UserTest.php
<?php
namespace Tests\Unit;
use Tests\TestCase;
use App\Models\User;
class UserTest extends TestCase
{
/**
* A basic unit test example.
*
* @return void
*/
public function test_loginUser()
{
$res = $this->graphQL(/** @lang GraphQL */ '
query(
$user_name: String!
$password: String!
){
loginUser(
user_name: $user_name
password: $password
) {
result
}
}
', [
'user_name' => 'テストユーザー',
'password' => 'testpassword'
]
);
$res->assertStatus(200);
}
}