Skip to content

Commit

Permalink
AgnosticRouter
Browse files Browse the repository at this point in the history
  • Loading branch information
ProklUng committed Jul 25, 2021
1 parent 96412a1 commit 930d125
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Services/Utils/BitrixRouteConvertor.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,14 @@ private function parseControllerString(string $name, $controller) : array
}
}

if (is_array($controller)) {
if (is_array($controller) && count($controller) > 0) {
if (!array_key_exists(1, $controller)) {
// Invoke controller (не поддерживается).
throw new LogicException(
sprintf('Route %s. Invokable controller %s not supporting.', $name, $controller[0])
);
}

if (strpos($controller[1], 'Action') === false) {
// В методе контроллера обязательно должно содержаться Action
// (особенность битриксовых контроллеров)
Expand Down
34 changes: 34 additions & 0 deletions Tests/Cases/BitrixRouteConvertorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,40 @@ public function testParseControllerStringInvalidArray() : void
);
}

/**
* parseControllerString(). Пустой массив.
*
* @return void
* @throws ReflectionException
*/
public function testParseControllerStringEmptyArray() : void
{
$this->expectException(LogicException::class);

PHPUnitUtils::callMethod(
$this->obTestObject,
'parseControllerString',
['fooName', []]
);
}

/**
* parseControllerString(). Массив. Invokable.
*
* @return void
* @throws ReflectionException
*/
public function testParseControllerStringArrayInvokable() : void
{
$this->expectException(LogicException::class);

PHPUnitUtils::callMethod(
$this->obTestObject,
'parseControllerString',
['fooName', ['Controller']]
);
}

/**
* parseControllerString(). Массив.
*
Expand Down

0 comments on commit 930d125

Please sign in to comment.