Eliminate Most Scrutinizer Problems in Test Suite (#2699)

* Eliminate Most Scrutinizer Problems in Test Suite

Mostly minor code changes, with some annotations.

* Missed 2 php-cs-fixer Problems

They should be fixed now.
This commit is contained in:
oleibman 2022-03-21 13:58:42 -07:00 committed by GitHub
parent 2482203c3e
commit c112802023
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 184 additions and 147 deletions

View File

@ -41,7 +41,7 @@ class CalculationFunctionListTest extends TestCase
* @param array|string $functionCall
* @param string $argumentCount
*/
public function testGetFunctions($category, $functionCall, $argumentCount): void
public function testGetFunctions(/** @scrutinizer ignore-unused */ $category, $functionCall, /** @scrutinizer ignore-unused */ $argumentCount): void
{
self::assertIsCallable($functionCall);
}

View File

@ -4,16 +4,10 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\TestCase;
class ComplexTest extends TestCase
{
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerCOMPLEX
*
@ -21,7 +15,15 @@ class ComplexTest extends TestCase
*/
public function testCOMPLEX($expectedResult, ...$args): void
{
$result = Engineering::COMPLEX(...$args);
if (count($args) === 0) {
$result = Engineering::COMPLEX();
} elseif (count($args) === 1) {
$result = Engineering::COMPLEX($args[0]);
} elseif (count($args) === 2) {
$result = Engineering::COMPLEX($args[0], $args[1]);
} else {
$result = Engineering::COMPLEX($args[0], $args[1], $args[2]);
}
self::assertEquals($expectedResult, $result);
}

View File

@ -4,16 +4,10 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\TestCase;
class DollarDeTest extends TestCase
{
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerDOLLARDE
*
@ -21,7 +15,13 @@ class DollarDeTest extends TestCase
*/
public function testDOLLARDE($expectedResult, ...$args): void
{
$result = Financial::DOLLARDE(...$args);
if (count($args) === 0) {
$result = Financial::DOLLARDE();
} elseif (count($args) === 1) {
$result = Financial::DOLLARDE($args[0]);
} else {
$result = Financial::DOLLARDE($args[0], $args[1]);
}
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
}

View File

@ -3,16 +3,10 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\TestCase;
class DollarFrTest extends TestCase
{
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerDOLLARFR
*
@ -20,7 +14,13 @@ class DollarFrTest extends TestCase
*/
public function testDOLLARFR($expectedResult, ...$args): void
{
$result = Financial::DOLLARFR(...$args);
if (count($args) === 0) {
$result = Financial::DOLLARFR();
} elseif (count($args) === 1) {
$result = Financial::DOLLARFR($args[0]);
} else {
$result = Financial::DOLLARFR($args[0], $args[1]);
}
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
}

View File

@ -3,16 +3,10 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\TestCase;
class FvTest extends TestCase
{
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerFV
*
@ -20,7 +14,19 @@ class FvTest extends TestCase
*/
public function testFV($expectedResult, array $args): void
{
$result = Financial::FV(...$args);
if (count($args) === 0) {
$result = Financial::FV();
} elseif (count($args) === 1) {
$result = Financial::FV($args[0]);
} elseif (count($args) === 2) {
$result = Financial::FV($args[0], $args[1]);
} elseif (count($args) === 3) {
$result = Financial::FV($args[0], $args[1], $args[2]);
} elseif (count($args) === 4) {
$result = Financial::FV($args[0], $args[1], $args[2], $args[3]);
} else {
$result = Financial::FV($args[0], $args[1], $args[2], $args[3], $args[4]);
}
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
}

View File

@ -3,16 +3,10 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\TestCase;
class NPerTest extends TestCase
{
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerNPER
*
@ -20,7 +14,19 @@ class NPerTest extends TestCase
*/
public function testNPER($expectedResult, array $args): void
{
$result = Financial::NPER(...$args);
if (count($args) === 0) {
$result = Financial::NPER();
} elseif (count($args) === 1) {
$result = Financial::NPER($args[0]);
} elseif (count($args) === 2) {
$result = Financial::NPER($args[0], $args[1]);
} elseif (count($args) === 3) {
$result = Financial::NPER($args[0], $args[1], $args[2]);
} elseif (count($args) === 4) {
$result = Financial::NPER($args[0], $args[1], $args[2], $args[3]);
} else {
$result = Financial::NPER($args[0], $args[1], $args[2], $args[3], $args[4]);
}
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
}

View File

@ -3,16 +3,10 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\TestCase;
class PDurationTest extends TestCase
{
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerPDURATION
*
@ -20,7 +14,15 @@ class PDurationTest extends TestCase
*/
public function testPDURATION($expectedResult, array $args): void
{
$result = Financial::PDURATION(...$args);
if (count($args) === 0) {
$result = Financial::PDURATION();
} elseif (count($args) === 1) {
$result = Financial::PDURATION($args[0]);
} elseif (count($args) === 2) {
$result = Financial::PDURATION($args[0], $args[1]);
} else {
$result = Financial::PDURATION($args[0], $args[1], $args[2]);
}
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
}

View File

@ -3,16 +3,10 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\TestCase;
class PmtTest extends TestCase
{
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerPMT
*
@ -23,7 +17,13 @@ class PmtTest extends TestCase
$interestRate = array_shift($args);
$numberOfPeriods = array_shift($args);
$presentValue = array_shift($args);
$result = Financial::PMT($interestRate, $numberOfPeriods, $presentValue, ...$args);
if (count($args) === 0) {
$result = Financial::PMT($interestRate, $numberOfPeriods, $presentValue);
} elseif (count($args) === 1) {
$result = Financial::PMT($interestRate, $numberOfPeriods, $presentValue, $args[0]);
} else {
$result = Financial::PMT($interestRate, $numberOfPeriods, $presentValue, $args[0], $args[1]);
}
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
}

View File

@ -3,16 +3,10 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\TestCase;
class PvTest extends TestCase
{
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerPV
*
@ -20,7 +14,19 @@ class PvTest extends TestCase
*/
public function testPV($expectedResult, array $args): void
{
$result = Financial::PV(...$args);
if (count($args) === 0) {
$result = Financial::PV();
} elseif (count($args) === 1) {
$result = Financial::PV($args[0]);
} elseif (count($args) === 2) {
$result = Financial::PV($args[0], $args[1]);
} elseif (count($args) === 3) {
$result = Financial::PV($args[0], $args[1], $args[2]);
} elseif (count($args) === 4) {
$result = Financial::PV($args[0], $args[1], $args[2], $args[3]);
} else {
$result = Financial::PV($args[0], $args[1], $args[2], $args[3], $args[4]);
}
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
}

View File

@ -3,16 +3,10 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\TestCase;
class RriTest extends TestCase
{
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerRRI
*
@ -20,7 +14,15 @@ class RriTest extends TestCase
*/
public function testRRI($expectedResult, array $args): void
{
$result = Financial::RRI(...$args);
if (count($args) === 0) {
$result = Financial::RRI();
} elseif (count($args) === 1) {
$result = Financial::RRI($args[0]);
} elseif (count($args) === 2) {
$result = Financial::RRI($args[0], $args[1]);
} else {
$result = Financial::RRI($args[0], $args[1], $args[2]);
}
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
}

View File

@ -12,9 +12,13 @@ class UsDollarTest extends TestCase
*
* @param mixed $expectedResult
*/
public function testUSDOLLAR($expectedResult, ...$args): void
public function testUSDOLLAR($expectedResult, float $amount, ?int $precision = null): void
{
$result = Dollar::format(...$args);
if ($precision === null) {
$result = Dollar::format($amount);
} else {
$result = Dollar::format($amount, $precision);
}
self::assertSame($expectedResult, $result);
}

View File

@ -2,17 +2,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Logical;
use PHPUnit\Framework\TestCase;
class IfTest extends TestCase
{
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerIF
*
@ -20,7 +14,15 @@ class IfTest extends TestCase
*/
public function testIF($expectedResult, ...$args): void
{
$result = Logical::statementIf(...$args);
if (count($args) === 0) {
$result = Logical::statementIf();
} elseif (count($args) === 1) {
$result = Logical::statementIf($args[0]);
} elseif (count($args) === 2) {
$result = Logical::statementIf($args[0], $args[1]);
} else {
$result = Logical::statementIf($args[0], $args[1], $args[2]);
}
self::assertEquals($expectedResult, $result);
}

View File

@ -3,17 +3,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Logical;
use PHPUnit\Framework\TestCase;
class NotTest extends TestCase
{
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerNOT
*
@ -21,7 +15,11 @@ class NotTest extends TestCase
*/
public function testNOT($expectedResult, ...$args): void
{
$result = Logical::NOT(...$args);
if (count($args) === 0) {
$result = Logical::NOT();
} else {
$result = Logical::NOT($args[0]);
}
self::assertEquals($expectedResult, $result);
}

View File

@ -17,7 +17,7 @@ class RandArrayTest extends AllSetupTeardown
$result = MathTrig\Random::randArray($rows, $cols, $min, $max, true);
self::assertIsArray($result);
self::assertCount($rows, $result);
self::assertCount($rows, /** @scrutinizer ignore-type */ $result);
self::assertIsArray($result[0]);
self::assertCount($cols, $result[0]);
@ -40,7 +40,7 @@ class RandArrayTest extends AllSetupTeardown
$result = MathTrig\Random::randArray($rows, $cols, $min, $max, false);
self::assertIsArray($result);
self::assertCount($rows, $result);
self::assertCount($rows, /** @scrutinizer ignore-type */ $result);
self::assertIsArray($result[0]);
self::assertCount($cols, $result[0]);

View File

@ -62,7 +62,7 @@ class RandBetweenTest extends AllSetupTeardown
self::assertIsArray($result);
self::assertCount($expectedRows, $result);
self::assertIsArray($result[0]);
self::assertCount($expectedColumns, $result[0]);
self::assertCount($expectedColumns, /** @scrutinizer ignore-type */ $result[0]);
}
public function providerRandBetweenArray(): array

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig\MatrixFunctions;
class SequenceTest extends AllSetupTeardown
{
@ -14,7 +14,17 @@ class SequenceTest extends AllSetupTeardown
*/
public function testSEQUENCE(array $arguments, $expectedResult): void
{
$result = MathTrig\MatrixFunctions::sequence(...$arguments);
if (count($arguments) === 0) {
$result = MatrixFunctions::sequence();
} elseif (count($arguments) === 1) {
$result = MatrixFunctions::sequence($arguments[0]);
} elseif (count($arguments) === 2) {
$result = MatrixFunctions::sequence($arguments[0], $arguments[1]);
} elseif (count($arguments) === 3) {
$result = MatrixFunctions::sequence($arguments[0], $arguments[1], $arguments[2]);
} else {
$result = MatrixFunctions::sequence($arguments[0], $arguments[1], $arguments[2], $arguments[3]);
}
self::assertEquals($expectedResult, $result);
}

View File

@ -17,11 +17,16 @@ class GrowthTest extends TestCase
* @dataProvider providerGROWTH
*
* @param mixed $expectedResult
* @param mixed $yValues
*/
public function testGROWTH($expectedResult, $yValues, ...$args): void
public function testGROWTH($expectedResult, array $yValues, array $xValues, ?array $newValues = null, ?bool $const = null): void
{
$result = Statistical::GROWTH($yValues, ...$args);
if ($newValues === null) {
$result = Statistical::GROWTH($yValues, $xValues);
} elseif ($const === null) {
$result = Statistical::GROWTH($yValues, $xValues, $newValues);
} else {
$result = Statistical::GROWTH($yValues, $xValues, $newValues, $const);
}
self::assertEqualsWithDelta($expectedResult, $result[0], 1E-12);
}

View File

@ -17,11 +17,16 @@ class TrendTest extends TestCase
* @dataProvider providerGROWTH
*
* @param mixed $expectedResult
* @param mixed $yValues
*/
public function testTREND($expectedResult, $yValues, ...$args): void
public function testTREND($expectedResult, array $yValues, array $xValues, ?array $newValues = null, ?bool $const = null): void
{
$result = Statistical::TREND($yValues, ...$args);
if ($newValues === null) {
$result = Statistical::TREND($yValues, $xValues);
} elseif ($const === null) {
$result = Statistical::TREND($yValues, $xValues, $newValues);
} else {
$result = Statistical::TREND($yValues, $xValues, $newValues, $const);
}
self::assertEqualsWithDelta($expectedResult, $result[0], 1E-12);
}

View File

@ -23,7 +23,7 @@ class WebServiceTest extends TestCase
*/
public function testWEBSERVICE(string $expectedResult, string $url, ?array $responseData): void
{
if ($responseData) {
if (!empty($responseData)) {
$body = $this->createMock(StreamInterface::class);
$body->expects(self::atMost(1))->method('getContents')->willReturn($responseData[1]);

View File

@ -76,12 +76,10 @@ class FunctionsTest extends TestCase
/**
* @dataProvider providerIfCondition
*
* @param mixed $expectedResult
*/
public function testIfCondition($expectedResult, ...$args): void
public function testIfCondition(string $expectedResult, string $args): void
{
$result = Functions::ifCondition(...$args);
$result = Functions::ifCondition($args);
self::assertEquals($expectedResult, $result);
}

View File

@ -32,16 +32,18 @@ class AddressHelperTest extends TestCase
?int $row = null,
?int $column = null
): void {
$args = [];
if ($row !== null) {
$args[] = $row;
if ($row === null) {
if ($column === null) {
$actualValue = AddressHelper::convertToA1($address);
} else {
$actualValue = AddressHelper::convertToA1($address, $column);
}
if ($column !== null) {
$args[] = $column;
} elseif ($column === null) {
$actualValue = AddressHelper::convertToA1($address, $row);
} else {
$actualValue = AddressHelper::convertToA1($address, $row, $column);
}
$actualValue = AddressHelper::convertToA1($address, ...$args);
self::assertSame($expectedValue, $actualValue);
}

View File

@ -265,7 +265,7 @@ class CoordinateTest extends TestCase
$cellRange = null;
// @phpstan-ignore-next-line
Coordinate::buildRange($cellRange);
Coordinate::buildRange(/** @scrutinizer ignore-type */ $cellRange);
}
public function testBuildRangeInvalid2(): void

View File

@ -155,11 +155,17 @@ class PropertiesTest extends TestCase
*
* @param mixed $expectedType
* @param mixed $expectedValue
* @param mixed $propertyName
* @param string $propertyName
* @param mixed $propertyValue
* @param ?string $propertyType
*/
public function testSetCustomProperties($expectedType, $expectedValue, $propertyName, ...$args): void
public function testSetCustomProperties($expectedType, $expectedValue, $propertyName, $propertyValue, $propertyType = null): void
{
$this->properties->setCustomProperty($propertyName, ...$args);
if ($propertyType === null) {
$this->properties->setCustomProperty($propertyName, $propertyValue);
} else {
$this->properties->setCustomProperty($propertyName, $propertyValue, $propertyType);
}
self::assertTrue($this->properties->isCustomPropertySet($propertyName));
self::assertSame($expectedType, $this->properties->getCustomPropertyType($propertyName));
$result = $this->properties->getCustomPropertyValue($propertyName);

View File

@ -81,39 +81,13 @@ class IOFactoryTest extends TestCase
/**
* @dataProvider providerIdentify
*
* @param string $file
* @param string $expectedName
* @param string $expectedClass
*/
public function testIdentify($file, $expectedName, $expectedClass): void
public function testIdentifyCreateLoad(string $file, string $expectedName, string $expectedClass): void
{
$actual = IOFactory::identify($file);
self::assertSame($expectedName, $actual);
}
/**
* @dataProvider providerIdentify
*
* @param string $file
* @param string $expectedName
* @param string $expectedClass
*/
public function testCreateReaderForFile($file, $expectedName, $expectedClass): void
{
$actual = IOFactory::createReaderForFile($file);
self::assertSame($expectedClass, get_class($actual));
}
/**
* @dataProvider providerIdentify
*
* @param string $file
* @param string $expectedName
* @param string $expectedClass
*/
public function testLoad($file, $expectedName, $expectedClass): void
{
$actual = IOFactory::load($file);
self::assertInstanceOf(Spreadsheet::class, $actual);
}

View File

@ -176,9 +176,9 @@ class DateTest extends TestCase
*
* @param mixed $expectedResult
*/
public function testIsDateTimeFormatCode($expectedResult, ...$args): void
public function testIsDateTimeFormatCode($expectedResult, string $format): void
{
$result = Date::isDateTimeFormatCode(...$args);
$result = Date::isDateTimeFormatCode($format);
self::assertEquals($expectedResult, $result);
}

View File

@ -78,11 +78,14 @@ class ColorTest extends TestCase
* @dataProvider providerColorGetRed
*
* @param mixed $expectedResult
* @param mixed $color
*/
public function testGetRed($expectedResult, $color, ...$args): void
public function testGetRed($expectedResult, string $color, ?bool $bool = null): void
{
$result = Color::getRed($color, ...$args);
if ($bool === null) {
$result = Color::getRed($color);
} else {
$result = Color::getRed($color, $bool);
}
self::assertEquals($expectedResult, $result);
}
@ -95,11 +98,14 @@ class ColorTest extends TestCase
* @dataProvider providerColorGetGreen
*
* @param mixed $expectedResult
* @param mixed $color
*/
public function testGetGreen($expectedResult, $color, ...$args): void
public function testGetGreen($expectedResult, string $color, ?bool $bool = null): void
{
$result = Color::getGreen($color, ...$args);
if ($bool === null) {
$result = Color::getGreen($color);
} else {
$result = Color::getGreen($color, $bool);
}
self::assertEquals($expectedResult, $result);
}
@ -112,11 +118,14 @@ class ColorTest extends TestCase
* @dataProvider providerColorGetBlue
*
* @param mixed $expectedResult
* @param mixed $color
*/
public function testGetBlue($expectedResult, $color, ...$args): void
public function testGetBlue($expectedResult, string $color, ?bool $bool = null): void
{
$result = Color::getBlue($color, ...$args);
if ($bool === null) {
$result = Color::getBlue($color);
} else {
$result = Color::getBlue($color, $bool);
}
self::assertEquals($expectedResult, $result);
}

View File

@ -44,7 +44,7 @@ class ColumnCellIteratorTest extends TestCase
self::assertEquals($ColumnCellIndexResult++, $key);
self::assertInstanceOf(Cell::class, $ColumnCell);
}
$transposed = array_map(null, ...self::CELL_VALUES);
$transposed = array_map(/** @scrutinizer ignore-type */ null, ...self::CELL_VALUES);
self::assertSame($transposed[0], $values);
$spreadsheet->disconnectWorksheets();
}