Test Failed
Push — main ( bae745...1288aa )
by Michiel
09:14
created

TstampTaskTest::testIllegalLocaleShouldNotFail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * This software consists of voluntary contributions made by many individuals
17
 * and is licensed under the LGPL. For more information please see
18
 * <http://phing.info>.
19
 */
20
21
namespace Phing\Test\Task\System;
22
23
use Phing\Project;
24
use Phing\Task\System\TstampTask;
25
use Phing\Test\Support\BuildFileTest;
26
27
/**
28
 * Tests the Tstamp Task.
29
 *
30
 * - Timezone is always UTC in tests
31
 * - Locale is always en_US in tests
32
 *
33
 * @see tests/build.xml:35
34
 *
35
 * @author  Siad Ardroumli <[email protected]>
36
 *
37
 * @internal
38
 */
39
class TstampTaskTest extends BuildFileTest
40
{
41
    /** @var TstampTask */
42
    private $tstamp;
43
44
    public function setUp(): void
45
    {
46
        $this->configureProject(
47
            PHING_TEST_BASE . '/etc/tasks/system/TstampTest.xml'
48
        );
49
50
        $this->tstamp = new TstampTask();
51
        $this->tstamp->setProject($this->project);
52
    }
53
54
    public function testMagicProperty(): void
55
    {
56
        $this->executeTarget(__FUNCTION__);
57
        $this->assertPropertyEquals('DSTAMP', 19700102);
58
    }
59
60
    public function testMagicPropertyIso(): void
61
    {
62
        $this->executeTarget(__FUNCTION__);
63
        $this->assertPropertyEquals('DSTAMP', 19720417);
64
    }
65
66
    public function testMagicPropertyBoth(): void
67
    {
68
        $this->executeTarget(__FUNCTION__);
69
        $this->assertPropertyEquals('DSTAMP', 19720417);
70
    }
71
72
    public function testMagicPropertyIsoCustomFormat(): void
73
    {
74
        $this->executeTarget(__FUNCTION__);
75
        $this->assertPropertyEquals('tstamp.test', '1972-04-17');
76
    }
77
78
    public function testPrefix(): void
79
    {
80
        $this->tstamp->setPrefix('prefix');
81
        $this->tstamp->main();
82
        $prop = $this->project->getProperty('prefix.DSTAMP');
83
        $this->assertNotNull($prop);
84
    }
85
86
    public function testWarningOnOldSyntax(): void
87
    {
88
        $this->executeTarget(__FUNCTION__);
89
        $this->assertInLogs('pattern attribute must use ICU format https://www.phing.info/guide/chunkhtml/TstampTask.html', Project::MSG_WARN);
90
    }
91
92
    public function testNegativeMagicProperty(): void
93
    {
94
        $this->executeTarget(__FUNCTION__);
95
        $this->assertPropertyEquals('DSTAMP', '19691230');
96
        $this->assertPropertyEquals('TSTAMP', '2013');
97
        $this->assertPropertyEquals('TODAY', 'December 30, 1969');
98
    }
99
100
    public function testTimezone(): void
101
    {
102
        $this->executeTarget(__FUNCTION__);
103
        $this->assertPropertyEquals('caracas', '05:54');
104
        $this->assertPropertyEquals('TSTAMP', '0954'); // UTC in tests
105
    }
106
107
    public function testLocale(): void
108
    {
109
        $this->executeTarget(__FUNCTION__);
110
        $this->assertPropertyEquals('español', 'viernes');
111
    }
112
113
    /**
114
     * @requires PHP >= 8.1
115
     */
116
    public function testIllegalLocaleShouldNotFail(): void
117
    {
118
        $this->executeTarget(__FUNCTION__);
119
        $this->assertPropertyEquals('tstamp.test', '');
120
    }
121
}
122