Мутанты не были охвачены тестами в PHP Infection

Я провожу несколько тестов на мутацию ("infection/infection": "^0.26.1") и по какой-то неизвестной причине PHP Infection утверждает, что есть тесты, которые не покрываются даже написанными там юнит-тестами.

Вот ошибка, предполагаемая инфекцией:

      1) /opt/www/app/Infrastructure/Http/Resources/Mobile/PaymentMethods/PaymentMethodsCollection.php:34    [M] ArrayItemRemoval

--- Original
+++ New
@@ @@
         $paymentMethods = PaymentMethodsResource::collection($collection['PaymentMethods'] ?? []);
         $balance = BalanceResource::make(
             $collection['Balance'] ?? ['balance' => '0.00', 'withdraw_balance' => '0.00', 'withdraw_balance_from_credits' => '0.00']
         );
         $defaultPaymentMethod = DefaultPaymentMethodResource::make($collection['DefaultPaymentMethod'] ?? null);

-        return ['data' => ['PaymentMethods' => $paymentMethods, 'Balance' => $balance, 'DefaultPaymentMethod' => $defaultPaymentMethod]];
+        return [];
     }
 }

Вот модульный тест, покрывающий такой сценарий:

          /**
     * @dataProvider dataProvider
     */
    public function testToArray($input, $output): void
    {
        $this->service = new PaymentMethodsCollection($input);

        $result = $this->service->toArray();

        $this->assertNotEmpty($result);
        $this->assertArrayHasKey('data', $result);
        $this->assertArrayHasKey('PaymentMethods', $result['data']);
        $this->assertArrayHasKey('Balance', $result['data']);
        $this->assertArrayHasKey('DefaultPaymentMethod', $result['data']);

        $this->assertInstanceOf(ResourceCollection::class,
            $result['data']['PaymentMethods']
        );
        $this->assertInstanceOf(BalanceResource::class,
            $result['data']['Balance']
        );
        $this->assertInstanceOf(DefaultPaymentMethodResource::class,
            $result['data']['DefaultPaymentMethod']
        );
    }

Если я запускаю модульные тесты изолированно, результат будет таким:

      Payment Methods Collection (Test\Unit\Infrastructure\Http\Resources\Mobile\PaymentMethods\PaymentMethodsCollection)
 ✔ To array with only·balance·empty
 ✔ To array with full·empty
 ✔ To array with only·default·payment·method·empty
 ✔ To array with only·payments·methods·empty
 ✔ To array with filled

Time: 00:01.257, Memory: 28.00 MB

OK (5 tests, 45 assertions)

Переходим к настройке Infection:

      {
    "$schema": "vendor/infection/infection/resources/schema.json",
    "source": {
        "directories": [
            "app"
        ]
    },
    "tmpDir": "tmp",
    "logs": {
        "text": "test/reports/infection/infection.log",
        "html": "test/reports/infection/infection.html"
    },
    "mutators": {
        "@default": true,
        "@function_signature": false
    },
    "testFramework":"phpunit",
    "testFrameworkOptions": "--testsuite=Unit",
    "phpUnit": {
        "configDir": "test/Infection"
    }
} 

Почему PHP-инфекция утверждает, что она не защищена?

Где проблема, которую я не вижу?

Понятие «не охвачено» — это когда модульный тест не охватывает этот сценарий и оставляет мутанта в живых, верно?

0 ответов

Другие вопросы по тегам