MonthTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. class MonthTest extends AllSetupTeardown
  5. {
  6. /**
  7. * @dataProvider providerMONTH
  8. *
  9. * @param mixed $expectedResult
  10. */
  11. public function testMONTH($expectedResult, string $dateTimeValue): void
  12. {
  13. $this->mightHaveException($expectedResult);
  14. $sheet = $this->getSheet();
  15. $sheet->getCell('A1')->setValue("=MONTH($dateTimeValue)");
  16. $sheet->getCell('B1')->setValue('1954-11-23');
  17. self::assertSame($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
  18. }
  19. public function providerMONTH(): array
  20. {
  21. return require 'tests/data/Calculation/DateTime/MONTH.php';
  22. }
  23. /**
  24. * @dataProvider providerMonthArray
  25. */
  26. public function testMonthArray(array $expectedResult, string $array): void
  27. {
  28. $calculation = Calculation::getInstance();
  29. $formula = "=MONTH({$array})";
  30. $result = $calculation->_calculateFormulaValue($formula);
  31. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  32. }
  33. public function providerMonthArray(): array
  34. {
  35. return [
  36. 'row vector' => [[[1, 6, 1]], '{"2022-01-01", "2022-06-01", "2023-01-01"}'],
  37. 'column vector' => [[[1], [3], [6]], '{"2022-01-01"; "2022-03-01"; "2022-06-01"}'],
  38. 'matrix' => [[[1, 4], [8, 12]], '{"2022-01-01", "2022-04-01"; "2022-08-01", "2022-12-01"}'],
  39. ];
  40. }
  41. }