Answer the question
In order to leave comments, you need to log in
Why are facades not working in laravel phpunit?
Calling Config::get('promocodes') throws an error RuntimeException : A facade root has not been set.
How do I fix this?
class ProductRepositoryTest extends TestCase
{
protected $productRepository;
protected function setUp(): void
{
$this->productRepository = new ProductRepository(
Product::class,
new ColorRepository(Color::class),
new TagRepository(Tag::class),
new PromocodeService(Config::get('promocodes')),
new InstallmentService()
);
}
/** @test */
public function get_correct_product_by_id()
{
$product = $this->productRepository->get(1);
$this->assertEquals(1, $product->id);
}
}
Answer the question
In order to leave comments, you need to log in
At the beginning of the setUp method, you need to call parent:setUp() and everything will work
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question