Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
77.42% covered (warning)
77.42%
24 / 31
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_wrapper_gmgetdate_test
77.42% covered (warning)
77.42%
24 / 31
50.00% covered (danger)
50.00%
1 / 2
4.18
0.00% covered (danger)
0.00%
0 / 1
 phpbb_gmgetdate_data
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 test_phpbb_gmgetdate
100.00% covered (success)
100.00%
24 / 24
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14class phpbb_wrapper_gmgetdate_test extends phpbb_test_case
15{
16    public static function phpbb_gmgetdate_data(): array
17    {
18        return [
19            [''],
20            ['UTC'],
21            ['Europe/Berlin'],
22            ['America/Los_Angeles'],
23            ['Pacific/Auckland'],
24        ];
25    }
26
27    /**
28     * @dataProvider phpbb_gmgetdate_data
29     */
30    public function test_phpbb_gmgetdate($timezone_identifier)
31    {
32        if ($timezone_identifier)
33        {
34            $current_timezone = date_default_timezone_get();
35            date_default_timezone_set($timezone_identifier);
36        }
37
38        $expected = time();
39
40        $date_array = phpbb_gmgetdate($expected);
41
42        $actual = gmmktime(
43            $date_array['hours'],
44            $date_array['minutes'],
45            $date_array['seconds'],
46            $date_array['mon'],
47            $date_array['mday'],
48            $date_array['year']
49        );
50
51        // Calling second-granularity time functions twice isn't guaranteed to
52        // give the same results. As long as they're in the right order, allow
53        // a 1 second difference.
54        $this->assertGreaterThanOrEqual(
55            $expected, $actual,
56            'Expected second time to be after (or equal to) the previous one'
57        );
58        $this->assertLessThanOrEqual(
59            1,
60            abs($actual - $expected),
61            "Expected $actual to be within 1 second of $expected."
62        );
63
64        if (isset($current_timezone))
65        {
66            date_default_timezone_set($current_timezone);
67        }
68    }
69}