-
-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#663 - Add test case
- Loading branch information
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
namespace Stub; | ||
|
||
class Issue663 | ||
{ | ||
public static function is_array_assoc(arr) -> bool | ||
{ | ||
if (!is_array(arr) || empty(arr)) { | ||
return false; | ||
} | ||
|
||
return static::is_array_assoc_internal(arr); | ||
} | ||
|
||
private static function is_array_assoc_internal(array arr) -> bool | ||
{ | ||
int count, i; | ||
let count = count(arr); | ||
for i in range(0, count - 1) { | ||
if (!isset(arr[i])) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public static function is_array_indexed(arr) -> bool | ||
{ | ||
if (!is_array(arr) || empty(arr)) { | ||
return false; | ||
} | ||
|
||
return !static::is_array_assoc_internal(arr); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Zephir. | ||
* | ||
* (c) Phalcon Team <[email protected]> | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Extension; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Stub\Issue663; | ||
|
||
final class Issue663Test extends TestCase | ||
{ | ||
public function testIssue663(): void | ||
{ | ||
$test = new Issue663(); | ||
|
||
$this->assertFalse($test->is_array_assoc(false)); | ||
$this->assertFalse($test->is_array_assoc(1)); | ||
$this->assertFalse($test->is_array_assoc([])); | ||
$this->assertTrue($test->is_array_assoc(['test' => 'test'])); | ||
$this->assertFalse($test->is_array_assoc(['test'])); | ||
$this->assertFalse($test->is_array_assoc([0 => 'test'])); | ||
|
||
$this->assertFalse($test->is_array_indexed(false)); | ||
$this->assertFalse($test->is_array_indexed(1)); | ||
$this->assertFalse($test->is_array_indexed([])); | ||
$this->assertFalse($test->is_array_indexed(['test' => 'test'])); | ||
$this->assertTrue($test->is_array_indexed(['test'])); | ||
$this->assertTrue($test->is_array_indexed([0 => 'test'])); | ||
} | ||
} |