/** * Parses the light instruction * @param $string * @return LightInstruction * @throws LightInstructionParserException */ public static function parse($string) { $matchResult = preg_match('/^((?:turn (?:on|off))|toggle) (\\d+),(\\d+) through (\\d+),(\\d+)$/', $string, $matches); if ($matchResult === 0) { throw new LightInstructionParserException('String is not formatted correctly: $string'); } return LightInstructionFactory::create(static::$actionMap[$matches[1]], [new Coordinate($matches[2], $matches[3]), new Coordinate($matches[4], $matches[5])]); }
/** @test */ public function createsInstruction() { $action = LightInstructionAction::TURN_ON; $coordinates = [new Coordinate(0, 0), new Coordinate(2, 2)]; $this->assertEquals(new LightInstruction($action, $coordinates), LightInstructionFactory::create($action, $coordinates)); }