Skip to content
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

[5.6] Throws an exception if null driver is given. #22018

Merged
merged 1 commit into from
Nov 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Illuminate/Support/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public function driver($driver = null)
{
$driver = $driver ?: $this->getDefaultDriver();

if (is_null($driver)) {
throw new InvalidArgumentException("Unable to resolve NULL driver for ".get_called_class());
}

// If the given driver has not been created before, we will create the instances
// here and cache it so we can return it next time very quickly. If there is
// already a driver created by this name, we'll just return that instance.
Expand Down
18 changes: 18 additions & 0 deletions tests/Integration/Support/Fixtures/NullableManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Illuminate\Tests\Integration\Support\Fixtures;

use Illuminate\Support\Manager;

class NullableManager extends Manager
{
/**
* Get the default driver name.
*
* @return string
*/
public function getDefaultDriver()
{
return null;
}
}
17 changes: 17 additions & 0 deletions tests/Integration/Support/ManagerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Illuminate\Tests\Integration\Support;

use Orchestra\Testbench\TestCase;

class ManagerTest extends TestCase
{
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Unable to resolve NULL driver for Illuminate\Tests\Integration\Support\Fixtures\NullableManager
*/
public function testDefaultDriverCannotBeNull()
{
(new Fixtures\NullableManager($this->app))->driver();
}
}