SumIfTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
  3. class SumIfTest extends AllSetupTeardown
  4. {
  5. /**
  6. * @dataProvider providerSUMIF
  7. *
  8. * @param mixed $expectedResult
  9. * @param mixed $condition
  10. */
  11. public function testSUMIF2($expectedResult, array $array1, $condition, ?array $array2 = null): void
  12. {
  13. $this->mightHaveException($expectedResult);
  14. if ($expectedResult === 'incomplete') {
  15. self::markTestIncomplete('Raises formula error - researching solution');
  16. }
  17. $sheet = $this->getSheet();
  18. $sheet->fromArray($array1, null, 'A1', true);
  19. $maxARow = count($array1);
  20. $firstArg = "A1:A$maxARow";
  21. $this->setCell('B1', $condition);
  22. $secondArg = 'B1';
  23. if (empty($array2)) {
  24. $sheet->getCell('D1')->setValue("=SUMIF($firstArg, $secondArg)");
  25. } else {
  26. $sheet->fromArray($array2, null, 'C1', true);
  27. $maxCRow = count($array2);
  28. $thirdArg = "C1:C$maxCRow";
  29. $sheet->getCell('D1')->setValue("=SUMIF($firstArg, $secondArg, $thirdArg)");
  30. }
  31. $result = $sheet->getCell('D1')->getCalculatedValue();
  32. self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
  33. }
  34. public function providerSUMIF(): array
  35. {
  36. return require 'tests/data/Calculation/MathTrig/SUMIF.php';
  37. }
  38. }