Я только начал работать с phpunit в Laravel 7. Я столкнулся с проблемой, решения которой не могу найти. Я использую Laravel 7 с Xampp.
My phpunit.xml:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpcd ..
cdit/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>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
<php>
<server name="APP_ENV" value="testing"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<server name="DB_CONNECTION" value="mysql"/>
<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>
Моя тестовая функция:
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase;
class ThreadsTest extends TestCase
{
use DatabaseMigrations;
public function test_a_user_can_browse_threads()
{
$response = $this->get('/threads');
$response->assertStatus(200);
}
}
Когда я запускаю phpunit (vendor / phpunit / phpunit / phpunit), я получаю следующее:
PHPUnit 8.5.8 by Sebastian Bergmann and contributors.
.E 2 / 2 (100%)
Time: 1.57 seconds, Memory: 20.00 MB
There was 1 error:
1) Tests\Feature\ThreadsTest::test_a_user_can_browse_threads
Illuminate\Database\QueryException: SQLSTATE[HY000] [1049] Unknown database ':memory:' (SQL:
ПОКАЗАТЬ ПОЛНЫЕ ТАБЛИЦЫ, ГДЕ table_type = 'BASE TABLE')
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Database\Connection.php:671
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Database\Connection.php:631
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Database\Connection.php:339
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Database\Schema\MySqlBuilder.php:99
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Database\Schema\MySqlBuilder.php:48
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Database\Console\WipeCommand.php:69
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Database\Console\WipeCommand.php:46
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:33
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Container\Util.php:37
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:91
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:35
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Container\Container.php:592
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Console\Command.php:134
C:\xampp\htdocs\forum\vendor\symfony\console\Command\Command.php:258
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Console\Command.php:121
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Console\Concerns\CallsCommands.php:56
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Console\Concerns\CallsCommands.php:28
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Database\Console\Migrations\FreshCommand.php:41
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:33
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Container\Util.php:37
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:91
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:35
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Container\Container.php:592
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Console\Command.php:134
C:\xampp\htdocs\forum\vendor\symfony\console\Command\Command.php:258
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Console\Command.php:121
C:\xampp\htdocs\forum\vendor\symfony\console\Application.php:911
C:\xampp\htdocs\forum\vendor\symfony\console\Application.php:264
C:\xampp\htdocs\forum\vendor\symfony\console\Application.php:140
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Console\Application.php:93
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Console\Application.php:185
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php:263
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Testing\PendingCommand.php:171
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Testing\PendingCommand.php:291
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\InteractsWithConsole.php:52
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Foundation\Testing\DatabaseMigrations.php:16
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Foundation\Testing\TestCase.php:119
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Foundation\Testing\TestCase.php:84
Caused by
PDOException: SQLSTATE[HY000] [1049] Unknown database ':memory:'
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:46
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Database\Connectors\MySqlConnector.php:24
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Database\Connectors\ConnectionFactory.php:184
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Database\Connection.php:926
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Database\Connection.php:961
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Database\Connection.php:405
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Database\Connection.php:331
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Database\Connection.php:631
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Database\Connection.php:339
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Database\Schema\MySqlBuilder.php:99
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Database\Schema\MySqlBuilder.php:48
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Database\Console\WipeCommand.php:69
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Database\Console\WipeCommand.php:46
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:33
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Container\Util.php:37
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:91
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:35
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Container\Container.php:592
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Console\Command.php:134
C:\xampp\htdocs\forum\vendor\symfony\console\Command\Command.php:258
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Console\Command.php:121
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Console\Concerns\CallsCommands.php:56
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Console\Concerns\CallsCommands.php:28
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Database\Console\Migrations\FreshCommand.php:41
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:33
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Container\Util.php:37
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:91
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:35
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Container\Container.php:592
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Console\Command.php:134
C:\xampp\htdocs\forum\vendor\symfony\console\Command\Command.php:258
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Console\Command.php:121
C:\xampp\htdocs\forum\vendor\symfony\console\Application.php:911
C:\xampp\htdocs\forum\vendor\symfony\console\Application.php:264
C:\xampp\htdocs\forum\vendor\symfony\console\Application.php:140
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Console\Application.php:93
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Console\Application.php:185
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php:263
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Testing\PendingCommand.php:171
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Testing\PendingCommand.php:291
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\InteractsWithConsole.php:52
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Foundation\Testing\DatabaseMigrations.php:16
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Foundation\Testing\TestCase.php:119
C:\xampp\htdocs\forum\vendor\laravel\framework\src\Illuminate\Foundation\Testing\TestCase.php:84
ERRORS!
Tests: 2, Assertions: 1, Errors: 1.
Также все таблицы в моей MYSQL базе данных удалены.
Есть предложения?
С уважением,
Hubert