Skip to content

Commit

Permalink
Throws an exception if null driver is given.
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed Nov 9, 2017
1 parent df1b0b3 commit ec68820
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
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();
}
}

0 comments on commit ec68820

Please sign in to comment.