Files
PhpSpreadsheet/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeTest.php
T
oleibman 1e8ff9f852 DateTimeExcel - Change Names of funcWhatever to evaluate (#2015)
* DateTimeExcel - Change Names of funcWhatever to evaluate

Per discussions while MathTrig was being broken up, this would help standardize the code. This PR applies that standardization to the DateTimeExcel family of functions.

The deprecation messages in DateTime.php are changed to match the style used in PR #2005.

All Phpstan grandfathered errors (about 25) in DateTimeExcel are fixed and removed from baseline. A small number (about 5) of phpstan annotations in the source members in that directory are also fixed and eliminated.
2021-04-24 18:56:58 +02:00

64 lines
1.8 KiB
PHP

<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Time;
class TimeTest extends AllSetupTeardown
{
/**
* @dataProvider providerTIME
*
* @param mixed $expectedResult
*/
public function testTIME($expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->sheet;
$sheet->getCell('B1')->setValue('15');
$sheet->getCell('B2')->setValue('32');
$sheet->getCell('B3')->setValue('50');
$sheet->getCell('A1')->setValue("=TIME($formula)");
self::assertEqualsWithDelta($expectedResult, $sheet->getCell('A1')->getCalculatedValue(), 1E-8);
}
public function providerTIME(): array
{
return require 'tests/data/Calculation/DateTime/TIME.php';
}
public function testTIMEtoUnixTimestamp(): void
{
self::setUnixReturn();
$result = Time::evaluate(7, 30, 20);
self::assertEqualsWithDelta(27020, $result, 1E-8);
}
public function testTIMEtoDateTimeObject(): void
{
self::setObjectReturn();
$result = Time::evaluate(7, 30, 20);
// Must return an object...
self::assertIsObject($result);
// ... of the correct type
self::assertTrue(is_a($result, 'DateTimeInterface'));
// ... with the correct value
self::assertEquals($result->format('H:i:s'), '07:30:20');
}
public function testTIME1904(): void
{
self::setMac1904();
$result = Time::evaluate(0, 0, 0);
self::assertEquals(0, $result);
}
public function testTIME1900(): void
{
$result = Time::evaluate(0, 0, 0);
self::assertEquals(0, $result);
}
}