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 .PHONY: test
test: test:
@#php artisan database:create --reset @#php artisan database:create --reset
@vendor/bin/phpunit --verbose --debug @vendor/bin/phpunit --verbose
.PHONY: phpcs .PHONY: phpcs
phpcs: phpcs:

View File

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

View File

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