diff --git a/build/api/core/Checker.php b/build/api/core/Checker.php index fa786dd..20d727d 100644 --- a/build/api/core/Checker.php +++ b/build/api/core/Checker.php @@ -48,16 +48,12 @@ /* [2] Si de type ARRAY(type_elements) =========================================================*/ - if( preg_match('/^array(?:<(.+)>)?$/', $type, $match) ){ + if( preg_match('/^array(?:<(.+)>)$/', $type, $match) ){ // Si c'est pas un tableau on retourne une erreur if( !is_array($value) ) return false; - // Si c'est un tableau et que 'array' recu - if( $type == 'array' ) - return true; - $elements_type = $match[1]; // On verifie le type pour chaque element diff --git a/spec/build/api/core/CheckerSpec.php b/spec/build/api/core/CheckerSpec.php index c1fe1d0..335fc22 100644 --- a/spec/build/api/core/CheckerSpec.php +++ b/spec/build/api/core/CheckerSpec.php @@ -775,7 +775,7 @@ /* (17) Array ---------------------------------------------------------*/ - context('* array', function(){ + context('* array', function(){ it('pass when empty array', function(){ @@ -783,7 +783,7 @@ expect($arr)->toBeA('array'); expect($arr)->toBeEmpty(); - expect(Checker::run('array', $arr))->toBeTruthy(); + expect(Checker::run('array', $arr))->toBeTruthy(); }); @@ -800,6 +800,17 @@ }); + it('fail when empty array (single type \'array\')', function(){ + + $arr = []; + + expect($arr)->toBeA('array'); + expect($arr)->toBeEmpty(); + + expect(Checker::run('array', $arr))->toBeFalsy(); + + }); + it('pass when recursive empty arrays', function(){ $arr = [[], []]; @@ -810,9 +821,22 @@ expect($arr[0])->toBeEmpty(); expect($arr[1])->toBeEmpty(); - expect(Checker::run('array', $arr))->toBeTruthy(); expect(Checker::run('array', $arr))->toBeTruthy(); - expect(Checker::run('array', $arr))->toBeTruthy(); + expect(Checker::run('array>', $arr))->toBeTruthy(); + + }); + + it('fail when recursive empty arrays (array)', function(){ + + $arr = [[], []]; + + expect($arr)->toBeA('array'); + expect($arr[0])->toBeA('array'); + expect($arr[1])->toBeA('array'); + expect($arr[0])->toBeEmpty(); + expect($arr[1])->toBeEmpty(); + + expect(Checker::run('array', $arr))->toBeFalsy(); }); @@ -824,7 +848,6 @@ expect(Checker::run('id', $id))->toBeTruthy(); expect($arr)->toBeA('array'); - expect(Checker::run('array', $arr))->toBeTruthy(); expect(Checker::run('array', $arr))->toBeTruthy(); expect(Checker::run('array', $arr))->toBeTruthy();