Z
Z
zobov2017-02-12 17:45:55
PHPUnit
zobov, 2017-02-12 17:45:55

Why does the test output 404?

The second day I struggle with the problem of tests in Laravel 5.4. Any path gives a 404 error. Didn't google anything.
In general, the task is to write tests for the ApiController controller. How to do it the right way? If possible, with examples, thanks in advance!
Issue background :
Project on latest laravel 5.4 available at localhost:8888/streaming_statistic/public
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);
    }
}

I run from the project folder. ./vendor/bin/phpunit
The result is as follows:
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.

At the same time, the page localhost:8888/streaming_statistic/public opens, since the route is registered
Route::get('/', function () {
    return view('welcome');
});

What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zobov, 2017-02-13
@zobov

As it turned out, he did not like the env variable:
APP_URL= 127.0.0.1:8888/streaming_statistic/public
Moving root to public and replacing it with this, everything became fine:
APP_URL= 127.0.0.1:8888
The only thing that remained unclear to me was why this behavior?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question