gpt4 book ai didi

mysql - Pphunit 不断给出错误 : [1049] Unknown database ':memory:'

转载 作者:行者123 更新时间:2023-12-05 02:06:19 24 4
gpt4 key购买 nike

我刚开始在 Laravel 7 中使用 phpunit。我遇到了一个找不到解决方案的问题。我将 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:

SHOW FULL TABLES WHERE 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数据库里的表都被删除了。

有什么建议吗?

亲切的问候,

休伯特

最佳答案

我猜你想将 sqlite 作为内存数据库运行,至少这是我首选的测试设置。

要实现这一点,您必须像这样在测试中设置环境。现在你有 Mysql 的连接,这不能使用 sqlite 的内存设置。

<server name="DB_CONNECTION" value="sqlite"/>
<server name="DB_DATABASE" value=":memory:"/>

关于mysql - Pphunit 不断给出错误 : [1049] Unknown database ':memory:' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62823839/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com