It could be cached config. Try php artisan config:clear
Only cache in production
Hi - I'm early in my learning TDD. I've set up my testing environment to use the in-memory sqlite database, but when I run my tests, the actual MySql database gets wiped out as well. Any thoughts on what I can look for that is triggering this? Here's the phpunit.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./app</directory>
</include>
</coverage>
<php>
<env name="APP_ENV" value="testing"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
<env name="MAIL_MAILER" value="array"/>
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="TELESCOPE_ENABLED" value="false"/>
</php>
</phpunit>
Here's an example test:
<?php
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
class ProfilePageTest extends TestCase
{
public function test_page_will_not_open_for_guest()
{
$response = $this->get('profile/3');
$response->assertRedirect('login');
}
public function test_page_will_open_for_auth_user()
{
$this->withoutExceptionHandling();
$this-refreshDatabase();
$user = User::factory()->create();
auth()->loginUsingId($user->id);
$response = $this->get(route('profile',['user' => $user]));
$response->assertViewIs('users.profile');
}
}
I have the RefreshDatabase in the TestCase model
<?php
namespace Tests;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
use RefreshDatabase;
}
I didn't have the DB_CONNECTION and DB_DATABASE uncommented on my first few tests, so I understood why I was losing my data then, but I can't figure it out now. Thanks for your help!
It could be cached config. Try php artisan config:clear
Only cache in production
Please or to participate in this conversation.