Skip to content

Commit 6a46c96

Browse files
committed
chore: update composer dependencies for PHP 8.2+ compatibility
1 parent 6051097 commit 6a46c96

File tree

12 files changed

+89
-55
lines changed

12 files changed

+89
-55
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[![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)
33
[![Maintainability](https://api.codeclimate.com/v1/badges/41aecf21566d7e9bfb69/maintainability)](https://codeclimate.com/github/php-kafka/php-avro-schema-generator/maintainability)
44
[![Test Coverage](https://api.codeclimate.com/v1/badges/41aecf21566d7e9bfb69/test_coverage)](https://codeclimate.com/github/php-kafka/php-avro-schema-generator/test_coverage)
5-
![Supported PHP versions: 7.4 .. 8.x](https://img.shields.io/badge/php-7.4%20..%208.x-blue.svg)
5+
![Supported PHP versions: ^8.2](https://img.shields.io/badge/php-%5E8.2-blue.svg)
66
[![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)
77

88
## Installation
@@ -53,7 +53,7 @@ How to enable optimizer:
5353

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

8888
**Console example**
8989
```bash
90-
./vendor/bin/avro-cli avro:schema:generate ./example/classes ./example/schemaTemplates
90+
./bin/avro-cli avro:schema:generate ./example/classes ./example/schemaTemplates
9191
```
9292

9393
**PHP Example**

composer.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@
88
],
99
"license": "MIT",
1010
"require": {
11+
"php": ">=8.2",
1112
"ext-json": "*",
12-
"flix-tech/avro-php": "^3.0|^4.0|^5.0",
13-
"symfony/console": "^4.3|^5.1|^6.0",
14-
"nikic/php-parser": "^4.13",
13+
"flix-tech/avro-php": "^5.1",
14+
"symfony/console": "^7.2",
15+
"nikic/php-parser": "^5.4",
1516
"pimple/pimple": "^3.5"
1617
},
1718
"require-dev": {
18-
"friendsofphp/php-cs-fixer": "^2.19|^3.15",
19-
"infection/infection": "^0.25|^0.27",
20-
"composer/xdebug-handler": "^2.0|^3.0",
19+
"friendsofphp/php-cs-fixer": "^3.70",
20+
"infection/infection": "^0.29",
21+
"composer/xdebug-handler": "^3.0",
2122
"phpstan/phpstan": "^1.2",
2223
"phpunit/phpunit": "^9.3",
2324
"rregeer/phpunit-coverage-check": "^0.3",

docker-compose.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ services:
99
HOST_USER_ID: ${USER_ID}
1010
volumes:
1111
- ./:/var/www/html
12+
- type: tmpfs
13+
target: /tmp/test
14+
tmpfs:
15+
size: 256M

docker/dev/php/Dockerfile

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
1-
FROM php:7.4-cli-alpine3.15
1+
FROM php:8.2-cli-alpine3.19
22

33
ARG HOST_USER_ID
44
ARG HOST_USER
55

6+
# Create sanitized username as an ENV variable so it persists throughout the build
7+
ENV CLEAN_USER=default
8+
RUN if [ ! -z "$HOST_USER" ]; then \
9+
export CLEAN_USER=$(echo "$HOST_USER" | sed 's/[^a-zA-Z0-9._-]/_/g') && \
10+
echo "export CLEAN_USER=$CLEAN_USER" >> /etc/profile; \
11+
fi
12+
613
COPY php/files/bin/ /usr/local/bin/
714

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

1219
RUN if [ ! -z "$HOST_USER_ID" ]; then \
13-
adduser -u $HOST_USER_ID -D -H $HOST_USER && \
14-
echo "ALL ALL=NOPASSWD: ALL" >> /etc/sudoers; \
15-
fi
20+
adduser -u $HOST_USER_ID -D -H $CLEAN_USER && \
21+
echo "ALL ALL=NOPASSWD: ALL" >> /etc/sudoers; \
22+
fi
23+
24+
# Create a directory with proper permissions for test files
25+
RUN mkdir -p /tmp/test && \
26+
chmod 777 /tmp/test && \
27+
chown $CLEAN_USER:$CLEAN_USER /tmp/test
1628

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

26-
USER $HOST_USER
38+
USER $CLEAN_USER
2739

2840
WORKDIR /var/www/html
2941

3042
CMD tail -f /dev/null
31-

example/generate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use PhpKafka\PhpAvroSchemaGenerator\Generator\SchemaGenerator;
1313
use PhpParser\ParserFactory;
1414

15-
$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
15+
$parser = (new ParserFactory())->createForNewestSupportedVersion();
1616
$classPropertyParser = new ClassPropertyParser(new DocCommentParser());
1717
$classParser = new ClassParser($parser, $classPropertyParser);
1818

src/Parser/ClassParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function getNamespace(): ?string
142142
foreach ($this->statements as $statement) {
143143
if ($statement instanceof Namespace_) {
144144
if ($statement->name instanceof Name) {
145-
return implode('\\', $statement->name->parts);
145+
return $statement->name->toString();
146146
}
147147
}
148148
}

src/ServiceProvider/ParserServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function register(Container $container): void
2424
};
2525

2626
$container[Parser::class] = static function (Container $container): Parser {
27-
return $container[ParserFactory::class]->create(ParserFactory::PREFER_PHP7);
27+
return $container[ParserFactory::class]->createForNewestSupportedVersion();
2828
};
2929

3030
$container[DocCommentParserInterface::class] = static function (): DocCommentParserInterface {

tests/Integration/Parser/ClassParserTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function testGetClassName(): void
2020
{
2121
$filePath = __DIR__ . '/../../../example/classes/SomeTestClass.php';
2222
$propertyParser = new ClassPropertyParser(new DocCommentParser());
23-
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
23+
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
2424
$parser->setCode((string) file_get_contents($filePath));
2525
self::assertEquals('SomeTestClass', $parser->getClassName());
2626
self::assertEquals('SomeTestClass', $parser->getClassName());
@@ -30,7 +30,7 @@ public function testGetClassNameForInterface(): void
3030
{
3131
$filePath = __DIR__ . '/../../../example/classes/SomeTestInterface.php';
3232
$propertyParser = new ClassPropertyParser(new DocCommentParser());
33-
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
33+
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
3434
$parser->setCode((string) file_get_contents($filePath));
3535
self::assertNull($parser->getClassName());
3636
}
@@ -39,7 +39,7 @@ public function testGetNamespace(): void
3939
{
4040
$filePath = __DIR__ . '/../../../example/classes/SomeTestClass.php';
4141
$propertyParser = new ClassPropertyParser(new DocCommentParser());
42-
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
42+
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
4343
$parser->setCode((string) file_get_contents($filePath));
4444
self::assertEquals('PhpKafka\\PhpAvroSchemaGenerator\\Example', $parser->getNamespace());
4545
self::assertEquals('PhpKafka\\PhpAvroSchemaGenerator\\Example', $parser->getNamespace());
@@ -49,7 +49,7 @@ public function testGetProperties(): void
4949
{
5050
$filePath = __DIR__ . '/../../../example/classes/SomeTestClass.php';
5151
$propertyParser = new ClassPropertyParser(new DocCommentParser());
52-
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
52+
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
5353
$parser->setCode((string) file_get_contents($filePath));
5454
$properties = $parser->getProperties();
5555
self::assertCount(16, $properties);
@@ -62,7 +62,7 @@ public function testGetProperties(): void
6262
public function testClassAndNamespaceAreNullWithNoCode(): void
6363
{
6464
$propertyParser = new ClassPropertyParser(new DocCommentParser());
65-
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
65+
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
6666
$refObject = new \ReflectionObject($parser);
6767
$refProperty = $refObject->getProperty('statements');
6868
$refProperty->setAccessible(true);
@@ -76,7 +76,7 @@ public function testClassAndNamespaceAreNullWithNoCode(): void
7676
public function testClassWithNoParent(): void
7777
{
7878
$propertyParser = new ClassPropertyParser(new DocCommentParser());
79-
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
79+
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
8080
$parser->setCode('<?php class foo {}');
8181
self::assertNull($parser->getNamespace());
8282
self::assertNull($parser->getParentClassName());
@@ -87,7 +87,7 @@ public function testClassWithNoParent(): void
8787
public function testClassWithNullableType(): void
8888
{
8989
$propertyParser = new ClassPropertyParser(new DocCommentParser());
90-
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
90+
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
9191
$parser->setCode('
9292
<?php
9393
class foo {
@@ -102,7 +102,7 @@ class foo {
102102
public function testClassWithUnionType(): void
103103
{
104104
$propertyParser = new ClassPropertyParser(new DocCommentParser());
105-
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
105+
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
106106
$parser->setCode('
107107
<?php
108108
class foo {
@@ -117,7 +117,7 @@ class foo {
117117
public function testClassWithDocUnionType(): void
118118
{
119119
$propertyParser = new ClassPropertyParser(new DocCommentParser());
120-
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
120+
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
121121
$parser->setCode('
122122
<?php
123123
class foo {
@@ -135,7 +135,7 @@ class foo {
135135
public function testClassWithAnnotations(): void
136136
{
137137
$propertyParser = new ClassPropertyParser(new DocCommentParser());
138-
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
138+
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
139139
$parser->setCode('
140140
<?php
141141
class foo {
@@ -159,7 +159,7 @@ class foo {
159159
public function testClassWithNoParentFile(): void
160160
{
161161
$propertyParser = new ClassPropertyParser(new DocCommentParser());
162-
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
162+
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
163163
$parser->setCode('<?php class foo extends \RuntimeException {private $x;}');
164164
$properties = $parser->getProperties();
165165
self::assertEquals(1, count($properties));

tests/Integration/Parser/ClassPropertyParserTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use PhpKafka\PhpAvroSchemaGenerator\Parser\ClassParser;
88
use PhpKafka\PhpAvroSchemaGenerator\Parser\ClassPropertyParser;
99
use PhpKafka\PhpAvroSchemaGenerator\Parser\DocCommentParser;
10-
use PhpKafka\PhpAvroSchemaGenerator\PhpClass\PhpClassPropertyInterface;
1110
use PhpParser\ParserFactory;
1211
use PHPUnit\Framework\TestCase;
1312

@@ -19,7 +18,7 @@ class ClassPropertyParserTest extends TestCase
1918
public function testNullDefaultProperty(): void
2019
{
2120
$propertyParser = new ClassPropertyParser(new DocCommentParser());
22-
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
21+
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
2322
$parser->setCode('
2423
<?php
2524
class foo {
@@ -37,7 +36,7 @@ class foo {
3736
public function testIntDefaultProperty(): void
3837
{
3938
$propertyParser = new ClassPropertyParser(new DocCommentParser());
40-
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
39+
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
4140
$parser->setCode('
4241
<?php
4342
class foo {
@@ -55,7 +54,7 @@ class foo {
5554
public function testFloatDefaultProperty(): void
5655
{
5756
$propertyParser = new ClassPropertyParser(new DocCommentParser());
58-
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
57+
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
5958
$parser->setCode('
6059
<?php
6160
class foo {
@@ -73,7 +72,7 @@ class foo {
7372
public function testEmptyStringDefaultProperty(): void
7473
{
7574
$propertyParser = new ClassPropertyParser(new DocCommentParser());
76-
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
75+
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
7776
$parser->setCode('
7877
<?php
7978
class foo {

tests/Integration/Registry/ClassRegistryTest.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ClassRegistryTest extends TestCase
2525
public function testClassDirectory(): void
2626
{
2727
$propertyParser = new ClassPropertyParser(new DocCommentParser());
28-
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
28+
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
2929
$converter = new PhpClassConverter($parser);
3030
$registry = new ClassRegistry($converter);
3131
$result = $registry->addClassDirectory('/tmp');
@@ -39,7 +39,7 @@ public function testLoad(): void
3939
$classDir = __DIR__ . '/../../../example/classes';
4040

4141
$propertyParser = new ClassPropertyParser(new DocCommentParser());
42-
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
42+
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
4343
$converter = new PhpClassConverter($parser);
4444
$registry = (new ClassRegistry($converter))->addClassDirectory($classDir)->load();
4545

@@ -58,7 +58,7 @@ public function testRegisterSchemaFileThatDoesntExist(): void
5858
{
5959
$fileInfo = new SplFileInfo('somenonexistingfile');
6060
$propertyParser = new ClassPropertyParser(new DocCommentParser());
61-
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
61+
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
6262
$converter = new PhpClassConverter($parser);
6363
$registry = new ClassRegistry($converter);
6464

@@ -73,13 +73,14 @@ public function testRegisterSchemaFileThatDoesntExist(): void
7373

7474
public function testRegisterSchemaFileThatIsNotReadable(): void
7575
{
76-
touch('testfile');
77-
chmod('testfile', 222);
76+
$filePath = '/tmp/test/testfile';
77+
touch($filePath);
78+
chmod($filePath, 222);
7879

79-
$fileInfo = new SplFileInfo('testfile');
80+
$fileInfo = new SplFileInfo($filePath);
8081

8182
$propertyParser = new ClassPropertyParser(new DocCommentParser());
82-
$parser = new ClassParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7), $propertyParser);
83+
$parser = new ClassParser((new ParserFactory())->createForNewestSupportedVersion(), $propertyParser);
8384
$converter = new PhpClassConverter($parser);
8485
$registry = new ClassRegistry($converter);
8586

@@ -94,7 +95,7 @@ public function testRegisterSchemaFileThatIsNotReadable(): void
9495
try {
9596
$method->invokeArgs($registry, [$fileInfo]);
9697
} finally {
97-
unlink('testfile');
98+
@unlink($filePath);
9899
}
99100
}
100101
}

tests/Integration/Registry/SchemaRegistryTest.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ public function testRegisterSchemaFileThatDoesntExist(): void
105105

106106
public function testRegisterSchemaFileThatIsNotReadable(): void
107107
{
108-
touch('testfile');
109-
chmod('testfile', 222);
110-
111-
$fileInfo = new SplFileInfo('testfile');
108+
$filePath = '/tmp/test/testfile';
109+
touch($filePath);
110+
chmod($filePath, 222);
112111

112+
$fileInfo = new SplFileInfo($filePath);
113113
$registry = new SchemaRegistry();
114114

115115
self::expectException(SchemaRegistryException::class);
@@ -123,15 +123,16 @@ public function testRegisterSchemaFileThatIsNotReadable(): void
123123
try {
124124
$method->invokeArgs($registry, [$fileInfo]);
125125
} finally {
126-
unlink('testfile');
126+
@unlink($filePath);
127127
}
128128
}
129129

130130
public function testRegisterSchemaWithInvalidContent(): void
131131
{
132-
touch('testfile');
132+
$filePath = '/tmp/test/testfile';
133+
touch($filePath);
133134

134-
$fileInfo = new SplFileInfo('testfile');
135+
$fileInfo = new SplFileInfo($filePath);
135136

136137
$registry = new SchemaRegistry();
137138

@@ -146,7 +147,7 @@ public function testRegisterSchemaWithInvalidContent(): void
146147
try {
147148
$method->invokeArgs($registry, [$fileInfo]);
148149
} finally {
149-
unlink('testfile');
150+
@unlink($filePath);
150151
}
151152
}
152153
}

0 commit comments

Comments
 (0)