A couple of our unit tests require calling Request::create() to function as intended. This RequestStaticValidateToInjectRector rule should never be applied to them since test methods cannot receive injected parameters. Here is an example test method:
#[Test]
public function it_transforms_provisional_load_transaction_correctly(): void
{
$transaction = ProvisionalLoadTransaction::factory()->create([
'bill_type' => BillType::ACCESSORIAL,
'rate_type' => ChargeType::OTHER,
'amount' => 123.45,
'currency' => 'USD',
'note' => 'Test note',
]);
$resource = new ProvisionalLoadTransactionResource($transaction);
$request = Request::create('/dummy-url');
$transformed = $resource->toArray($request);
$this->assertSame($transaction->id, $transformed['id']);
$this->assertSame(BillType::ACCESSORIAL, $transformed['bill_type']);
$this->assertSame(ChargeType::OTHER, $transformed['rate_type']);
$this->assertSame('123.45', $transformed['amount']);
$this->assertSame('USD', $transformed['currency']);
$this->assertSame('Test note', $transformed['note']);
}
I propose that this rule should never be applied to unit tests for this reason.
PS: I've already tried manually skipping it in the rector.php config file:
->withSkip([
RequestStaticValidateToInjectRector::class => [
__DIR__ . '/tests',
__DIR__ . '/Modules/*/tests',
],
]);
But since our project uses Laravel Modules, it seems Rector doesn't support glob patterns in paths. I've raised an issue about this over on their project, as well.
A couple of our unit tests require calling
Request::create()to function as intended. ThisRequestStaticValidateToInjectRectorrule should never be applied to them since test methods cannot receive injected parameters. Here is an example test method:#[Test] public function it_transforms_provisional_load_transaction_correctly(): void { $transaction = ProvisionalLoadTransaction::factory()->create([ 'bill_type' => BillType::ACCESSORIAL, 'rate_type' => ChargeType::OTHER, 'amount' => 123.45, 'currency' => 'USD', 'note' => 'Test note', ]); $resource = new ProvisionalLoadTransactionResource($transaction); $request = Request::create('/dummy-url'); $transformed = $resource->toArray($request); $this->assertSame($transaction->id, $transformed['id']); $this->assertSame(BillType::ACCESSORIAL, $transformed['bill_type']); $this->assertSame(ChargeType::OTHER, $transformed['rate_type']); $this->assertSame('123.45', $transformed['amount']); $this->assertSame('USD', $transformed['currency']); $this->assertSame('Test note', $transformed['note']); }I propose that this rule should never be applied to unit tests for this reason.
PS: I've already tried manually skipping it in the
rector.phpconfig file:But since our project uses Laravel Modules, it seems Rector doesn't support glob patterns in paths. I've raised an issue about this over on their project, as well.