From: Erik Bernhardson Date: Wed, 23 Sep 2015 21:07:44 +0000 (-0700) Subject: Remove $this reference in static method X-Git-Tag: 1.31.0-rc.0~9850^2 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=91aebb607209837c52899047ac68a17297382aa6;hp=889283b16ee96e7127cb1296d525620602e427f3;p=lhc%2Fweb%2Fwiklou.git Remove $this reference in static method Adds a couple tests to demonstrate the problem and fixes it. Change-Id: Ib15088e83ad333fb126446fad86f97ae12ff6e74 --- diff --git a/includes/utils/AvroValidator.php b/includes/utils/AvroValidator.php index 4f8e0b177b..89341eaf23 100644 --- a/includes/utils/AvroValidator.php +++ b/includes/utils/AvroValidator.php @@ -93,22 +93,19 @@ class AvroValidator { } $errors = array(); foreach ($datum as $d) { - $result = $this->validate( $schema->items(), $d ); + $result = self::getErrors( $schema->items(), $d ); if ( $result ) { $errors[] = $result; } } - if ( $errors ) { - return $errors; - } - return array(); + return $errors; case AvroSchema::MAP_SCHEMA: if (!is_array($datum)) { return self::wrongType( 'array', $datum ); } $errors = array(); foreach ($datum as $k => $v) { - if ( !is_string($k) ) { + if ( !is_string($k) ) { $errors[] = self::wrongType( 'string key', $k ); } $result = self::getErrors( $schema->values(), $v ); diff --git a/tests/phpunit/includes/utils/AvroValidatorTest.php b/tests/phpunit/includes/utils/AvroValidatorTest.php index 52c242c17d..d63af9af57 100644 --- a/tests/phpunit/includes/utils/AvroValidatorTest.php +++ b/tests/phpunit/includes/utils/AvroValidatorTest.php @@ -19,6 +19,10 @@ class AvroValidatorTest extends PHPUnit_Framework_TestCase { public function getErrorsProvider() { $stringSchema = AvroSchema::parse( json_encode( array( 'type' => 'string' ) ) ); + $stringArraySchema = AvroSchema::parse( json_encode( array( + 'type' => 'array', + 'items' => 'string', + ) ) ); $recordSchema = AvroSchema::parse( json_encode( array( 'type' => 'record', 'name' => 'ut', @@ -80,6 +84,18 @@ class AvroValidatorTest extends PHPUnit_Framework_TestCase { ) ) ) ), + array( + 'Empty array is accepted', + $stringArraySchema, array(), array() + ), + array( + 'correct array element accepted', + $stringArraySchema, array( 'fizzbuzz' ), array() + ), + array( + 'incorrect array element rejected', + $stringArraySchema, array( '12', 34 ), array( 'Expected string, but recieved integer' ) + ), ); }