Skip to content

Commit 7bee9e2

Browse files
committed
Corona: Throw exception if we found multiple matching controllers
Reviewed at https://reviews.lunr.nl/r/1091/
1 parent 1f560d2 commit 7bee9e2

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/Lunr/Corona/FrontController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use RecursiveIteratorIterator;
1515
use RecursiveRegexIterator;
1616
use RegexIterator;
17+
use RuntimeException;
1718

1819
/**
1920
* Controller class
@@ -143,6 +144,11 @@ public function get_controller(string $src, array $list = [], bool $blacklist =
143144
return '';
144145
}
145146

147+
if (count($matches) > 1)
148+
{
149+
throw new RuntimeException('Found multiple matching controllers!');
150+
}
151+
146152
$search = [ '.php', $src, '/' ];
147153
$replace = [ '', '', '\\' ];
148154

src/Lunr/Corona/Tests/FrontControllerGetTest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
namespace Lunr\Corona\Tests;
1212

13+
use RuntimeException;
14+
1315
/**
1416
* This class contains tests for getting controllers from the FrontController class.
1517
*
@@ -77,23 +79,23 @@ public function testGetControllerReturnsEmptyStringIfNoControllerInfoAvailable()
7779
}
7880

7981
/**
80-
* Test that get_controller() returns the first result if more than one exists.
82+
* Test that get_controller() throws an exception if more than one exists.
8183
*
8284
* @covers Lunr\Corona\FrontController::get_controller
8385
*/
84-
public function testGetControllerReturnsFirstMatchIfMultipleFound(): void
86+
public function testGetControllerThrowsExceptionIfMultipleFound(): void
8587
{
86-
$dir = TEST_STATICS . '/Corona/';
87-
$fqcn = 'Project\\Package2\\FooController';
88+
$dir = TEST_STATICS . '/Corona/';
8889

8990
$this->request->expects($this->exactly(2))
9091
->method('__get')
9192
->with('controller')
9293
->willReturn('foo');
9394

94-
$value = $this->class->get_controller($dir);
95+
$this->expectException(RuntimeException::class);
96+
$this->expectExceptionMessage('Found multiple matching controllers!');
9597

96-
$this->assertEquals($fqcn, $value);
98+
$this->class->get_controller($dir);
9799
}
98100

99101
/**

0 commit comments

Comments
 (0)