public function testStringRangeIsInvalidWhenStartingWithZero() { $numberNegotiator = new NumberNegotiator("03-02"); $this->assertTrue($numberNegotiator->isMatch()); $numberNegotiator->getNumbers(); $exceptions = $numberNegotiator->getExceptions(); $this->assertCount(2, $exceptions); $this->assertSame("Invalid left-hand number: Not an integer. Expected number the form: '/^[1-9]\\d*\$/'. Found: 03", $exceptions[0]->getMessage()); $this->assertSame("Invalid right-hand number: Not an integer. Expected number the form: '/^[1-9]\\d*\$/'. Found: 02", $exceptions[1]->getMessage()); }
public function __construct(array $args, BashCommand $bashCommand) { $this->bashCommand = $bashCommand; foreach (array_slice($args, 1, 2) as $arg) { if (!$this->requestedNumbers) { $numberNegotiator = new NumberNegotiator($arg); if ($numberNegotiator->isMatch()) { $this->requestedNumbers = $numberNegotiator->getNumbers(); if ($numberNegotiator->hasExceptions()) { throw new \RuntimeException(sprintf("NumberNegotiator Exceptions: " . PHP_EOL . "%s", $numberNegotiator->getExceptionsAsString())); } } else { $this->action = $arg; } } } if ($this->requestedNumbers) { $this->additionalArgs = array_slice($args, 3); } else { $this->action = $args[1]; $this->additionalArgs = array_slice($args, 2); } }