Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packages that require laravel-data throw ($throwWhenMaxDepthReached) must be of type bool, null given #731

Closed
RhysLees opened this issue Apr 3, 2024 · 2 comments

Comments

@RhysLees
Copy link
Contributor

RhysLees commented Apr 3, 2024

✏️ Describe the bug
Seems that in packages that require laravel-data, we have to set the following for tests to work.

config()->set('data.throw_when_max_transformation_depth_reached', true);

Related to: #699

Comments in the related issue also experience this

↪️ To Reproduce

Create new package
Create dto
Try convert to array

class BaseData extends Data
{
    public function __construct(
        public bool $something,
    ) {
    }
}


$data = BaseData::fromArray([
    'something' => false,
]);

$data->toArray(); // Error is thrown here

Spatie\LaravelData\Support\Transformation\TransformationContext::__construct(): Argument #11 ($throwWhenMaxDepthReached) must be of type bool, null given, called in /***/vendor/spatie/laravel-data/src/Concerns/TransformableData.php on line 24

✅ Expected behavior
DTO to be converted to Array successfully

🖥️ Versions

Laravel: 11
Laravel Data: 4.4.1
PHP: 8.3

@rubenvanassche
Copy link
Member

Ensure you've got the data service provider running within your package:

    protected function getPackageProviders($app)
    {
        return [
            LaravelPackagePlaygroundServiceProvider::class,
            LaravelDataServiceProvider::class
        ];
    }

@rubenvanassche
Copy link
Member

We've got some new docs on this will be publishing later today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants