Have you set up the provider and alias in config/app.php? Judging from the facade root has not been set message that is where I would start looking.
Feb 25, 2016
14
Level 24
How can I test a custom package that use Facades?
If I have this example class in my package:
<?php
namespace Foo\Bar;
use Illuminate\Support\Facades\DB;
class Example
{
protected $model;
public function __construct($model)
{
$this->model = $model;
}
public function execute()
{
$dummyData = collect([
['foo' => 'bar'],
['foo' => 'baz'],
]);
foreach ($dummyData->chunk(100) as $chunk) {
DB::transaction(function () use ($chunk) {
$this->model->insert($chunk->toArray());
});
}
}
}
And this TestExemple.php
<?php
use Foo\Bar\Example;
class TestExemple extends TestCase
{
/** @test */
function it_should_load_data()
{
$model = $this->getModel(); // TestCase class
$example = new Example($model);
$example->execute();
$this->assertEquals(2, $model->all()->count());
}
}
When i run phpunit i get:
1) TestExemple::it_should_load_data
RuntimeException: A facade root has not been set.
/path/to/package/vendor/illuminate/support/Facades/Facade.php:210
/path/to/package/src/Example.php:24
How can I make the Facade work without a full Laravel installation?
Please or to participate in this conversation.