Coder Social home page Coder Social logo

Error while writing the test about laravel-data HOT 3 CLOSED

spatie avatar spatie commented on August 29, 2024
Error while writing the test

from laravel-data.

Comments (3)

trianity avatar trianity commented on August 29, 2024 4

I ran into a similar problem.
The spatie/laravel-data package was used in my own package with Pest 2.x test framework.

The error message is: BindingResolutionException Unresolvable dependency resolving [Parameter #0 [ array $config ]] in class Spatie\LaravelData\Support\DataConfig

My PackageTestCase was used as follow:

use Orchestra\Testbench\TestCase;

class PackageTestCase extends TestCase
{
}

Correcting the PackageTestCase the issue was resolved:

use Orchestra\Testbench\TestCase;
use MyPackage\Providers\PackageServiceProvider;
use Spatie\LaravelData\LaravelDataServiceProvider;

class PackageTestCase extends TestCase
{
    protected function setUp(): void
    {
        parent::setUp();
        // additional setup
        config()->set('app.key', '6rE9Nz59bGRbeMATftriyQjrpF7DcOQm');
    }
    
    protected function getPackageProviders($app): array
    {
        return [
            LaravelDataServiceProvider::class,
            PackageServiceProvider::class,
        ];
    }
}

from laravel-data.

nickbeen avatar nickbeen commented on August 29, 2024 1

@inguldima You need to use feature tests, the service provider isn't bound because of the different TestCase class used in unit tests.

//use PHPUnit\Framework\TestCase;
use Tests\TestCase;

from laravel-data.

rubenvanassche avatar rubenvanassche commented on August 29, 2024

Somehow the LaravelDtaaServiceProvider isn't ran: https://github.com/spatie/laravel-data/blob/main/src/LaravelDataServiceProvider.php

Make sure it is otherwise the required bindings are not set up.

from laravel-data.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.