runBatch($directory, ['jushuitan:sync-shipping', '--days=3']); $this->assertSame(75, $process->getExitCode()); $this->assertFileDoesNotExist($directory . '/called'); flock($lock, LOCK_UN); $process = $this->runBatch($directory, ['jushuitan:sync-shipping', '--days=3']); $this->assertTrue($process->isSuccessful(), $process->getErrorOutput()); $arguments = file($directory . '/called', FILE_IGNORE_NEW_LINES); $this->assertContains('batch', $arguments); $this->assertSame(['jushuitan:sync-shipping', '--days=3'], array_slice($arguments, -2)); $this->assertContains('--no-deps', $arguments); $this->assertSame('image=123456789abc', $arguments[0]); } finally { fclose($lock); foreach (glob($directory . '/*') as $path) { unlink($path); } rmdir($directory); } } private function runBatch(string $directory, array $arguments): Process { file_put_contents($directory . '/docker', '#!/bin/sh' . "\n" . 'if [ "$1" = inspect ]; then echo caiwu_akaunting:123456789abc; exit 0; fi' . "\n" . 'printf "%s\n" "image=$IMAGE_TAG" "$@" > "$CAIWU_CAPTURE"' . "\n"); chmod($directory . '/docker', 0700); $process = new Process(array_merge(['sh', dirname(__DIR__, 3) . '/deploy/run-finance-batch.sh'], $arguments), $directory, [ 'PATH' => $directory . ':' . getenv('PATH'), 'CAIWU_REMOTE_DIR' => $directory, 'CAIWU_UPSTREAM_LOCK' => $directory . '/sync.lock', 'CAIWU_BATCH_LOCK_WAIT' => '0.1', 'CAIWU_CAPTURE' => $directory . '/called', ]); $process->run(); return $process; } }