File: IntlDateFormatterTest.php

package info (click to toggle)
php-symfony-polyfill 1.33.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 8,520 kB
  • sloc: php: 127,232; makefile: 69
file content (132 lines) | stat: -rw-r--r-- 3,935 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Polyfill\Tests\Intl\Icu\Verification;

use PHPUnit\Framework\Attributes\DataProvider;
use Symfony\Polyfill\Intl\Icu\IntlDateFormatter;
use Symfony\Polyfill\Tests\Intl\Icu\AbstractIntlDateFormatterTestCase;

/**
 * Verifies that {@link AbstractIntlDateFormatterTest} matches the behavior of
 * the {@link \IntlDateFormatter} class in a specific version of ICU.
 *
 * @author Bernhard Schussek <bschussek@gmail.com>
 *
 * @requires extension intl
 *
 * @group class-polyfill
 */
class IntlDateFormatterTest extends AbstractIntlDateFormatterTestCase
{
    /**
     * @dataProvider formatProvider
     */
    #[DataProvider('formatProvider')]
    public function testFormat($pattern, $timestamp, $expected)
    {
        if (\PHP_VERSION_ID < 70105 && $timestamp instanceof \DateTimeImmutable) {
            $this->markTestSkipped('PHP >= 7.1.5 required for DateTimeImmutable.');
        }

        parent::testFormat($pattern, $timestamp, $expected);
    }

    /**
     * @dataProvider formatTimezoneProvider
     */
    #[DataProvider('formatTimezoneProvider')]
    public function testFormatTimezone($pattern, $timezone, $expected)
    {
        if (version_compare(\INTL_ICU_VERSION, '59.1', '<')) {
            $this->markTestSkipped('ICU version 59.1 is required.');
        }

        parent::testFormatTimezone($pattern, $timezone, $expected);
    }

    public function testFormatUtcAndGmtAreSplit()
    {
        if (version_compare(\INTL_ICU_VERSION, '59.1', '<')) {
            $this->markTestSkipped('ICU version 59.1 is required.');
        }

        parent::testFormatUtcAndGmtAreSplit();
    }

    /**
     * @dataProvider dateAndTimeTypeProvider
     */
    #[DataProvider('dateAndTimeTypeProvider')]
    public function testDateAndTimeType($timestamp, $datetype, $timetype, $expected)
    {
        if (version_compare(\INTL_ICU_VERSION, '59.1', '<')) {
            $this->markTestSkipped('ICU version 59.1 is required.');
        }

        parent::testDateAndTimeType($timestamp, $datetype, $timetype, $expected);
    }

    /**
     * @requires PHP 8
     *
     * @dataProvider relativeDateTypeProvider
     */
    #[DataProvider('relativeDateTypeProvider')]
    public function testRelativeDateType($timestamp, $datetype, $timetype, $expected)
    {
        if (version_compare(\INTL_ICU_VERSION, '59.1', '<')) {
            $this->markTestSkipped('ICU version 59.1 is required.');
        }

        parent::testRelativeDateType($timestamp, $datetype, $timetype, $expected);
    }

    /**
     * @requires PHP 8
     */
    public function testFormatIgnoresPatternForRelativeDateType()
    {
        if (version_compare(\INTL_ICU_VERSION, '59.1', '<')) {
            $this->markTestSkipped('ICU version 59.1 is required.');
        }

        parent::testFormatIgnoresPatternForRelativeDateType();
    }

    protected function getDateFormatter($locale, $datetype, $timetype, $timezone = null, $calendar = IntlDateFormatter::GREGORIAN, $pattern = null)
    {
        if (version_compare(\INTL_ICU_VERSION, '55.1', '<')) {
            $this->markTestSkipped('ICU version 55.1 is required.');
        }

        if (!$formatter = new \IntlDateFormatter($locale, $datetype, $timetype, $timezone, $calendar, $pattern)) {
            throw new \InvalidArgumentException(intl_get_error_message());
        }

        return $formatter;
    }

    protected function getIntlErrorMessage(): string
    {
        return intl_get_error_message();
    }

    protected function getIntlErrorCode(): int
    {
        return intl_get_error_code();
    }

    protected function isIntlFailure($errorCode): bool
    {
        return intl_is_failure($errorCode);
    }
}