2026-10-05 18:10:18 -04:00
<? php
declare ( strict_types = 1 );
namespace Rules\Tests\Rules ;
use PHPStan\Rules\Rule ;
use PHPStan\Testing\RuleTestCase ;
2026-10-08 19:17:30 -04:00
use Rules\Laravel\Rules\NoServiceConstructionRule ;
2026-10-05 18:10:18 -04:00
/**
* @extends RuleTestCase<NoServiceConstructionRule>
*/
final class NoServiceConstructionRuleTest extends RuleTestCase
{
2026-10-08 19:17:30 -04:00
public function test_rule () : void
2026-10-05 18:10:18 -04:00
{
$message = 'Runtime code constructs the service `App\Services\ReportBuilder` instead of receiving it. Inject it through the constructor and let the container own the wiring.' ;
$this -> analyse ([ __DIR__ . '/data/no-service-construction.php' ], [
[ $message , 24 ],
[ $message , 29 ],
[ $message , 34 ],
]);
}
2026-10-08 19:17:30 -04:00
protected function getRule () : Rule
{
return new NoServiceConstructionRule ([ 'App\\Services\\' ], [ 'app/Providers/**' ]);
}
2026-10-05 18:10:18 -04:00
}