Posso il mio progetto su Laravel 5.4 dal link: localhost: 8888 / streaming_statistic / public
Ho un test:
<?php namespace Tests\Feature; use Tests\TestCase; use Illuminate\Foundation\Testing\WithoutMiddleware; use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseTransactions; class ApiTest extends TestCase { public function testBasicTest() { $response = $this->get('/'); $response->assertStatus(200); } }
Eseguo tutti i test con il command
./vendor/bin/phpunit
Ma il risultato è:
PHPUnit 5.7.13 by Sebastian Bergmann and contributors. F 1 / 1 (100%) Time: 222 ms, Memory: 12.25MB There was 1 failure: 1) Tests\Feature\ApiTest::testBasicTest Expected status code 200 but received 404. Failed asserting that false is true. /Applications/MAMP/htdocs/streaming_statistic/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:56 /Applications/MAMP/htdocs/streaming_statistic/tests/Feature/ApiTest.php:16 FAILURES! Tests: 1, Assertions: 1, Failures: 1.
Posso aprire questa pagina http: // localhost: 8888 / streaming_statistic / public / Ho una rotta:
Route::get('/', function () { return view('welcome'); });
Cosa sto facendo di sbagliato? E quale è il modo giusto di scrivere test per i methods di controllo in laravel? Potrebbe essere il test HTTP non è la soluzione migliore per loro?
per i test questa variabile env era sbagliata …
APP_URL=http://127.0.0.1:8888/streaming_statistic/public
Ho cambiato la directory del server web di root in streaming_statistic / public e env to
APP_URL=http://127.0.0.1:8888
Dopo che ho ottenuto:
OK (1 test, 1 assertion)