我是 laravel 和 php 单元测试的新手。
我正在尝试在 laravel 中运行一个非常基本的测试,并在通过命令行运行 phpunit
时出现以下错误:
Caused by PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'after
impressions
,clicks
int not null,clicks_change
float(4, 2) not null' at line 1
class ExampleTest extends TestCase {
/**
* A basic functional test example.
*
* @return void
*/
public function testStats()
{
$result = true;
$this->assertEquals(true, $result);
}
}
最佳答案
请检查您所写的查询。 或者从 phpunit.xml 中注释掉与数据库相关的部分,以在没有数据库交互的情况下运行测试
<!--<env name="DB_CONNECTION" value="mysql"/>-->
<!--<env name="DB_DATABASE" value="event_test_db"/>-->
关于php - 由 PDOException : SQLSTATE[42000] - php unit test in Laravel 引起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29250227/