Fix params for launching process #724

This commit is contained in:
Nabeel Shahzad 2020-05-23 12:51:12 -04:00
parent 8527b39fe2
commit 688be6f75a
3 changed files with 19 additions and 11 deletions

View File

@ -76,7 +76,7 @@ tests: test
.PHONY: test
test:
@#php artisan database:create --reset
@vendor/bin/phpunit --verbose --debug
@vendor/bin/phpunit --verbose
.PHONY: phpcs
phpcs:

View File

@ -79,6 +79,13 @@ class CreateDatabase extends Command
*/
protected function create_sqlite($dbkey)
{
$dbPath = config($dbkey.'database');
// Skip if running in memory
if ($dbPath === ':memory:') {
return;
}
$exec = 'sqlite3';
if ($this->os->isWindowsLike()) {
$exec = 'sqlite3.exe';
@ -89,11 +96,11 @@ class CreateDatabase extends Command
$this->runCommand($cmd);
}
if (!file_exists(config($dbkey.'database'))) {
if (!file_exists($dbPath)) {
$cmd = [
$exec,
config($dbkey.'database'),
'""',
$dbPath,
'".exit"',
];
$this->runCommand($cmd);

View File

@ -3,6 +3,7 @@
namespace App\Contracts;
use Illuminate\Support\Facades\Log;
use function is_array;
use Symfony\Component\Process\Process;
/**
@ -82,7 +83,7 @@ abstract class Command extends \Illuminate\Console\Command
}
/**
* @param $cmd
* @param array|string $cmd
* @param bool $return
* @param mixed $verbose
*
@ -93,16 +94,16 @@ abstract class Command extends \Illuminate\Console\Command
*/
public function runCommand($cmd, $return = false, $verbose = true): string
{
if (!\is_array($cmd)) {
$cmd = explode(' ', $cmd);
if (is_array($cmd)) {
$cmd = implode(' ', $cmd);
}
if ($verbose) {
$this->info('Running "'.implode(' ', $cmd).'"');
$this->info('Running '.$cmd);
}
$val = '';
$process = new Process($cmd);
$process = Process::fromShellCommandline($cmd);
$process->run(function ($type, $buffer) use ($return, &$val) {
if ($return) {
$val .= $buffer;