-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Improving bad bundle exception in _controller #11210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,6 +107,36 @@ public function getMissingControllersTest() | |
); | ||
} | ||
|
||
/** | ||
* @expectedException | ||
* @dataProvider getInvalidBundleNameTests | ||
*/ | ||
public function testInvalidBundleName($bundleName, $suggestedBundleName) | ||
{ | ||
$parser = $this->createParser(); | ||
|
||
try { | ||
$parser->parse($bundleName); | ||
} catch (\Exception $e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. given that you can all exceptions, this will never fail if there is no exception (PHPUnit failures are exception). You should use the PHPUnit |
||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->parse() throws a \InvalidArgumentException if the bundle does not exist'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this does not actually test the new feature. You need to test the message |
||
|
||
if (false === $suggestedBundleName) { | ||
// make sure we don't have a suggestion | ||
$this->assertNotContains('Did you mean', $e->getMessage()); | ||
} else { | ||
$this->assertContains(sprintf('Did you mean "%s"', $suggestedBundleName), $e->getMessage()); | ||
} | ||
} | ||
} | ||
|
||
public function getInvalidBundleNameTests() | ||
{ | ||
return array( | ||
array('FoodBundle:Default:index', 'FooBundle:Default:index'), | ||
array('CrazyBundle:Default:index', false), | ||
); | ||
} | ||
|
||
private function createParser() | ||
{ | ||
$bundles = array( | ||
|
@@ -121,6 +151,10 @@ private function createParser() | |
->expects($this->any()) | ||
->method('getBundle') | ||
->will($this->returnCallback(function ($bundle) use ($bundles) { | ||
if (!isset($bundles[$bundle])) { | ||
throw new \InvalidArgumentException(sprintf('Invalid bundle name "%s"', $bundle)); | ||
} | ||
|
||
return $bundles[$bundle]; | ||
})) | ||
; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing phpdoc