Home > Blockchain >  Deprecated: Return type of PHPUnit\Framework\TestCase::count() should either be compatible with Co
Deprecated: Return type of PHPUnit\Framework\TestCase::count() should either be compatible with Co

Time:11-21

please help me with an error. I updated my app to php 8.1 and now I am getting this error :

Deprecated: Return type of PHPUnit\Framework\TestCase::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in path

TestCase :

/**
 * Counts the number of test cases executed by run(TestResult result).
 *
 * @return int
 */
public function count()
{
    return 1;
}

I tried adding #[\ReturnTypeWillChange] in annotations :

/**
 * Counts the number of test cases executed by run(TestResult result).
 *
 * [\ReturnTypeWillChange]
 */
public function count()
{
    return 1;
}

CodePudding user response:

Just change the signature so it returns an int. If the countable interface is implemented, the signature must match.

public function count(): int
{
    return 1;
}
  •  Tags:  
  • php
  • Related