Route always not defined #453
-
I rewrite my test from phpunit to pest but my routing always not defined, my test on phpunit is passed and the route is exists.. This my simple test <?php
use Tests\TestCase;
uses(TestCase::class);
it('asserts true is true', function () {
$this->assertTrue(true);
});
it('can render page', function () {
$this->get(route('auth.login'))->assertSuccessful();
}); This my <?php
namespace Tests;
use Livewire\LivewireServiceProvider;
use BladeUI\Icons\BladeIconsServiceProvider;
use Orchestra\Testbench\TestCase as BaseTestCase;
use BladeUI\Heroicons\BladeHeroiconsServiceProvider;
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
abstract class TestCase extends BaseTestCase
{
use LazilyRefreshDatabase;
protected function getPackageProviders($app): array
{
return [
BladeHeroiconsServiceProvider::class,
BladeIconsServiceProvider::class,
LivewireServiceProvider::class,
];
}
} This my <?xml version="1.0" encoding="UTF-8"?>
<phpunit
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
verbose="true"
>
<testsuites>
<testsuite name="Tests">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<php>
<env name="APP_KEY" value="base64:yk+bUVuZa1p86Dqjk9OjVK2R1pm6XHxC6xEKFq8utH0="/>
<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> |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
First, try to do not use Or/and add a test checking for "route exists" before. Because "Route not defined" is an unrelated error and should be tested separately. Also, I think the "route" helper is not ready yet for your defined routes in this lifecycle step, or cache is outdated. Try cleaning/refreshing the cache before running the tests. |
Beta Was this translation helpful? Give feedback.
First, try to do not use
route()
helper, and use explicit URL instead for these kinds of tests.Or/and add a test checking for "route exists" before.
Because "Route not defined" is an unrelated error and should be tested separately.
Also, I think the "route" helper is not ready yet for your defined routes in this lifecycle step, or cache is outdated. Try cleaning/refreshing the cache before running the tests.