|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace RESTAPI\Tests; |
| 4 | + |
| 5 | +use RESTAPI\Core\TestCase; |
| 6 | +use RESTAPI\Dispatchers\SystemUpdateDispatcher; |
| 7 | + |
| 8 | +class TestSystemUpdateDispatcher extends SystemUpdateDispatcher { |
| 9 | + public array $commands = []; |
| 10 | + |
| 11 | + protected function run_command(string $command): void { |
| 12 | + $this->commands[] = $command; |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +class APIDispatchersSystemUpdateDispatcherTestCase extends TestCase { |
| 17 | + /** |
| 18 | + * Ensure the dispatcher enforces max_queue of one process. |
| 19 | + */ |
| 20 | + public function test_max_queue_is_one(): void { |
| 21 | + $dispatcher = new SystemUpdateDispatcher(); |
| 22 | + $this->assert_equals($dispatcher->max_queue, 1); |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * Ensure the dispatcher calls pkg-static update and standard upgrade by default. |
| 27 | + */ |
| 28 | + public function test_process_without_dry_run_uses_standard_upgrade_command(): void { |
| 29 | + $dispatcher = new TestSystemUpdateDispatcher(); |
| 30 | + $dispatcher->process(); |
| 31 | + |
| 32 | + $this->assert_equals($dispatcher->commands, [ |
| 33 | + '/usr/local/sbin/pkg-static update', |
| 34 | + '/usr/local/sbin/pfSense-upgrade -y', |
| 35 | + ]); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Ensure named dry_run appends -n to pfSense-upgrade. |
| 40 | + */ |
| 41 | + public function test_process_with_named_dry_run_uses_noop_upgrade_command(): void { |
| 42 | + $dispatcher = new TestSystemUpdateDispatcher(); |
| 43 | + $dispatcher->process(dry_run: true); |
| 44 | + |
| 45 | + $this->assert_equals($dispatcher->commands, [ |
| 46 | + '/usr/local/sbin/pkg-static update', |
| 47 | + '/usr/local/sbin/pfSense-upgrade -y -n', |
| 48 | + ]); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * Ensure positional dry_run argument also appends -n to pfSense-upgrade. |
| 53 | + */ |
| 54 | + public function test_process_with_positional_dry_run_uses_noop_upgrade_command(): void { |
| 55 | + $dispatcher = new TestSystemUpdateDispatcher(); |
| 56 | + $dispatcher->process(true); |
| 57 | + |
| 58 | + $this->assert_equals($dispatcher->commands, [ |
| 59 | + '/usr/local/sbin/pkg-static update', |
| 60 | + '/usr/local/sbin/pfSense-upgrade -y -n', |
| 61 | + ]); |
| 62 | + } |
| 63 | +} |
0 commit comments