M
M
Maxim Zolotoy2020-06-14 17:49:50
Laravel
Maxim Zolotoy, 2020-06-14 17:49:50

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

2 answer(s)
Q
qvisn00, 2020-06-18
@spacenear

At the beginning of the setUp method, you need to call parent:setUp() and everything will work

J
JhaoDa, 2020-06-14
@JhaoDa

Because you redefined setUpwithout reading the documentation. She's for suckers, right?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question