previousContainer = Container::getInstance(); $app = new Application(dirname(__DIR__, 3)); $app['env'] = 'production'; $app->instance('config', new Repository([ 'finance_batch' => ['container' => false, 'import_commands' => ['product:monthly-weighted-average:base']], ])); Container::setInstance($app); } protected function tearDown(): void { Container::setInstance($this->previousContainer); parent::tearDown(); } private function starting(string $name): CommandStarting { return new CommandStarting($name, new ArrayInput([]), new BufferedOutput()); } public function test_production_imports_cannot_start_in_web_container(): void { $this->expectException(RuntimeException::class); $this->expectExceptionMessage('run-finance-batch.sh'); (new RequireImportBatchContainer())->handle($this->starting('order-data:import-after-sales-cost')); } public function test_registered_import_without_import_in_its_name_is_also_protected(): void { $this->expectException(RuntimeException::class); (new RequireImportBatchContainer())->handle($this->starting('product:monthly-weighted-average:base')); } public function test_production_batch_runtime_can_import_and_health_checks_stay_available(): void { $listener = new RequireImportBatchContainer(); $listener->handle($this->starting('app:ready')); config(['finance_batch.container' => true]); $listener->handle($this->starting('order-data:import-after-sales-cost')); $this->addToAssertionCount(2); } public function test_local_and_test_imports_keep_their_existing_usage(): void { app()['env'] = 'testing'; (new RequireImportBatchContainer())->handle($this->starting('order-data:import-after-sales-cost')); $this->addToAssertionCount(1); } public function test_registry_includes_every_existing_import_command(): void { $root = dirname(__DIR__, 3); $commands = json_decode(file_get_contents($root . '/deploy/finance-batch-imports.json'), true, 512, JSON_THROW_ON_ERROR); foreach (glob($root . '/app/Console/Commands/Import*.php') as $file) { preg_match('/\$signature\s*=\s*\'([^\s\']+)/', file_get_contents($file), $match); $this->assertContains($match[1], $commands, basename($file)); } } }