Jyxo\Time\ComposerTest::testInvalidDates PHP Метод

testInvalidDates() публичный Метод

Tests invalid data.
public testInvalidDates ( )
    public function testInvalidDates()
    {
        $composer = new Composer();
        // Invalid date/time parts
        $units = ['second' => [-1, 61], 'minute' => [-1, 61], 'hour' => [-1, 24], 'day' => [0, 32], 'month' => [0, 13], 'year' => [1901, 2038]];
        foreach ($units as $unit => $tests) {
            foreach ($tests as $test) {
                try {
                    $composer->{'set' . ucfirst($unit)}($test);
                } catch (\Exception $e) {
                    $this->assertInstanceOf(\Jyxo\Time\ComposerException::class, $e);
                    $this->assertSame(constant('\\Jyxo\\Time\\ComposerException::' . strtoupper($unit)), $e->getCode(), sprintf('Failed test for unit %s and value %s.', $unit, $test));
                }
            }
        }
        // Incomplete date
        try {
            $date = $composer->getTime();
        } catch (\Exception $e) {
            $this->assertInstanceOf(\Jyxo\Time\ComposerException::class, $e);
            $this->assertSame(ComposerException::NOT_COMPLETE, $e->getCode());
        }
        // Invalid dates
        $tests = ['2002-04-31', '2003-02-29', '2004-02-30', '2005-06-31', '2006-09-31', '2007-11-31'];
        foreach ($tests as $test) {
            try {
                list($year, $month, $day) = explode('-', $test);
                $composer->setDay((int) $day)->setMonth((int) $month)->setYear((int) $year);
                $time = $composer->getTime();
            } catch (\Exception $e) {
                $this->assertInstanceOf(\Jyxo\Time\ComposerException::class, $e);
                $this->assertSame(ComposerException::INVALID, $e->getCode(), sprintf('Failed test for %s.', $test));
            }
        }
    }