Skip to content

Commit 9d82a01

Browse files
committed
Clean up DateTimeZone::getLocation() test
And avoid invalid array access.
1 parent dfe5fd2 commit 9d82a01

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

ext/date/tests/DateTimeZone_getLocation.phpt

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
--TEST--
2-
DateTimeZone::getLocation -- timezone_location_get — Returns location information for a timezone public array DateTimeZone::getLocation ( void ) ;
2+
Test DateTimeZone::getLocation()
33
--CREDITS--
44
marcosptf - <marcosptf@yahoo.com.br> - #phparty7 - @phpsp - novatec/2015 - sao paulo - br
55
--FILE--
66
<?php
7-
$arrayDate = DateTimeZone::listAbbreviations();
87
$countryCode = array("??");
98
$countryCodeTest = array("AU", "CA", "ET", "AF", "US", "KZ", "AM");
109

11-
foreach($arrayDate as $value){
12-
13-
if(NULL != $value[0]['timezone_id']){
10+
foreach (DateTimeZone::listAbbreviations() as $value) {
11+
if (NULL != $value[0]['timezone_id']) {
1412
$timeZone = new DateTimeZone($value[0]['timezone_id']);
1513
$timeZoneArray = $timeZone->getLocation();
14+
if (false === $timeZoneArray) {
15+
continue;
16+
}
1617

17-
if((!in_array($timeZoneArray['country_code'], $countryCode)) && (NULL != $timeZoneArray['country_code']) && ("" != $timeZoneArray['country_code'])) {
18+
if (!in_array($timeZoneArray['country_code'], $countryCode) && NULL != $timeZoneArray['country_code']) {
1819
array_push($countryCode, $timeZoneArray['country_code']);
1920

2021
if(in_array($timeZoneArray['country_code'], $countryCodeTest)){
@@ -24,12 +25,6 @@ foreach($arrayDate as $value){
2425
}
2526
}
2627
?>
27-
--CLEAN--
28-
<?php
29-
unset($arrayDate);
30-
unset($countryCode);
31-
unset($countryCodeTest);
32-
?>
3328
--EXPECTF--
3429
Array
3530
(

0 commit comments

Comments
 (0)