From 267c1b31b766bd1c295927e62c48582d0896721c Mon Sep 17 00:00:00 2001 From: Thomas Ploch Date: Fri, 30 Aug 2019 08:26:49 +0200 Subject: [PATCH] =?UTF-8?q?Drop=20PHP=207.1=20from=20build=20environment?= =?UTF-8?q?=20and=20allow=20`beberlei/assert`=20v=E2=80=A6=20(#29)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [CI] Drop PHP 7.1 from build environment * [UR] Going full PHP 7.2 mode * [CS] Fixing coding standards * [CI] Upgrade `phpstan` to 0.11.x * [TEST] Removed unneeded assertion in `DefaultRecordSerializerFactoryTest` * [DOCKER] Fix build to support 7.2 and 7.3 * [TEST] Serializer factory should always produce new instances * [DEPEND] `beberlei/assert` fails with PHP 7.3 * [DEPEND] Remove support for `symfony/serializer` 2.x --- .travis.yml | 13 ++-- Dockerfile | 9 +-- Makefile | 2 +- README.md | 71 ++++++++++++------- benchmarks/AvroEncodingBench.php | 12 +++- bin/php | 2 +- composer.json | 12 ++-- .../Symfony/Serializer/AvroSerDeEncoder.php | 11 +++ .../Exceptions/AvroDecodingException.php | 3 +- .../Exceptions/AvroEncodingException.php | 3 +- src/Objects/Exceptions/Exceptions.php | 2 +- src/Objects/HasSchemaDefinitionInterface.php | 2 +- src/Objects/RecordSerializer.php | 2 +- src/Objects/SchemaResolverInterface.php | 2 +- .../SchemaResolvers/CallableResolver.php | 12 +++- src/Objects/SchemaResolvers/ChainResolver.php | 2 +- .../DefinitionInterfaceResolver.php | 21 ++++-- src/Objects/SchemaResolvers/FileResolver.php | 12 +++- src/Protocol.php | 2 + src/Serialize.php | 25 +++++-- test/AbstractFunctionalTestCase.php | 3 + test/CommonTest.php | 4 +- .../DefaultRecordSerializerFactoryTest.php | 6 +- test/Objects/RecordSerializerTest.php | 24 +++++++ .../SchemaResolvers/CallableResolverTest.php | 5 ++ .../SchemaResolvers/ChainResolverTest.php | 23 ++++-- .../DefinitionInterfaceResolverTest.php | 2 + .../SchemaResolvers/FileResolverTest.php | 31 +++++--- test/SerializeTest.php | 36 +++++++--- 29 files changed, 260 insertions(+), 94 deletions(-) diff --git a/.travis.yml b/.travis.yml index d448eca..dffddeb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,8 +6,8 @@ services: - docker php: -- '7.1' - '7.2' +- '7.3' env: global: @@ -15,11 +15,10 @@ env: matrix: - DEPENDENCIES="low" - DEPENDENCIES="stable" - - DEPENDENCIES="stable" INTEGRATION_TEST="enabled" CONFLUENT_VERSION="3.2.4" - - DEPENDENCIES="stable" INTEGRATION_TEST="enabled" CONFLUENT_VERSION="3.3.2" - - DEPENDENCIES="stable" INTEGRATION_TEST="enabled" CONFLUENT_VERSION="4.0.2" - - DEPENDENCIES="stable" INTEGRATION_TEST="enabled" CONFLUENT_VERSION="4.1.2" - - DEPENDENCIES="stable" INTEGRATION_TEST="enabled" CONFLUENT_VERSION="5.0.1" + - DEPENDENCIES="stable" INTEGRATION_TEST="enabled" CONFLUENT_VERSION="3.3.3" + - DEPENDENCIES="stable" INTEGRATION_TEST="enabled" CONFLUENT_VERSION="4.1.3" + - DEPENDENCIES="stable" INTEGRATION_TEST="enabled" CONFLUENT_VERSION="5.2.3" + - DEPENDENCIES="stable" INTEGRATION_TEST="enabled" CONFLUENT_VERSION="latest" before_script: - make install-phars @@ -38,7 +37,7 @@ script: jobs: include: - stage: coverage - php: 7.2 + php: '7.2' env: - DEPENDENCIES="stable" script: diff --git a/Dockerfile b/Dockerfile index 84d63cc..4aaf98b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,12 @@ -ARG PHP_VERSION=7.1 +ARG PHP_VERSION=7.2 FROM php:${PHP_VERSION}-cli-alpine -ARG XDEBUG_VERSION=2.6.1 +ARG XDEBUG_VERSION=2.7.2 -RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS zlib-dev \ - && apk add --no-cache --virtual .runtime-deps git \ +RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \ + && apk add --no-cache --virtual .runtime-deps git libzip-dev \ + && docker-php-ext-configure zip --with-libzip=/usr/include \ && docker-php-ext-install zip \ && pecl install xdebug-$XDEBUG_VERSION \ && docker-php-ext-enable xdebug \ diff --git a/Makefile b/Makefile index 843f8ae..d460429 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ ZOOKEEPER_IPV4 ?= 192.168.104.101 COMPOSER ?= bin/composer.phar PHP ?= bin/php PHP_VERSION ?= 7.2 -XDEBUG_VERSION ?= 2.6.1 +XDEBUG_VERSION ?= 2.7.2 export docker: diff --git a/README.md b/README.md index bd9ca9a..5d60b68 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Avro SerDe for PHP 7.1+ +# Avro SerDe for PHP 7.2+ [![Build Status](https://travis-ci.org/flix-tech/avro-serde-php.svg?branch=master)](https://travis-ci.org/flix-tech/avro-serde-php) [![Latest Stable Version](https://poser.pugx.org/flix-tech/avro-serde-php/version)](https://packagist.org/packages/flix-tech/avro-serde-php) @@ -27,7 +27,7 @@ integrates FlixTech's [Schema Registry Client](https://github.com/flix-tech/sche This library is using the [composer package manager](https://getcomposer.org/) for PHP. ```bash -composer require 'flix-tech/avro-serde-php:^1.0' +composer require 'flix-tech/avro-serde-php:^2.0' ``` ## Quickstart @@ -45,11 +45,16 @@ for more detailed information. ```php 'registry.example.com']) +use FlixTech\SchemaRegistryApi\Registry\Cache\AvroObjectCacheAdapter; +use FlixTech\SchemaRegistryApi\Registry\CachedRegistry; +use FlixTech\SchemaRegistryApi\Registry\PromisingRegistry; +use GuzzleHttp\Client; + +$schemaRegistryClient = new CachedRegistry( + new PromisingRegistry( + new Client(['base_uri' => 'registry.example.com']) ), - new \FlixTech\SchemaRegistryApi\Registry\Cache\AvroObjectCacheAdapter() + new AvroObjectCacheAdapter() ); ``` @@ -61,14 +66,16 @@ The `RecordSerializer` is the main way you interact with this library. It provid ```php false, + RecordSerializer::OPTION_REGISTER_MISSING_SCHEMAS => false, // If you want to auto-register missing subjects set this to true - \FlixTech\AvroSerializer\Objects\RecordSerializer::OPTION_REGISTER_MISSING_SUBJECTS => false, + RecordSerializer::OPTION_REGISTER_MISSING_SUBJECTS => false, ] ); ``` @@ -126,6 +133,8 @@ is targeting a key schema. namespace MyNamespace; use FlixTech\AvroSerializer\Objects\SchemaResolvers\FileResolver; +use function get_class;use function is_object; +use function str_replace; class MyRecord {} @@ -133,10 +142,10 @@ $record = new MyRecord(); $baseDir = __DIR__ . '/files'; -$inflector = function ($record, bool $isKey) { +$inflector = static function ($record, bool $isKey) { $ext = $isKey ? '.key.avsc' : '.avsc'; - $fileName = \is_object($record) - ? \str_replace('\\', '.', \get_class($record)) + $fileName = is_object($record) + ? str_replace('\\', '.', get_class($record)) : 'default'; return $fileName . $ext; @@ -160,6 +169,10 @@ value- or key-schemas respectively. A key schema resolver is optional. ```php 'bar' ]; $schema = $resolver->valueSchemaFor($record); -\PHPUnit\Framework\Assert::assertEquals($schema, $valueSchema); +Assert::assertEquals($schema, $valueSchema); ``` ### DefinitionInterfaceResolver @@ -265,6 +278,12 @@ This library provides integrations with the [Symfony Serializer component](https ```php serialize( $user, - \FlixTech\AvroSerializer\Integrations\Symfony\Serializer\AvroSerDeEncoder::FORMAT_AVRO, + AvroSerDeEncoder::FORMAT_AVRO, [ - \FlixTech\AvroSerializer\Integrations\Symfony\Serializer\AvroSerDeEncoder::CONTEXT_ENCODE_SUBJECT => 'users-value', - \FlixTech\AvroSerializer\Integrations\Symfony\Serializer\AvroSerDeEncoder::CONTEXT_ENCODE_WRITERS_SCHEMA => \AvroSchema::parse($avroSchemaJson), + AvroSerDeEncoder::CONTEXT_ENCODE_SUBJECT => 'users-value', + AvroSerDeEncoder::CONTEXT_ENCODE_WRITERS_SCHEMA => AvroSchema::parse($avroSchemaJson), ] ); $deserializedUser = $symfonySerializer->deserialize( $serialized, User::class, - \FlixTech\AvroSerializer\Integrations\Symfony\Serializer\AvroSerDeEncoder::FORMAT_AVRO + AvroSerDeEncoder::FORMAT_AVRO ); -\PHPUnit\Framework\Assert::assertEquals($deserializedUser, $user); +Assert::assertEquals($deserializedUser, $user); ``` diff --git a/benchmarks/AvroEncodingBench.php b/benchmarks/AvroEncodingBench.php index 770cf94..21edc7f 100644 --- a/benchmarks/AvroEncodingBench.php +++ b/benchmarks/AvroEncodingBench.php @@ -66,6 +66,10 @@ class AvroEncodingBench */ private $schema; + /** + * @throws \AvroSchemaParseException + * @throws \FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException + */ public function setUp(): void { $this->schema = \AvroSchema::parse(self::SCHEMA_JSON); @@ -194,7 +198,13 @@ public function benchDecodeWithSyncCachedRegistry(): void $this->serializers[self::SYNC_CACHED]->decodeMessage($this->messages[self::SYNC_CACHED]); } - private function prepareTestForMode(string $mode, Registry $registry) + /** + * @param string $mode + * @param \FlixTech\SchemaRegistryApi\Registry $registry + * + * @throws \FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException + */ + private function prepareTestForMode(string $mode, Registry $registry): void { $result = $registry->register('test', $this->schema); !$result instanceof PromiseInterface ?: $result->wait(); diff --git a/bin/php b/bin/php index bd2550b..d464966 100755 --- a/bin/php +++ b/bin/php @@ -7,7 +7,7 @@ command -v docker >/dev/null 2>&1 || { echo "docker is required to run this bina USER=${USER:-$( id -un )} GROUP=${GROUP:-$( id -gn )} COMPOSER_HOME=${COMPOSER_HOME:-${HOME}/.composer} -PHP_VERSION=${PHP_VERSION:-7.1} +PHP_VERSION=${PHP_VERSION:-7.2} DOCKER_OPTS=${DOCKER_OPTS:-'-it'} exec docker run ${DOCKER_OPTS} --rm \ diff --git a/composer.json b/composer.json index 87a3401..19dd90e 100644 --- a/composer.json +++ b/composer.json @@ -23,18 +23,18 @@ } ], "require": { - "php": "^7.1", - "beberlei/assert": "~2.7", - "flix-tech/confluent-schema-registry-api": "^6.0.0", + "php": "^7.2", + "beberlei/assert": "^2.9.9|~3.0", + "flix-tech/confluent-schema-registry-api": "~7.0", "flix-tech/avro-php": "^3.0.0", "widmogrod/php-functional": "^4.2|^5.0" }, "require-dev": { - "phpunit/phpunit": "~7.0", - "phpstan/phpstan-shim": "^0.10", + "phpunit/phpunit": "~7.0,<8.0", + "phpstan/phpstan-shim": "^0.11", "phpbench/phpbench": "~0.9", "vlucas/phpdotenv": "~2.4", - "symfony/serializer": "^2.8|^3.1|^4.0" + "symfony/serializer": "^3.4|^4.3" }, "autoload": { "psr-4": { diff --git a/integrations/Symfony/Serializer/AvroSerDeEncoder.php b/integrations/Symfony/Serializer/AvroSerDeEncoder.php index 434a5e4..14bbcc2 100644 --- a/integrations/Symfony/Serializer/AvroSerDeEncoder.php +++ b/integrations/Symfony/Serializer/AvroSerDeEncoder.php @@ -27,6 +27,11 @@ public function __construct(RecordSerializer $recordSerializer) $this->recordSerializer = $recordSerializer; } + /** + * {@inheritdoc} + * + * @throws \FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException + */ public function decode($data, $format, array $context = []) { $readersSchema = $context[self::CONTEXT_DECODE_READERS_SCHEMA] ?? null; @@ -40,6 +45,12 @@ public function supportsDecoding($format): bool return self::FORMAT_AVRO === $format; } + /** + * {@inheritdoc} + * + * @throws \AvroSchemaParseException + * @throws \FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException + */ public function encode($data, $format, array $context = []) { $this->validateEncodeContext($context); diff --git a/src/Objects/Exceptions/AvroDecodingException.php b/src/Objects/Exceptions/AvroDecodingException.php index c26abe4..a063dc5 100644 --- a/src/Objects/Exceptions/AvroDecodingException.php +++ b/src/Objects/Exceptions/AvroDecodingException.php @@ -5,7 +5,8 @@ namespace FlixTech\AvroSerializer\Objects\Exceptions; use FlixTech\AvroSerializer\Objects\AvroSerializerException; +use RuntimeException; -class AvroDecodingException extends \RuntimeException implements AvroSerializerException +class AvroDecodingException extends RuntimeException implements AvroSerializerException { } diff --git a/src/Objects/Exceptions/AvroEncodingException.php b/src/Objects/Exceptions/AvroEncodingException.php index 4b456b0..8a3edc6 100644 --- a/src/Objects/Exceptions/AvroEncodingException.php +++ b/src/Objects/Exceptions/AvroEncodingException.php @@ -5,7 +5,8 @@ namespace FlixTech\AvroSerializer\Objects\Exceptions; use FlixTech\AvroSerializer\Objects\AvroSerializerException; +use RuntimeException; -class AvroEncodingException extends \RuntimeException implements AvroSerializerException +class AvroEncodingException extends RuntimeException implements AvroSerializerException { } diff --git a/src/Objects/Exceptions/Exceptions.php b/src/Objects/Exceptions/Exceptions.php index 68268fb..dbc1655 100644 --- a/src/Objects/Exceptions/Exceptions.php +++ b/src/Objects/Exceptions/Exceptions.php @@ -20,7 +20,7 @@ public static function forEncode($record, \AvroSchema $schema, \Exception $previ "$exportedRecord" Schema: -"{$schema->__toString()}" +"{(string) $schema}" MESSAGE; return new AvroEncodingException($message, self::ERROR_ENCODING, $previous); diff --git a/src/Objects/HasSchemaDefinitionInterface.php b/src/Objects/HasSchemaDefinitionInterface.php index 877a167..3f25ff7 100644 --- a/src/Objects/HasSchemaDefinitionInterface.php +++ b/src/Objects/HasSchemaDefinitionInterface.php @@ -8,5 +8,5 @@ interface HasSchemaDefinitionInterface { public static function valueSchemaJson(): string; - public static function keySchemaJson(); + public static function keySchemaJson(): ?string; } diff --git a/src/Objects/RecordSerializer.php b/src/Objects/RecordSerializer.php index 643ec71..106f656 100644 --- a/src/Objects/RecordSerializer.php +++ b/src/Objects/RecordSerializer.php @@ -142,7 +142,7 @@ public function decodeMessage(string $binaryMessage, AvroSchema $readersSchema = /** @var \Widmogrod\Monad\Either\Either $read */ $read = $validated - ->orElse(function () { throw new \InvalidArgumentException('Could not validate message wire protocol.'); }) + ->orElse(static function () { throw new \InvalidArgumentException('Could not validate message wire protocol.'); }) ->bind($this->avroBinaryGetter) ->bind($cachedReader($readersSchema)); diff --git a/src/Objects/SchemaResolverInterface.php b/src/Objects/SchemaResolverInterface.php index 41a6da5..a285c01 100644 --- a/src/Objects/SchemaResolverInterface.php +++ b/src/Objects/SchemaResolverInterface.php @@ -23,5 +23,5 @@ public function valueSchemaFor($record): AvroSchema; * * @return AvroSchema|null */ - public function keySchemaFor($record); + public function keySchemaFor($record): ?AvroSchema; } diff --git a/src/Objects/SchemaResolvers/CallableResolver.php b/src/Objects/SchemaResolvers/CallableResolver.php index 3dc7ef8..5a8ecc0 100644 --- a/src/Objects/SchemaResolvers/CallableResolver.php +++ b/src/Objects/SchemaResolvers/CallableResolver.php @@ -19,17 +19,27 @@ class CallableResolver implements SchemaResolverInterface */ private $keySchemaResolverCallable; - public function __construct(callable $valueSchemaResolverCallable, callable $keySchemaResolverCallable = null) + public function __construct(callable $valueSchemaResolverCallable, ?callable $keySchemaResolverCallable = null) { $this->valueSchemaResolverCallable = $valueSchemaResolverCallable; $this->keySchemaResolverCallable = $keySchemaResolverCallable; } + /** + * {@inheritdoc} + * + * @throws \AvroSchemaParseException + */ public function valueSchemaFor($record): AvroSchema { return AvroSchema::parse(\call_user_func($this->valueSchemaResolverCallable, $record)); } + /** + * {@inheritdoc} + * + * @throws \AvroSchemaParseException + */ public function keySchemaFor($record): ?AvroSchema { if (!$this->keySchemaResolverCallable) { diff --git a/src/Objects/SchemaResolvers/ChainResolver.php b/src/Objects/SchemaResolvers/ChainResolver.php index a40dbad..ab5d65a 100644 --- a/src/Objects/SchemaResolvers/ChainResolver.php +++ b/src/Objects/SchemaResolvers/ChainResolver.php @@ -34,7 +34,7 @@ public function valueSchemaFor($record): AvroSchema ); } - public function keySchemaFor($record) + public function keySchemaFor($record): ?AvroSchema { $keySchema = null; diff --git a/src/Objects/SchemaResolvers/DefinitionInterfaceResolver.php b/src/Objects/SchemaResolvers/DefinitionInterfaceResolver.php index a64e98e..d497b61 100644 --- a/src/Objects/SchemaResolvers/DefinitionInterfaceResolver.php +++ b/src/Objects/SchemaResolvers/DefinitionInterfaceResolver.php @@ -11,6 +11,13 @@ class DefinitionInterfaceResolver implements SchemaResolverInterface { + /** + * @param mixed $record + * + * @return \AvroSchema + * + * @throws \AvroSchemaParseException + */ public function valueSchemaFor($record): AvroSchema { /** @var HasSchemaDefinitionInterface $record */ @@ -19,7 +26,14 @@ public function valueSchemaFor($record): AvroSchema return AvroSchema::parse($record::valueSchemaJson()); } - public function keySchemaFor($record) + /** + * @param mixed $record + * + * @return \AvroSchema|null + * + * @throws \AvroSchemaParseException + */ + public function keySchemaFor($record): ?AvroSchema { $this->guardRecordHasDefinition($record); @@ -32,10 +46,7 @@ public function keySchemaFor($record) return AvroSchema::parse($keySchemaJson); } - /** - * @param HasSchemaDefinitionInterface $record - */ - private function guardRecordHasDefinition($record) + private function guardRecordHasDefinition($record): void { Assert::that($record) ->isObject() diff --git a/src/Objects/SchemaResolvers/FileResolver.php b/src/Objects/SchemaResolvers/FileResolver.php index 70c4d4d..7879527 100644 --- a/src/Objects/SchemaResolvers/FileResolver.php +++ b/src/Objects/SchemaResolvers/FileResolver.php @@ -26,6 +26,11 @@ public function __construct(string $baseDir, callable $inflector) $this->inflector = $inflector; } + /** + * {@inheritdoc} + * + * @throws \AvroSchemaParseException + */ public function valueSchemaFor($record): AvroSchema { $inflectedFileName = \call_user_func($this->inflector, $record, false); @@ -38,7 +43,12 @@ public function valueSchemaFor($record): AvroSchema return AvroSchema::parse((string) @\file_get_contents($filePath)); } - public function keySchemaFor($record) + /** + * {@inheritdoc} + * + * @throws \AvroSchemaParseException + */ + public function keySchemaFor($record): ?AvroSchema { $inflectedFileName = \call_user_func($this->inflector, $record, true); Assert::that($inflectedFileName)->string()->notEmpty(); diff --git a/src/Protocol.php b/src/Protocol.php index cc75c20..18924bf 100644 --- a/src/Protocol.php +++ b/src/Protocol.php @@ -29,6 +29,7 @@ function version(): int function encode(int $protocolVersion, int $schemaId, string $avroEncodedBinaryString): Either { + /** @var bool|string $packed */ $packed = @\pack('CNA*', $protocolVersion, $schemaId, $avroEncodedBinaryString); return false !== $packed @@ -63,6 +64,7 @@ function decode(string $binaryString): Either PROTOCOL_ACCESSOR_AVRO ); + /** @var array|bool $unpacked */ $unpacked = @\unpack( $packedFormat, $binaryString diff --git a/src/Serialize.php b/src/Serialize.php index 2917375..2276832 100644 --- a/src/Serialize.php +++ b/src/Serialize.php @@ -17,6 +17,13 @@ const avroStringIo = '\FlixTech\AvroSerializer\Serialize\avroStringIo'; +/** + * @param string $contents + * + * @return \AvroStringIO + * + * @throws \AvroIOException + */ function avroStringIo(string $contents): AvroStringIO { return new AvroStringIO($contents); @@ -38,6 +45,11 @@ function avroBinaryDecoder(AvroStringIO $io): AvroIOBinaryDecoder const avroDatumWriter = '\FlixTech\AvroSerializer\Serialize\avroDatumWriter'; +/** + * @return callable + * + * @throws \AvroIOException + */ function avroDatumWriter(): callable { $writer = new AvroIODatumWriter(); @@ -51,13 +63,13 @@ function avroDatumWriter(): callable function writeDatum(AvroIODatumWriter $writer, AvroStringIO $io, AvroSchema $schema, $record): Either { return tryCatch( - function ($record) use ($schema, $writer, $io) { + static function ($record) use ($schema, $writer, $io) { $io->truncate(); $writer->write_data($schema, $record, avroBinaryEncoder($io)); return Right::of($io->string()); }, - function (\AvroException $e) use ($record, $schema) { + static function (\AvroException $e) use ($record, $schema) { return Left::of( Exceptions::forEncode($record, $schema, $e) ); @@ -68,6 +80,11 @@ function (\AvroException $e) use ($record, $schema) { const avroDatumReader = '\FlixTech\AvroSerializer\Serialize\avroDatumReader'; +/** + * @return callable + * + * @throws \AvroIOException + */ function avroDatumReader(): callable { $reader = new AvroIODatumReader(); @@ -86,14 +103,14 @@ function readDatum( $data ): Either { return tryCatch( - function ($data) use ($writersSchema, $readersSchema, $reader, $io) { + static function ($data) use ($writersSchema, $readersSchema, $reader, $io) { $io->truncate(); $io->write($data); $io->seek(0); return Right::of($reader->read_data($writersSchema, $readersSchema, avroBinaryDecoder($io))); }, - function (\AvroException $e) use ($data) { + static function (\AvroException $e) use ($data) { return Left::of( Exceptions::forDecode($data, $e) ); diff --git a/test/AbstractFunctionalTestCase.php b/test/AbstractFunctionalTestCase.php index 77bf63b..da84a7c 100644 --- a/test/AbstractFunctionalTestCase.php +++ b/test/AbstractFunctionalTestCase.php @@ -68,6 +68,9 @@ abstract class AbstractFunctionalTestCase extends TestCase */ protected $invalidSchema; + /** + * @throws \AvroSchemaParseException + */ protected function setUp() { $this->avroSchema = AvroSchema::parse(self::SCHEMA_JSON); diff --git a/test/CommonTest.php b/test/CommonTest.php index 17fe364..96f2c47 100644 --- a/test/CommonTest.php +++ b/test/CommonTest.php @@ -19,7 +19,7 @@ class CommonTest extends AbstractFunctionalTestCase /** * @test */ - public function get_should_return_Maybe_monad() + public function get_should_return_Maybe_monad(): void { $array = [ PROTOCOL_ACCESSOR_VERSION => 0, @@ -37,7 +37,7 @@ public function get_should_return_Maybe_monad() /** * @test */ - public function getter_returns_curried_get() + public function getter_returns_curried_get(): void { $this->assertEquals( curryN(2, get), diff --git a/test/Objects/DefaultRecordSerializerFactoryTest.php b/test/Objects/DefaultRecordSerializerFactoryTest.php index f25bf18..c0d094c 100644 --- a/test/Objects/DefaultRecordSerializerFactoryTest.php +++ b/test/Objects/DefaultRecordSerializerFactoryTest.php @@ -5,7 +5,6 @@ namespace FlixTech\AvroSerializer\Test\Objects; use FlixTech\AvroSerializer\Objects\DefaultRecordSerializerFactory; -use FlixTech\AvroSerializer\Objects\RecordSerializer; use PHPUnit\Framework\TestCase; class DefaultRecordSerializerFactoryTest extends TestCase @@ -15,8 +14,9 @@ class DefaultRecordSerializerFactoryTest extends TestCase */ public function it_should_produce_a_default_RecordSerializer(): void { - $serializer = DefaultRecordSerializerFactory::get('http://localhost'); + $one = DefaultRecordSerializerFactory::get('http://localhost'); + $two = DefaultRecordSerializerFactory::get('http://localhost'); - $this->assertInstanceOf(RecordSerializer::class, $serializer); + $this->assertNotSame($one, $two); } } diff --git a/test/Objects/RecordSerializerTest.php b/test/Objects/RecordSerializerTest.php index 0f101c4..f9bb2f3 100644 --- a/test/Objects/RecordSerializerTest.php +++ b/test/Objects/RecordSerializerTest.php @@ -24,6 +24,10 @@ class RecordSerializerTest extends AbstractFunctionalTestCase */ private $recordSerializer; + /** + * @throws \ReflectionException + * @throws \AvroSchemaParseException + */ protected function setUp() { parent::setUp(); @@ -40,6 +44,8 @@ protected function tearDown() /** * @test + * + * @throws \FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException */ public function it_should_encode_a_record_with_schema_and_subject(): void { @@ -72,6 +78,8 @@ public function it_should_encode_a_record_with_schema_and_subject(): void * * @expectedException \FlixTech\AvroSerializer\Objects\Exceptions\AvroEncodingException * @expectedExceptionCode 501 + * + * @throws \FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException */ public function it_should_throw_encoding_exception_on_invalid_schema(): void { @@ -88,6 +96,8 @@ public function it_should_throw_encoding_exception_on_invalid_schema(): void * @test * * @expectedException \FlixTech\SchemaRegistryApi\Exception\SchemaNotFoundException + * + * @throws \FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException */ public function it_should_not_register_new_schemas_by_default(): void { @@ -106,6 +116,8 @@ public function it_should_not_register_new_schemas_by_default(): void /** * @test + * + * @throws \FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException */ public function it_should_register_new_schemas_when_configured(): void { @@ -145,6 +157,8 @@ public function it_should_register_new_schemas_when_configured(): void * @test * * @expectedException \FlixTech\SchemaRegistryApi\Exception\SubjectNotFoundException + * + * @throws \FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException */ public function it_should_fail_when_the_subject_is_not_found(): void { @@ -163,6 +177,8 @@ public function it_should_fail_when_the_subject_is_not_found(): void /** * @test + * + * @throws \FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException */ public function it_should_register_new_subject_when_configured(): void { @@ -202,6 +218,8 @@ public function it_should_register_new_subject_when_configured(): void * @test * * @expectedException \FlixTech\SchemaRegistryApi\Exception\SubjectNotFoundException + * + * @throws \FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException */ public function it_should_fail_when_the_subject_is_not_found_via_promise(): void { @@ -222,6 +240,8 @@ public function it_should_fail_when_the_subject_is_not_found_via_promise(): void * @test * * @expectedException \LogicException + * + * @throws \FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException */ public function it_should_fail_when_an_unexpected_exception_is_wrapped_in_a_promise(): void { @@ -240,6 +260,8 @@ public function it_should_fail_when_an_unexpected_exception_is_wrapped_in_a_prom /** * @test + * + * @throws \FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException */ public function it_should_decode_wire_protocol_messages_correctly(): void { @@ -269,6 +291,8 @@ public function it_should_decode_wire_protocol_messages_correctly(): void /** * @test + * + * @throws \FlixTech\SchemaRegistryApi\Exception\SchemaRegistryException */ public function it_should_decode_with_readers_schema(): void { diff --git a/test/Objects/SchemaResolvers/CallableResolverTest.php b/test/Objects/SchemaResolvers/CallableResolverTest.php index 9b24147..3660765 100644 --- a/test/Objects/SchemaResolvers/CallableResolverTest.php +++ b/test/Objects/SchemaResolvers/CallableResolverTest.php @@ -12,6 +12,9 @@ class CallableResolverTest extends AbstractFunctionalTestCase { /** * @test + * + * @throws \AvroSchemaParseException + * @throws \AvroSchemaParseException */ public function it_should_use_callable_for_resolving_value_schemas(): void { @@ -23,6 +26,8 @@ public function it_should_use_callable_for_resolving_value_schemas(): void /** * @test + * + * @throws \AvroSchemaParseException */ public function it_should_use_callable_for_resolving_key_schemas(): void { diff --git a/test/Objects/SchemaResolvers/ChainResolverTest.php b/test/Objects/SchemaResolvers/ChainResolverTest.php index c4131cb..7b6b779 100644 --- a/test/Objects/SchemaResolvers/ChainResolverTest.php +++ b/test/Objects/SchemaResolvers/ChainResolverTest.php @@ -23,6 +23,9 @@ class ChainResolverTest extends TestCase */ private $chain; + /** + * @throws \ReflectionException + */ protected function setUp() { $this->chainOne = $this->getMockForAbstractClass(SchemaResolverInterface::class); @@ -33,8 +36,10 @@ protected function setUp() /** * @test + * + * @throws \AvroSchemaParseException */ - public function it_will_exit_early_when_a_schema_has_been_resolved() + public function it_will_exit_early_when_a_schema_has_been_resolved(): void { $record = 'I am a record'; $avroSchema = \AvroSchema::parse('{"type": "string"}'); @@ -54,8 +59,10 @@ public function it_will_exit_early_when_a_schema_has_been_resolved() /** * @test + * + * @throws \AvroSchemaParseException */ - public function it_will_exit_early_when_a_key_schema_has_been_resolved() + public function it_will_exit_early_when_a_key_schema_has_been_resolved(): void { $record = 'I am a record'; $avroSchema = \AvroSchema::parse('{"type": "string"}'); @@ -75,8 +82,10 @@ public function it_will_exit_early_when_a_key_schema_has_been_resolved() /** * @test + * + * @throws \AvroSchemaParseException */ - public function it_will_call_all_resolvers() + public function it_will_call_all_resolvers(): void { $record = 'I am a record'; $avroSchema = \AvroSchema::parse('{"type": "string"}'); @@ -98,8 +107,10 @@ public function it_will_call_all_resolvers() /** * @test + * + * @throws \AvroSchemaParseException */ - public function it_will_call_all_resolvers_for_key_schemas() + public function it_will_call_all_resolvers_for_key_schemas(): void { $record = 'I am a record'; $avroSchema = \AvroSchema::parse('{"type": "string"}'); @@ -125,7 +136,7 @@ public function it_will_call_all_resolvers_for_key_schemas() * @expectedException \InvalidArgumentException * @expectedExceptionMessage No schema resolver in the chain is able to resolve the schema for the record */ - public function it_should_call_all_resolvers_and_throw_for_value_when_no_resolver_has_a_result() + public function it_should_call_all_resolvers_and_throw_for_value_when_no_resolver_has_a_result(): void { $record = 'I am a record'; @@ -145,7 +156,7 @@ public function it_should_call_all_resolvers_and_throw_for_value_when_no_resolve /** * @test */ - public function it_should_call_all_resolvers_and_return_null_when_no_key_resolver_has_a_result() + public function it_should_call_all_resolvers_and_return_null_when_no_key_resolver_has_a_result(): void { $record = 'I am a record'; diff --git a/test/Objects/SchemaResolvers/DefinitionInterfaceResolverTest.php b/test/Objects/SchemaResolvers/DefinitionInterfaceResolverTest.php index 09169b8..3eb17ad 100644 --- a/test/Objects/SchemaResolvers/DefinitionInterfaceResolverTest.php +++ b/test/Objects/SchemaResolvers/DefinitionInterfaceResolverTest.php @@ -10,6 +10,8 @@ class DefinitionInterfaceResolverTest extends TestCase { /** * @test + * + * @throws \AvroSchemaParseException */ public function it_should_allow_correct_interfaces(): void { diff --git a/test/Objects/SchemaResolvers/FileResolverTest.php b/test/Objects/SchemaResolvers/FileResolverTest.php index eb29681..93d400d 100644 --- a/test/Objects/SchemaResolvers/FileResolverTest.php +++ b/test/Objects/SchemaResolvers/FileResolverTest.php @@ -12,8 +12,10 @@ class FileResolverTest extends TestCase { /** * @test + * + * @throws \AvroSchemaParseException */ - public function it_should_find_value_and_key_schemas_when_defined() + public function it_should_find_value_and_key_schemas_when_defined(): void { $fileSchemaResolver = $this->getFileSchemaResolverInstance(); @@ -33,8 +35,10 @@ public function it_should_find_value_and_key_schemas_when_defined() * @test * * @expectedException \InvalidArgumentException + * + * @throws \AvroSchemaParseException */ - public function it_should_fail_for_non_existing_value_schema() + public function it_should_fail_for_non_existing_value_schema(): void { $fromSchemaFileResolver = $this->getFileSchemaResolverInstance(); @@ -46,12 +50,14 @@ public function it_should_fail_for_non_existing_value_schema() * @test * * @expectedException \InvalidArgumentException + * + * @throws \AvroSchemaParseException */ - public function it_should_fail_for_value_schema_for_invalid_inflector_result() + public function it_should_fail_for_value_schema_for_invalid_inflector_result(): void { $baseDir = __DIR__ . '/files'; - $inflector = function () { + $inflector = static function () { return ''; }; @@ -63,12 +69,14 @@ public function it_should_fail_for_value_schema_for_invalid_inflector_result() * @test * * @expectedException \InvalidArgumentException + * + * @throws \AvroSchemaParseException */ - public function it_should_fail_for_key_schema_for_invalid_inflector_result() + public function it_should_fail_for_key_schema_for_invalid_inflector_result(): void { $baseDir = __DIR__ . '/files'; - $inflector = function () { + $inflector = static function () { return ''; }; @@ -80,15 +88,18 @@ protected function getFileSchemaResolverInstance(): FileResolver { $baseDir = __DIR__ . '/files'; - $inflector = function ($record, bool $isKey) { + $inflector = static function ($record, bool $isKey) { $ext = $isKey ? '.key.json' : '.json'; - return inflectRecord($record) + /** @var \Widmogrod\Common\ValueOfInterface $inflectedString */ + $inflectedString = inflectRecord($record) ->map( - function ($inflectedObjectName) use ($ext) { + static function ($inflectedObjectName) use ($ext) { return $inflectedObjectName . $ext; } - )->extract(); + ); + + return $inflectedString->extract(); }; return new FileResolver($baseDir, $inflector); diff --git a/test/SerializeTest.php b/test/SerializeTest.php index b9278fe..1c58aba 100644 --- a/test/SerializeTest.php +++ b/test/SerializeTest.php @@ -21,8 +21,10 @@ class SerializeTest extends AbstractFunctionalTestCase { /** * @test + * + * @throws \AvroIOException */ - public function avroStringIo_should_produce_new_instances_of_AvroStringIO() + public function avroStringIo_should_produce_new_instances_of_AvroStringIO(): void { $avroStringIo = avroStringIo('test'); $instance = new \AvroStringIO('test'); @@ -33,8 +35,10 @@ public function avroStringIo_should_produce_new_instances_of_AvroStringIO() /** * @test + * + * @throws \AvroIOException */ - public function avroBinaryEncoder_should_produce_new_instances_of_AvroBinaryEncoder() + public function avroBinaryEncoder_should_produce_new_instances_of_AvroBinaryEncoder(): void { $avroStringIo = avroStringIo('test'); @@ -47,8 +51,10 @@ public function avroBinaryEncoder_should_produce_new_instances_of_AvroBinaryEnco /** * @test + * + * @throws \AvroIOException */ - public function avroBinaryDecoder_should_produce_new_instances_of_AvroBinaryDecoder() + public function avroBinaryDecoder_should_produce_new_instances_of_AvroBinaryDecoder(): void { $avroStringIo = avroStringIo('test'); @@ -61,8 +67,10 @@ public function avroBinaryDecoder_should_produce_new_instances_of_AvroBinaryDeco /** * @test + * + * @throws \AvroIOException */ - public function avroDatumWriter_should_create_curried_function() + public function avroDatumWriter_should_create_curried_function(): void { $writer = new AvroIODatumWriter(); $io = avroStringIo(''); @@ -75,8 +83,10 @@ public function avroDatumWriter_should_create_curried_function() /** * @test + * + * @throws \AvroIOException */ - public function writeDatum_should_correctly_produce_avro_encoded_binary_string_Right_Monad() + public function writeDatum_should_correctly_produce_avro_encoded_binary_string_Right_Monad(): void { $writer = new AvroIODatumWriter(); $io = avroStringIo(''); @@ -97,8 +107,10 @@ public function writeDatum_should_correctly_produce_avro_encoded_binary_string_R /** * @test + * + * @throws \AvroIOException */ - public function writeDatum_should_produce_Left_Monad_for_invalid_inputs() + public function writeDatum_should_produce_Left_Monad_for_invalid_inputs(): void { $writer = new AvroIODatumWriter(); $io = avroStringIo(''); @@ -111,8 +123,10 @@ public function writeDatum_should_produce_Left_Monad_for_invalid_inputs() /** * @test + * + * @throws \AvroIOException */ - public function avroDatumReader_should_return_curried_function() + public function avroDatumReader_should_return_curried_function(): void { $writer = new \AvroIODatumReader(); $io = avroStringIo(''); @@ -125,8 +139,10 @@ public function avroDatumReader_should_return_curried_function() /** * @test + * + * @throws \AvroIOException */ - public function readDatum_should_return_Right_Monad_for_valid_inputs() + public function readDatum_should_return_Right_Monad_for_valid_inputs(): void { $reader = new \AvroIODatumReader(); $io = avroStringIo(''); @@ -150,8 +166,10 @@ public function readDatum_should_return_Right_Monad_for_valid_inputs() /** * @test + * + * @throws \AvroIOException */ - public function readDatum_should_turn_Left_Monad_for_invalid_reader_and_writer_schemas() + public function readDatum_should_turn_Left_Monad_for_invalid_reader_and_writer_schemas(): void { $reader = new \AvroIODatumReader(); $io = avroStringIo('');