我开始使用laravel4,并try 开始使用单元测试,这样我就可以让我的生活变得更容易.你们都会猜到,在try phpunit测试之后,我的开发并没有变得更容易.简单的测试很简单,但是当事情开始变得有点复杂时,它们就不会像我想象的那样进行了.

The problem is I have conducted simple tests but I get some strange error PDOException: could not find driver. I have read a few articles and post on this topic but nothing solved my problem. I have installed php5-mysql and when I call php -m it says that I have both PDO and pdo_mysql. The actual command I use is php -m |grep -i "pdo" and the output is:

PDO
pdo_mysql

Well I've tried to actualy test PDOException class in the browser. For that purpose I have change the mysql user password to incorrect one and tested what will happen in artisan server (called with command php artisan serve ---> http://localhost:8000/). In the browser everything works as a charm but when I try to call ``phpunit` in the console the result is not the same.

I have tried to see if webserver and cli have different configuration files but it turnout that the files are identical. The configuration files that I have compared are:

for the web server

/etc/php5/apache2/conf.d/20-pdo_mysql.ini
/etc/php5/apache2/conf.d/05-opcache.ini
/etc/php5/apache2/conf.d/20-json.ini
/etc/php5/apache2/conf.d/20-mysql.ini
/etc/php5/apache2/conf.d/20-mysqli.ini
/etc/php5/apache2/conf.d/10-pdo.ini
/etc/php5/apache2/conf.d/20-mcrypt.ini
/etc/php5/apache2/conf.d/20-curl.ini
/etc/php5/apache2/php.ini

for command line

/etc/php5/cli/conf.d/20-pdo_mysql.ini
/etc/php5/cli/conf.d/05-opcache.ini
/etc/php5/cli/conf.d/20-json.ini
/etc/php5/cli/conf.d/20-mysql.ini
/etc/php5/cli/conf.d/20-mysqli.ini
/etc/php5/cli/conf.d/10-pdo.ini
/etc/php5/cli/conf.d/20-mcrypt.ini
/etc/php5/cli/conf.d/20-curl.ini
/etc/php5/cli/php.ini

to compare them I user the diff command like so diff -s /path/to/file1 /path/to/file2.

The errors look like this:

1) ExampleTest::testBasicExample
PDOException: could not find driver

/var/www/smlsspd/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:47
/var/www/smlsspd/vendor/laravel/framework/src/Illuminate/Database/Connectors/SQLiteConnector.php:22
/var/www/smlsspd/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php:59
/var/www/smlsspd/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php:47
/var/www/smlsspd/vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php:127
/var/www/smlsspd/vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php:63
/var/www/smlsspd/vendor/laravel/framework/src/Illuminate/Database/Migrations/DatabaseMigrationRepository.php:167
/var/www/smlsspd/vendor/laravel/framework/src/Illuminate/Database/Migrations/DatabaseMigrationRepository.php:135
/var/www/smlsspd/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:366
/var/www/smlsspd/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php:93
/var/www/smlsspd/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php:56
/var/www/smlsspd/vendor/laravel/framework/src/Illuminate/Console/Command.php:108
/var/www/smlsspd/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:241
/var/www/smlsspd/vendor/laravel/framework/src/Illuminate/Console/Command.php:96
/var/www/smlsspd/vendor/laravel/framework/src/Illuminate/Console/Application.php:96
/var/www/smlsspd/vendor/laravel/framework/src/Illuminate/Foundation/Artisan.php:57
/var/www/smlsspd/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:208
/var/www/smlsspd/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:208
/var/www/smlsspd/app/tests/TestCase.php:70
/var/www/smlsspd/app/tests/TestCase.php:70
/var/www/smlsspd/app/tests/TestCase.php:46
phar:///var/www/smlsspd/phpunit.phar/phpunit/TextUI/Command.php:179
phar:///var/www/smlsspd/phpunit.phar/phpunit/TextUI/Command.php:132

你能给我一个提示或解决这个问题的方法吗?

感谢您抽出时间:)

推荐答案

似乎Laravel使用SQLite作为数据库进行测试.请参见第2行的回溯:

/var/www/smlsspd/vendor/laravel/framework/src/Illuminate/Database/Connectors/SQLiteConnector.php:22

但这似乎没有安装在您的系统上.所以我认为你需要安装SQLite驱动程序.

Laravel相关问答推荐

密码确认在Livewire中不匹配

Laravel 数据未传递到下拉框

当两个外键都在同一个表上时创建直通关系

我如何通过 laravel 在高图中针对不同的时间范围进行烛台数据分组

导出所有客户端不起作用,文件保存时没有名称和扩展名

Laravel Livewire 组件属性在 div 类中为空

laravel render() 方法有什么用?

如何更新 Laravel 4 中现有的 Eloquent 关系?

如何为路由 laravel 5 使用OR中间件

判断 Laravel 模型表中是否存在列,然后应用条件

将 Laravel Socialite 与 API 一起使用?

Laravel 中的填充方法不起作用?

在 Laravel 中,如何获取 *only* POST 参数?

Laravel - 语法错误,文件意外结束

如果 Laravel 中的值不为空,如何验证输入字段

Laravel/PHPUnit:断言 json 元素存在而不定义值

控制器中的artisan调用输出?

是否可以在 Laravel 的不同数据库中引用外键?

Laravel 部署……有标准的方式吗?

在 Laravel 中翻译特定语言