diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 44baeaf..53c3223 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,3 +35,9 @@ jobs: if: ${{ matrix.php >= 7.3 }} - run: vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy if: ${{ matrix.php < 7.3 }} + - run: cd tests/install-as-dep && composer install && php query.php + - run: cd tests/install-as-dep && php -d phar.readonly=0 vendor/bin/phar-composer build . query.phar + continue-on-error: ${{ matrix.os == 'windows-2019' }} + id: phar + - run: php tests/install-as-dep/query.phar + if: ${{ steps.phar.outcome == 'success' }} diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 8c38d9a..1b8eb6a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,6 +9,7 @@ ./tests/ + ./tests/install-as-dep/ diff --git a/phpunit.xml.legacy b/phpunit.xml.legacy index e65d4cb..080247b 100644 --- a/phpunit.xml.legacy +++ b/phpunit.xml.legacy @@ -8,6 +8,7 @@ ./tests/ + ./tests/install-as-dep/ diff --git a/src/Factory.php b/src/Factory.php index 98a4f28..7e7f6ca 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -226,7 +226,16 @@ public function openLazy($filename, $flags = null, array $options = []) private function openProcessIo($filename, $flags = null) { - $command = 'exec ' . \escapeshellarg($this->bin) . ' sqlite-worker.php'; + $cwd = null; + $worker = \dirname(__DIR__) . '/res/sqlite-worker.php'; + + if (\class_exists('Phar', false) && \Phar::running(false) !== '') { + $worker = '-r' . 'require(' . \var_export($worker, true) . ');'; // @codeCoverageIgnore + } else { + $cwd = __DIR__ . '/../res'; + $worker = \basename($worker); + } + $command = 'exec ' . \escapeshellarg($this->bin) . ' ' . escapeshellarg($worker); // Try to get list of all open FDs (Linux/Mac and others) $fds = @\scandir('/dev/fd'); @@ -269,7 +278,7 @@ private function openProcessIo($filename, $flags = null) $command = 'exec bash -c ' . \escapeshellarg($command); } - $process = new Process($command, __DIR__ . '/../res', null, $pipes); + $process = new Process($command, $cwd, null, $pipes); $process->start($this->loop); $db = new ProcessIoDatabase($process); @@ -285,7 +294,16 @@ private function openProcessIo($filename, $flags = null) private function openSocketIo($filename, $flags = null) { - $command = \escapeshellarg($this->bin) . ' sqlite-worker.php'; + $cwd = null; + $worker = \dirname(__DIR__) . '/res/sqlite-worker.php'; + + if (\class_exists('Phar', false) && \Phar::running(false) !== '') { + $worker = '-r' . 'require(' . \var_export($worker, true) . ');'; // @codeCoverageIgnore + } else { + $cwd = __DIR__ . '/../res'; + $worker = \basename($worker); + } + $command = \escapeshellarg($this->bin) . ' ' . escapeshellarg($worker); // launch process without default STDIO pipes, but inherit STDERR $null = \DIRECTORY_SEPARATOR === '\\' ? 'nul' : '/dev/null'; @@ -307,7 +325,7 @@ private function openSocketIo($filename, $flags = null) stream_set_blocking($server, false); $command .= ' ' . stream_socket_get_name($server, false); - $process = new Process($command, __DIR__ . '/../res', null, $pipes); + $process = new Process($command, $cwd, null, $pipes); $process->start($this->loop); $deferred = new Deferred(function () use ($process, $server) { diff --git a/tests/install-as-dep/.gitignore b/tests/install-as-dep/.gitignore new file mode 100644 index 0000000..070e2f2 --- /dev/null +++ b/tests/install-as-dep/.gitignore @@ -0,0 +1,3 @@ +/composer.lock +/query.phar +/vendor/ diff --git a/tests/install-as-dep/composer.json b/tests/install-as-dep/composer.json new file mode 100644 index 0000000..ff46121 --- /dev/null +++ b/tests/install-as-dep/composer.json @@ -0,0 +1,20 @@ +{ + "require": { + "clue/reactphp-sqlite": "*@dev" + }, + "require-dev": { + "clue/phar-composer": "^1.0" + }, + "bin": [ + "query.php" + ], + "repositories": [ + { + "type": "path", + "url": "../../", + "options": { + "symlink": false + } + } + ] +} diff --git a/tests/install-as-dep/query.php b/tests/install-as-dep/query.php new file mode 100644 index 0000000..d2ab547 --- /dev/null +++ b/tests/install-as-dep/query.php @@ -0,0 +1,26 @@ +openLazy(':memory:', null, ['idle' => 0.001]); + +$query = isset($argv[1]) ? $argv[1] : 'SELECT 42 AS value'; +$args = array_slice(isset($argv) ? $argv : [], 2); + +$db->query('SELECT ? AS answer', [42])->then(function (Clue\React\SQLite\Result $result) { + if ($result->columns !== ['answer'] || count($result->rows) !== 1 || $result->rows[0]['answer'] !== 42) { + var_dump($result); + throw new RuntimeException('Unexpected result'); + } + + $answer = $result->rows[0]['answer']; + echo 'Answer: ' . $answer . PHP_EOL; +})->then(null, function (Exception $e) { + echo 'Error: ' . $e->getMessage() . PHP_EOL; + exit(1); +});