Laravel API测试执行全类无返回问题排查求助
Laravel API执行
php artisan test无任何返回的问题排查 我在Laravel API环境下执行php artisan test时,命令行没有任何返回内容——既没有成功提示,也没有错误信息。
相关配置与代码
API路由(api.php)
Route::group(['prefix' => '{facultyId}'], function () { Route::resource('awards', AwardController::class); });
Feature测试类
<?php namespace Tests\Feature; use Illuminate\Foundation\Testing\WithoutMiddleware; use Tests\TestCase; class TestInfoTest extends TestCase { use WithoutMiddleware; /** @test */ public function test_get_endpoint_exists() { $response = $this->getJson(route('test.index', [ 'facultyId' => '0000001', 'page' => 1, 'itemsPerPage' => 5, 'search' => '' ])); $response ->assertStatus(200) ->assertJson([ 'message' => 'Success' ]); } /** @test */ public function test_is_there_a_model() { $test = Test::find(1); return $this->assertModelExists($test); } }
phpunit.xml配置
<?xml version="1.0" encoding="UTF-8"?> <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true"> <coverage processUncoveredFiles="true"> <include> <directory suffix=".php">./app</directory> </include> </coverage> <testsuites> <testsuite name="Unit"> <directory suffix="Test.php">./tests/Unit</directory> </testsuite> <testsuite name="Feature"> <directory suffix="Test.php">./tests/Feature</directory> </testsuite> </testsuites> <php> <server name="APP_ENV" value="testing"/> <server name="BCRYPT_ROUNDS" value="4"/> <server name="CACHE_DRIVER" value="array"/> <server name="DB_CONNECTION" value="sqlite"/> <server name="DB_DATABASE" value=":memory:"/> <server name="MAIL_MAILER" value="array"/> <server name="QUEUE_CONNECTION" value="sync"/> <server name="SESSION_DRIVER" value="array"/> <server name="TELESCOPE_ENABLED" value="false"/> </php> </phpunit>
已确认的现象
- 单独运行每个测试方法时,均可正常通过
- 在测试中调用
$response->dump(),确认getJson请求能成功返回200状态码及Success消息 - 已在
artisan.php中添加错误输出配置:ini_set('display_errors',1); error_reporting(-1);
已尝试但未解决问题的操作
- 直接指定测试文件运行:
php artisan test tests/Feature/MyFeatureTest.php - 清除缓存:
php artisan cache:clear - 清除配置缓存:
php artisan config:clear - 启用调试模式运行测试:
php artisan test --debug - 遇到失败立即停止:
php artisan test --stop-on-failure
补充信息
项目使用无迁移的Oracle数据库,需要找到解决测试无返回的方案。
内容的提问来源于stack exchange,提问作者Michael Carrier
相关产品推荐
相关产品推荐

