Skip to content

update composer dependencies for PHP 8.2+ compatibility #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![Actions Status](https://github.com/php-kafka/php-avro-schema-generator/workflows/CI/badge.svg)](https://github.com/php-kafka/php-avro-schema-generator/workflows/CI/badge.svg)
[![Maintainability](https://api.codeclimate.com/v1/badges/41aecf21566d7e9bfb69/maintainability)](https://codeclimate.com/github/php-kafka/php-avro-schema-generator/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/41aecf21566d7e9bfb69/test_coverage)](https://codeclimate.com/github/php-kafka/php-avro-schema-generator/test_coverage)
![Supported PHP versions: 7.4 .. 8.x](https://img.shields.io/badge/php-7.4%20..%208.x-blue.svg)
![Supported PHP versions: ^8.2](https://img.shields.io/badge/php-%5E8.2-blue.svg)
[![Latest Stable Version](https://poser.pugx.org/php-kafka/php-avro-schema-generator/v/stable)](https://packagist.org/packages/php-kafka/php-avro-schema-generator)

## Installation
Expand Down Expand Up @@ -53,7 +53,7 @@ How to enable optimizer:

**Console example**
```bash
./vendor/bin/avro-cli --optimizeFullNames --optimizeFieldOrder --optimizePrimitiveSchemas avro:subschema:merge ./example/schemaTemplates ./example/schema
./bin/avro-cli --optimizeFullNames --optimizeFieldOrder --optimizePrimitiveSchemas avro:subschema:merge ./example/schemaTemplates ./example/schema
```
**PHP Example**
```php
Expand Down Expand Up @@ -87,7 +87,7 @@ After you have reviewed and adjusted your templates you will need to merge them

**Console example**
```bash
./vendor/bin/avro-cli avro:schema:generate ./example/classes ./example/schemaTemplates
./bin/avro-cli avro:schema:generate ./example/classes ./example/schemaTemplates
```

**PHP Example**
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
"license": "MIT",
"require": {
"ext-json": "*",
"flix-tech/avro-php": "^3.0|^4.0|^5.0",
"symfony/console": "^4.3|^5.1|^6.0",
"nikic/php-parser": "^4.13",
"flix-tech/avro-php": "^5.1",
"symfony/console": "^7.2",
"nikic/php-parser": "^5.4",
"pimple/pimple": "^3.5"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.19|^3.15",
"infection/infection": "^0.25|^0.27",
"composer/xdebug-handler": "^2.0|^3.0",
"friendsofphp/php-cs-fixer": "^3.70",
"infection/infection": "^0.29",
"composer/xdebug-handler": "^3.0",
"phpstan/phpstan": "^1.2",
"phpunit/phpunit": "^9.3",
"rregeer/phpunit-coverage-check": "^0.3",
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ services:
HOST_USER_ID: ${USER_ID}
volumes:
- ./:/var/www/html
- type: tmpfs
target: /tmp/test
tmpfs:
size: 256M
23 changes: 17 additions & 6 deletions docker/dev/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
FROM php:7.4-cli-alpine3.15
FROM php:8.2-cli-alpine3.19

ARG HOST_USER_ID
ARG HOST_USER

# Create sanitized username as an ENV variable so it persists throughout the build
ENV CLEAN_USER=default
RUN if [ ! -z "$HOST_USER" ]; then \
export CLEAN_USER=$(echo "$HOST_USER" | sed 's/[^a-zA-Z0-9._-]/_/g') && \
echo "export CLEAN_USER=$CLEAN_USER" >> /etc/profile; \
fi

COPY php/files/bin/ /usr/local/bin/

# SYS: Install required packages
RUN apk --no-cache upgrade && \
apk --no-cache add bash git sudo make autoconf gcc g++

RUN if [ ! -z "$HOST_USER_ID" ]; then \
adduser -u $HOST_USER_ID -D -H $HOST_USER && \
echo "ALL ALL=NOPASSWD: ALL" >> /etc/sudoers; \
fi
adduser -u $HOST_USER_ID -D -H $CLEAN_USER && \
echo "ALL ALL=NOPASSWD: ALL" >> /etc/sudoers; \
fi

# Create a directory with proper permissions for test files
RUN mkdir -p /tmp/test && \
chmod 777 /tmp/test && \
chown $CLEAN_USER:$CLEAN_USER /tmp/test

# PHP: Install php extensions
RUN mkdir /phpIni && \
Expand All @@ -23,9 +35,8 @@ RUN mkdir /phpIni && \
# COMPOSER: install binary
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer

USER $HOST_USER
USER $CLEAN_USER

WORKDIR /var/www/html

CMD tail -f /dev/null

3 changes: 2 additions & 1 deletion example/generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
use PhpKafka\PhpAvroSchemaGenerator\Parser\ClassPropertyParser;
use PhpKafka\PhpAvroSchemaGenerator\Generator\SchemaGenerator;
use PhpParser\ParserFactory;
use PhpParser\PhpVersion;

$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
$parser = (new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2));
$classPropertyParser = new ClassPropertyParser(new DocCommentParser());
$classParser = new ClassParser($parser, $classPropertyParser);

Expand Down
2 changes: 1 addition & 1 deletion src/Parser/ClassParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function getNamespace(): ?string
foreach ($this->statements as $statement) {
if ($statement instanceof Namespace_) {
if ($statement->name instanceof Name) {
return implode('\\', $statement->name->parts);
return $statement->name->toString();
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/ServiceProvider/ParserServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PhpKafka\PhpAvroSchemaGenerator\Parser\DocCommentParserInterface;
use PhpParser\ParserFactory;
use PhpParser\Parser;
use PhpParser\PhpVersion;
use Pimple\Container;
use Pimple\ServiceProviderInterface;

Expand All @@ -24,7 +25,7 @@ public function register(Container $container): void
};

$container[Parser::class] = static function (Container $container): Parser {
return $container[ParserFactory::class]->create(ParserFactory::PREFER_PHP7);
return $container[ParserFactory::class]->createForVersion(PhpVersion::fromComponents(8, 2));
};

$container[DocCommentParserInterface::class] = static function (): DocCommentParserInterface {
Expand Down
23 changes: 12 additions & 11 deletions tests/Integration/Parser/ClassParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PhpKafka\PhpAvroSchemaGenerator\Parser\DocCommentParser;
use PhpKafka\PhpAvroSchemaGenerator\PhpClass\PhpClassPropertyInterface;
use PhpParser\ParserFactory;
use PhpParser\PhpVersion;
use PHPUnit\Framework\TestCase;

/**
Expand All @@ -20,7 +21,7 @@ public function testGetClassName(): void
{
$filePath = __DIR__ . '/../../../example/classes/SomeTestClass.php';
$propertyParser = new ClassPropertyParser(new DocCommentParser());
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
$parser->setCode((string) file_get_contents($filePath));
self::assertEquals('SomeTestClass', $parser->getClassName());
self::assertEquals('SomeTestClass', $parser->getClassName());
Expand All @@ -30,7 +31,7 @@ public function testGetClassNameForInterface(): void
{
$filePath = __DIR__ . '/../../../example/classes/SomeTestInterface.php';
$propertyParser = new ClassPropertyParser(new DocCommentParser());
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
$parser->setCode((string) file_get_contents($filePath));
self::assertNull($parser->getClassName());
}
Expand All @@ -39,7 +40,7 @@ public function testGetNamespace(): void
{
$filePath = __DIR__ . '/../../../example/classes/SomeTestClass.php';
$propertyParser = new ClassPropertyParser(new DocCommentParser());
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
$parser->setCode((string) file_get_contents($filePath));
self::assertEquals('PhpKafka\\PhpAvroSchemaGenerator\\Example', $parser->getNamespace());
self::assertEquals('PhpKafka\\PhpAvroSchemaGenerator\\Example', $parser->getNamespace());
Expand All @@ -49,7 +50,7 @@ public function testGetProperties(): void
{
$filePath = __DIR__ . '/../../../example/classes/SomeTestClass.php';
$propertyParser = new ClassPropertyParser(new DocCommentParser());
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
$parser->setCode((string) file_get_contents($filePath));
$properties = $parser->getProperties();
self::assertCount(16, $properties);
Expand All @@ -62,7 +63,7 @@ public function testGetProperties(): void
public function testClassAndNamespaceAreNullWithNoCode(): void
{
$propertyParser = new ClassPropertyParser(new DocCommentParser());
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
$refObject = new \ReflectionObject($parser);
$refProperty = $refObject->getProperty('statements');
$refProperty->setAccessible(true);
Expand All @@ -76,7 +77,7 @@ public function testClassAndNamespaceAreNullWithNoCode(): void
public function testClassWithNoParent(): void
{
$propertyParser = new ClassPropertyParser(new DocCommentParser());
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
$parser->setCode('<?php class foo {}');
self::assertNull($parser->getNamespace());
self::assertNull($parser->getParentClassName());
Expand All @@ -87,7 +88,7 @@ public function testClassWithNoParent(): void
public function testClassWithNullableType(): void
{
$propertyParser = new ClassPropertyParser(new DocCommentParser());
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
$parser->setCode('
<?php
class foo {
Expand All @@ -102,7 +103,7 @@ class foo {
public function testClassWithUnionType(): void
{
$propertyParser = new ClassPropertyParser(new DocCommentParser());
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
$parser->setCode('
<?php
class foo {
Expand All @@ -117,7 +118,7 @@ class foo {
public function testClassWithDocUnionType(): void
{
$propertyParser = new ClassPropertyParser(new DocCommentParser());
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
$parser->setCode('
<?php
class foo {
Expand All @@ -135,7 +136,7 @@ class foo {
public function testClassWithAnnotations(): void
{
$propertyParser = new ClassPropertyParser(new DocCommentParser());
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
$parser->setCode('
<?php
class foo {
Expand All @@ -159,7 +160,7 @@ class foo {
public function testClassWithNoParentFile(): void
{
$propertyParser = new ClassPropertyParser(new DocCommentParser());
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
$parser->setCode('<?php class foo extends \RuntimeException {private $x;}');
$properties = $parser->getProperties();
self::assertEquals(1, count($properties));
Expand Down
10 changes: 5 additions & 5 deletions tests/Integration/Parser/ClassPropertyParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use PhpKafka\PhpAvroSchemaGenerator\Parser\ClassParser;
use PhpKafka\PhpAvroSchemaGenerator\Parser\ClassPropertyParser;
use PhpKafka\PhpAvroSchemaGenerator\Parser\DocCommentParser;
use PhpKafka\PhpAvroSchemaGenerator\PhpClass\PhpClassPropertyInterface;
use PhpParser\ParserFactory;
use PhpParser\PhpVersion;
use PHPUnit\Framework\TestCase;

/**
Expand All @@ -19,7 +19,7 @@ class ClassPropertyParserTest extends TestCase
public function testNullDefaultProperty(): void
{
$propertyParser = new ClassPropertyParser(new DocCommentParser());
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
$parser->setCode('
<?php
class foo {
Expand All @@ -37,7 +37,7 @@ class foo {
public function testIntDefaultProperty(): void
{
$propertyParser = new ClassPropertyParser(new DocCommentParser());
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
$parser->setCode('
<?php
class foo {
Expand All @@ -55,7 +55,7 @@ class foo {
public function testFloatDefaultProperty(): void
{
$propertyParser = new ClassPropertyParser(new DocCommentParser());
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
$parser->setCode('
<?php
class foo {
Expand All @@ -73,7 +73,7 @@ class foo {
public function testEmptyStringDefaultProperty(): void
{
$propertyParser = new ClassPropertyParser(new DocCommentParser());
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
$parser->setCode('
<?php
class foo {
Expand Down
18 changes: 10 additions & 8 deletions tests/Integration/Registry/ClassRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use PhpKafka\PhpAvroSchemaGenerator\Registry\ClassRegistry;
use PhpKafka\PhpAvroSchemaGenerator\Registry\ClassRegistryInterface;
use PhpParser\ParserFactory;
use PhpParser\PhpVersion;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use SplFileInfo;
Expand All @@ -25,7 +26,7 @@ class ClassRegistryTest extends TestCase
public function testClassDirectory(): void
{
$propertyParser = new ClassPropertyParser(new DocCommentParser());
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
$converter = new PhpClassConverter($parser);
$registry = new ClassRegistry($converter);
$result = $registry->addClassDirectory('/tmp');
Expand All @@ -39,7 +40,7 @@ public function testLoad(): void
$classDir = __DIR__ . '/../../../example/classes';

$propertyParser = new ClassPropertyParser(new DocCommentParser());
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
$converter = new PhpClassConverter($parser);
$registry = (new ClassRegistry($converter))->addClassDirectory($classDir)->load();

Expand All @@ -58,7 +59,7 @@ public function testRegisterSchemaFileThatDoesntExist(): void
{
$fileInfo = new SplFileInfo('somenonexistingfile');
$propertyParser = new ClassPropertyParser(new DocCommentParser());
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
$converter = new PhpClassConverter($parser);
$registry = new ClassRegistry($converter);

Expand All @@ -73,13 +74,14 @@ public function testRegisterSchemaFileThatDoesntExist(): void

public function testRegisterSchemaFileThatIsNotReadable(): void
{
touch('testfile');
chmod('testfile', 222);
$filePath = '/tmp/test/testfile';
touch($filePath);
chmod($filePath, 222);

$fileInfo = new SplFileInfo('testfile');
$fileInfo = new SplFileInfo($filePath);

$propertyParser = new ClassPropertyParser(new DocCommentParser());
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
$parser = new ClassParser((new ParserFactory())->createForVersion(PhpVersion::fromComponents(8,2)), $propertyParser);
$converter = new PhpClassConverter($parser);
$registry = new ClassRegistry($converter);

Expand All @@ -94,7 +96,7 @@ public function testRegisterSchemaFileThatIsNotReadable(): void
try {
$method->invokeArgs($registry, [$fileInfo]);
} finally {
unlink('testfile');
@unlink($filePath);
}
}
}
Loading
Loading