Wednesday, April 25, 2018

unit testing - use database or sqlite cache

use new database for unit testing

add new testing connection to config/database.php

'testing' => [        
'driver' => 'mysql',        
'host' => env('DB_HOST', '127.0.0.1'),        
'port' => env('DB_PORT', '3306'),        
'database' => env('TEST_DB_DATABASE', 'forge'),        
'username' => env('DB_USERNAME', 'forge'),        
'password' => env('DB_PASSWORD', ''),        
'unix_socket' => env('DB_SOCKET', ''),        
'charset' => 'utf8mb4',        
'collation' => 'utf8mb4_unicode_ci',        
'prefix' => '',        'strict' => true,        
'engine' => null,]


Then open phpunit.xml file on root.

After that add  <env name="DB_CONNECTION" value="testing"/>   PHP section

Otherwise you can use sqlite cache.

Run test on single file

php vendor/bin/phpunit tests/Feature/BrokerRecordTest








Share/Bookmark

0 comments:

Post a Comment