|
1 | 1 | --TEST--
|
2 |
| -Test of compare object handler for DateTime objects |
| 2 | +Test of compare object handler for DateTimeZone objects |
3 | 3 | --FILE--
|
4 | 4 | <?php
|
5 | 5 |
|
6 |
| -// NB: DateTimeZone class does not define a customized compare class handler so standard object handler will be used |
| 6 | +$timezones = array( |
| 7 | + ['+0200', '-0200'], |
| 8 | + ['EST', 'PST'], |
| 9 | + ['Europe/Amsterdam', 'Europe/Berlin'] |
| 10 | +); |
7 | 11 |
|
8 |
| -echo "Simple test for DateTimeZone compare object handler\n"; |
9 |
| - |
10 |
| -//Set the default time zone |
11 |
| -date_default_timezone_set("Europe/London"); |
12 |
| - |
13 |
| -class DateTimeZoneExt1 extends DateTimeZone { |
14 |
| -} |
15 |
| - |
16 |
| -class DateTimeZoneExt2 extends DateTimeZone{ |
17 |
| - public $foo = "Hello"; |
18 |
| - private $bar = 99; |
| 12 | +foreach ($timezones as [$timezone1, $timezone2]) { |
| 13 | + compare_timezones($timezone1, $timezone1); |
| 14 | + compare_timezones($timezone1, $timezone2); |
19 | 15 | }
|
20 | 16 |
|
21 |
| -class DateTimeZoneExt3 extends DateTimeZoneExt2 { |
| 17 | +var_dump(new DateTimeZone('Europe/Berlin') == new DateTimeZone('CET')); |
| 18 | + |
| 19 | +function compare_timezones($timezone1, $timezone2) |
| 20 | +{ |
| 21 | + $tz1 = new DateTimeZone($timezone1); |
| 22 | + $tz2 = new DateTimeZone($timezone2); |
| 23 | + echo "compare $timezone1 with $timezone2\n"; |
| 24 | + echo "< "; |
| 25 | + var_dump($tz1 < $tz2); |
| 26 | + echo "= "; |
| 27 | + var_dump($tz1 == $tz2); |
| 28 | + echo "> "; |
| 29 | + var_dump($tz1 > $tz2); |
22 | 30 | }
|
23 | 31 |
|
24 |
| -$obj1 = new DateTimeZone("Europe/London"); |
25 |
| -$obj2 = new DateTimeZoneExt1("Europe/London"); |
26 |
| -$obj3 = new DateTimeZoneExt2("Europe/London"); |
27 |
| -$obj4 = new DateTimeZoneExt3("Europe/London"); |
28 |
| - |
29 |
| -echo "\n-- All the following tests should compare equal --\n"; |
30 |
| -var_dump($obj1 == $obj1); |
31 |
| -echo "\n-- All the following tests should compare NOT equal --\n"; |
32 |
| -var_dump($obj1 == $obj2); |
33 |
| -var_dump($obj1 == $obj3); |
34 |
| -var_dump($obj1 == $obj4); |
35 |
| -var_dump($obj2 == $obj3); |
36 |
| -var_dump($obj2 == $obj4); |
37 |
| -var_dump($obj3 == $obj4); |
38 |
| - |
39 | 32 | ?>
|
40 |
| -===DONE=== |
41 |
| ---EXPECT-- |
42 |
| -Simple test for DateTimeZone compare object handler |
43 |
| - |
44 |
| --- All the following tests should compare equal -- |
45 |
| -bool(true) |
46 |
| - |
47 |
| --- All the following tests should compare NOT equal -- |
48 |
| -bool(false) |
49 |
| -bool(false) |
50 |
| -bool(false) |
51 |
| -bool(false) |
52 |
| -bool(false) |
| 33 | +--EXPECTF-- |
| 34 | +compare +0200 with +0200 |
| 35 | +< bool(false) |
| 36 | += bool(true) |
| 37 | +> bool(false) |
| 38 | +compare +0200 with -0200 |
| 39 | +< bool(false) |
| 40 | += bool(false) |
| 41 | +> bool(false) |
| 42 | +compare EST with EST |
| 43 | +< bool(false) |
| 44 | += bool(true) |
| 45 | +> bool(false) |
| 46 | +compare EST with PST |
| 47 | +< bool(false) |
| 48 | += bool(false) |
| 49 | +> bool(false) |
| 50 | +compare Europe/Amsterdam with Europe/Amsterdam |
| 51 | +< bool(false) |
| 52 | += bool(true) |
| 53 | +> bool(false) |
| 54 | +compare Europe/Amsterdam with Europe/Berlin |
| 55 | +< bool(false) |
| 56 | += bool(false) |
| 57 | +> bool(false) |
| 58 | + |
| 59 | +Warning: main(): Trying to compare different kinds of DateTimeZone objects in %s on line %d |
53 | 60 | bool(false)
|
54 |
| -===DONE=== |
|
0 commit comments