assertSame($values, $args->getArguments()); } /** * Get arguments by index */ public function testGetArgumentAt(): void { $values = ['big', 'brown', 'bear']; $args = new Arguments($values, [], []); $this->assertSame($values[0], $args->getArgumentAt(0)); $this->assertSame($values[1], $args->getArgumentAt(1)); $this->assertNull($args->getArgumentAt(3)); } /** * check arguments by index */ public function testHasArgumentAt(): void { $values = ['big', 'brown', 'bear']; $args = new Arguments($values, [], []); $this->assertTrue($args->hasArgumentAt(0)); $this->assertTrue($args->hasArgumentAt(1)); $this->assertFalse($args->hasArgumentAt(3)); $this->assertFalse($args->hasArgumentAt(-1)); } /** * check arguments by name */ public function testHasArgument(): void { $values = ['big', 'brown', 'bear']; $names = ['size', 'color', 'species', 'odd']; $args = new Arguments($values, [], $names); $this->assertTrue($args->hasArgument('size')); $this->assertTrue($args->hasArgument('color')); $this->assertFalse($args->hasArgument('odd')); $this->assertFalse($args->hasArgument('undefined')); } /** * get arguments by name */ public function testGetArgument(): void { $values = ['big', 'brown', 'bear']; $names = ['size', 'color', 'species', 'odd']; $args = new Arguments($values, [], $names); $this->assertSame($values[0], $args->getArgument('size')); $this->assertSame($values[1], $args->getArgument('color')); $this->assertNull($args->getArgument('odd')); } /** * get arguments missing value */ public function testGetArgumentMissing(): void { $values = []; $names = ['size', 'color']; $args = new Arguments($values, [], $names); $this->assertNull($args->getArgument('size')); $this->assertNull($args->getArgument('color')); } /** * get arguments by name */ public function testGetArgumentInvalid(): void { $values = []; $names = ['size']; $args = new Arguments($values, [], $names); $this->expectException(ConsoleException::class); $args->getArgument('color'); } /** * test getOptions() */ public function testGetOptions(): void { $options = [ 'verbose' => true, 'off' => false, 'empty' => '', ]; $args = new Arguments([], $options, []); $this->assertSame($options, $args->getOptions()); } /** * test hasOption() */ public function testHasOption(): void { $options = [ 'verbose' => true, 'off' => false, 'zero' => 0, 'empty' => '', ]; $args = new Arguments([], $options, []); $this->assertTrue($args->hasOption('verbose')); $this->assertTrue($args->hasOption('off')); $this->assertTrue($args->hasOption('empty')); $this->assertTrue($args->hasOption('zero')); $this->assertFalse($args->hasOption('undef')); } /** * test getOption() */ public function testGetOption(): void { $options = [ 'verbose' => true, 'off' => false, 'zero' => '0', 'empty' => '', ]; $args = new Arguments([], $options, []); $this->assertTrue($args->getOption('verbose')); $this->assertFalse($args->getOption('off')); $this->assertSame('', $args->getOption('empty')); $this->assertSame('0', $args->getOption('zero')); $this->assertNull($args->getOption('undef')); } /** * test getOption() checks types */ public function testGetOptionInvalidType(): void { $options = [ 'list' => [1, 2], ]; $args = new Arguments([], $options, []); $this->expectException(ConsoleException::class); $args->getOption('list'); } public function testGetBooleanOption(): void { $options = [ 'verbose' => true, ]; $args = new Arguments([], $options, []); $this->assertTrue($args->getBooleanOption('verbose')); $this->assertNull($args->getBooleanOption('missing')); } /** * test getOption() checks types */ public function testGetOptionBooleanInvalidType(): void { $options = [ 'list' => [1, 2], ]; $args = new Arguments([], $options, []); $this->expectException(ConsoleException::class); $args->getBooleanOption('list'); } public function testGetMultipleOption(): void { $options = [ 'types' => ['one', 'two', 'three'], ]; $args = new Arguments([], $options, []); $this->assertSame(['one', 'two', 'three'], $args->getMultipleOption('types')); $this->assertNull($args->getMultipleOption('missing')); } public function testGetMultipleOptionInvalidType(): void { $options = [ 'connection' => 'test', ]; $args = new Arguments([], $options, []); $this->expectException(ConsoleException::class); $args->getMultipleOption('connection'); } }