Larastan: Any way to register service providers?

Created on 20 May 2021  路  8Comments  路  Source: nunomaduro/larastan

Hi there,

I'm working on a custom Laravel package, which uses quite a few other packages as dependencies. For instance, Livewire. When I try to run phpstan against my codebase it complains that classes haven't been registered in the container:

Note: Using configuration file /home/runner/work/laravel-custom/laravel-custom/phpstan.neon.dist.
Illuminate\Contracts\Container\BindingResolutionException thrown in /home/runner/work/laravel-custom/laravel-custom/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 838 while loading bootstrap file /home/runner/work/laravel-custom/laravel-custom/vendor/nunomaduro/larastan/bootstrap.php: Target class [livewire] does not exist.

Is there any way we can register additional service providers when developing a custom package?

Cheers,
E

All 8 comments

Hello,

Do you have orchestra/testbench installed? If not, installing this will probably help you.

@canvural I got orchestra/testbench installed, doesn't help.

@szepeviktor thanks, saw it, but this one is migration-related, isn't it?

I think the problem might be here: https://github.com/nunomaduro/larastan/blob/master/src/ApplicationResolver.php#L46

When we bootstrap the application for the package we only register the actual package service provider and the rest got ignored, hence we have an error related to missing bindings in the container...

I think enabling package auto-discovery in testbench should do the trick.

Hi, I have the same issue (except it's with the package nWidart/laravel-modules and not Livewire), and I don't know how to fix it 馃槥

I think enabling package auto-discovery in testbench should do the trick.

Are you sure ? I have tried but it still does not work :/
But it seems logical to me, the method ignorePackageDiscoveriesFrom must be overrided in the TestCase class, which phpstan does not load or include 馃

I'm am very curious of your findings.

I think I have found a workaround using the testbench bootstrap file.

The issue is when you enter in the else at this point :
https://github.com/nunomaduro/larastan/blob/master/bootstrap.php#L9

So I have created a file bootstrap/app.php containing :

<?php

return include getcwd()."/vendor/orchestra/testbench-core/laravel/bootstrap/app.php";

And it seems to work now, I don't have the Target class ['modules'] does not exist error no more 馃し

Thank you.

@canvural Please consider automating this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hailwood picture hailwood  路  4Comments

bogdankharchenko picture bogdankharchenko  路  4Comments

tranba picture tranba  路  4Comments

gitetsu picture gitetsu  路  4Comments

fico7489 picture fico7489  路  3Comments