Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Commit fbaa3bc

Browse files
authored
PHP 8.2 compatibility (#157)
PR in fork: SOHELAHMED7#22 - [x] also add PHP 8.3 in test pipeline
2 parents 6d027c6 + 7571169 commit fbaa3bc

File tree

10 files changed

+57
-24
lines changed

10 files changed

+57
-24
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
strategy:
2121
fail-fast: false
2222
matrix:
23-
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1'] # TODO add '8.2' https://github.com/cebe/yii2-openapi/issues/142
23+
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
2424

2525
# TODO use cache
2626
steps:

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ cd yii2-openapi
1010
make clean_all
1111
make up
1212
make installdocker
13+
sudo chmod -R 777 tests/tmp/ # https://github.com/cebe/yii2-openapi/issues/156
1314
make migrate
1415

1516
# to check everything is setup up correctly ensure all tests passes
1617
make cli
18+
# in Docker container
1719
./vendor/bin/phpunit
1820

1921
# create new branch from master and Happy contributing!

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
"require": {
2121
"php": ">=7.2.0",
2222
"cebe/php-openapi": "^1.5.0",
23-
"yiisoft/yii2": "~2.0.15",
23+
"yiisoft/yii2": "~2.0.48",
2424
"yiisoft/yii2-gii": "~2.0.0 | ~2.1.0 | ~2.2.0| ~2.3.0",
25-
"laminas/laminas-code": "^3.4 | ^4.0",
25+
"laminas/laminas-code": ">=3.4 <=4.13",
2626
"insolita/yii2-fractal": "^1.0.0",
2727
"fakerphp/faker": "^1.9",
2828
"sam-it/yii2-mariadb": "^2.0"

src/lib/ColumnToCode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ public static function wrapQuotes(string $str, string $quotes = "'", bool $escap
299299

300300
public static function enumToString(array $enum):string
301301
{
302-
$items = implode(", ", array_map('self::wrapQuotes', $enum));
302+
$items = implode(", ", array_map(self::class.'::wrapQuotes', $enum));
303303
return self::escapeQuotes($items);
304304
}
305305

src/lib/FakerStubResolver.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,13 @@ public function resolve():?string
5353

5454
// column name ends with `_id`
5555
if (substr($this->attribute->columnName, -strlen('_id'))==='_id') {
56-
return '$faker->randomElement(\\'.$this->config->modelNamespace
57-
. ($this->config->modelNamespace ? '\\' : '')
56+
$config = $this->config;
57+
if (!$config) {
58+
$config = new Config;
59+
}
60+
$mn = $config->modelNamespace;
61+
return '$faker->randomElement(\\'.$mn
62+
. ($mn ? '\\' : '')
5863
. ucfirst($this->attribute->reference).'::find()->select("id")->column())';
5964
}
6065

tests/docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ RUN apt-get update && \
3535
apt-get clean && \
3636
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
3737
# https://xdebug.org/docs/compat \
38-
&& if [ "$BUILD_PHP_VERSION" = "8.2" ] ; then pecl install xdebug ; else pecl install xdebug-3.1.5 ; fi \
38+
&& if [ "$BUILD_PHP_VERSION" = "8.2" ] || [ "$BUILD_PHP_VERSION" = "8.3" ] ; then pecl install xdebug ; else pecl install xdebug-3.1.5 ; fi \
3939
&& docker-php-ext-enable xdebug \
4040
&& docker-php-ext-install \
4141
zip \

tests/fixtures/blog.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@
7373
->asReference('Category')
7474
->setRequired()
7575
->setDescription('Category of posts')
76-
->setFakerStub('$faker->randomElement(\Category::find()->select("id")->column())'),
76+
->setFakerStub('$faker->randomElement(\app\models\Category::find()->select("id")->column())'),
7777
'created_at' => (new Attribute('created_at', ['phpType' => 'string', 'dbType' => 'date']))
7878
->setFakerStub('$faker->dateTimeThisCentury->format(\'Y-m-d\')'),
7979
'created_by' => (new Attribute('created_by', ['phpType' => 'int', 'dbType' => 'integer']))
8080
->asReference('User')
8181
->setDescription('The User')
82-
->setFakerStub('$faker->randomElement(\User::find()->select("id")->column())'),
82+
->setFakerStub('$faker->randomElement(\app\models\User::find()->select("id")->column())'),
8383
],
8484
'relations' => [
8585
'category' => new AttributeRelation('category',
@@ -110,12 +110,12 @@
110110
->setSize(128)
111111
->asReference('Post')
112112
->setDescription('A blog post (uid used as pk for test purposes)')
113-
->setFakerStub('$faker->randomElement(\Post::find()->select("id")->column())'),
113+
->setFakerStub('$faker->randomElement(\app\models\Post::find()->select("id")->column())'),
114114
'author' => (new Attribute('author', ['phpType' => 'int', 'dbType' => 'integer']))
115115
->setRequired()
116116
->asReference('User')
117117
->setDescription('The User')
118-
->setFakerStub('$faker->randomElement(\User::find()->select("id")->column())'),
118+
->setFakerStub('$faker->randomElement(\app\models\User::find()->select("id")->column())'),
119119
'message' => (new Attribute('message', ['phpType' => 'array', 'dbType' => 'json', 'xDbType' => 'json']))
120120
->setRequired()->setDefault([])->setFakerStub('["a" => "b"]'),
121121
'meta_data' => (new Attribute('meta_data', ['phpType' => 'array', 'dbType' => 'json', 'xDbType' => 'json']))

tests/unit/MultiDbFreshMigrationTest.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,11 @@ public function testAfterKeyword()
185185
$dbSchema, 'tableName', $columnSchema, false, false
186186
);
187187

188-
$this->assertStringContainsString('AFTER username', $column->getCode());
189-
$this->assertStringNotContainsString('AFTER username', $columnWithoutPreviousCol->getCode());
188+
// https://github.com/cebe/yii2-openapi/pull/141/files#diff-d2ab9925cad7eac58e0ff4cc0d251a937ecf49e4b6bf57f8b95aab76648a9d34R33
189+
$this->assertSame(strpos($column->getCode(), 'AFTER username'), 28);
190+
// $this->assertStringContainsString('AFTER username', $column->getCode());
191+
// $this->assertStringNotContainsString('AFTER username', $columnWithoutPreviousCol->getCode());
192+
$this->assertFalse(strpos($columnWithoutPreviousCol->getCode(), 'AFTER username'));
190193

191194
// test `after` for fluent part in function call `after()`
192195
unset($column, $columnWithoutPreviousCol);
@@ -198,7 +201,12 @@ public function testAfterKeyword()
198201
$dbSchema, 'tableName', $columnSchema, true, false
199202
);
200203

201-
$this->assertStringContainsString("->after('username')", $column->getCode());
202-
$this->assertStringNotContainsString("->after('username')", $columnWithoutPreviousCol->getCode());
204+
// https://github.com/cebe/yii2-openapi/pull/141/files#diff-d2ab9925cad7eac58e0ff4cc0d251a937ecf49e4b6bf57f8b95aab76648a9d34R33
205+
// $this->assertStringContainsString("->after('username')", $column->getCode());
206+
$this->assertSame(strpos($column->getCode(), "->after('username')"), 41);
207+
208+
// https://github.com/cebe/yii2-openapi/pull/141/files#diff-d2ab9925cad7eac58e0ff4cc0d251a937ecf49e4b6bf57f8b95aab76648a9d34R33
209+
// $this->assertStringNotContainsString("->after('username')", $columnWithoutPreviousCol->getCode());
210+
$this->assertFalse(strpos($columnWithoutPreviousCol->getCode(), "->after('username')"));
203211
}
204212
}

tests/unit/SchemaToDatabaseTest.php

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,35 @@ public function testFindJunctionSchemas()
2222
//VarDumper::dump($result->indexByJunctionRef());
2323
//VarDumper::dump($result->indexByJunctionSchema());
2424
self::assertInstanceOf(JunctionSchemas::class, $result);
25-
self::assertEqualsCanonicalizing(
26-
['junction_Photos2Posts', 'junction_PostsGallery', 'junction_PostsAttaches'],
27-
array_keys($result->indexByJunctionSchema())
25+
26+
// https://github.com/cebe/yii2-openapi/pull/141/files#diff-d2ab9925cad7eac58e0ff4cc0d251a937ecf49e4b6bf57f8b95aab76648a9d34R33
27+
// self::assertEqualsCanonicalizing(
28+
// ['junction_Photos2Posts', 'junction_PostsGallery', 'junction_PostsAttaches'],
29+
// array_keys($result->indexByJunctionSchema())
30+
// );
31+
$juncs = ['junction_Photos2Posts', 'junction_PostsGallery', 'junction_PostsAttaches'];
32+
sort($juncs);
33+
$indexedJuncs = array_keys($result->indexByJunctionSchema());
34+
sort($indexedJuncs);
35+
self::assertEquals(
36+
$juncs,
37+
$indexedJuncs
2838
);
29-
self::assertEqualsCanonicalizing(
30-
['Post', 'Photo'],
31-
array_keys($result->indexByClassSchema())
39+
40+
// https://github.com/cebe/yii2-openapi/pull/141/files#diff-d2ab9925cad7eac58e0ff4cc0d251a937ecf49e4b6bf57f8b95aab76648a9d34R33
41+
// self::assertEqualsCanonicalizing(
42+
// ['Post', 'Photo'],
43+
// array_keys($result->indexByClassSchema())
44+
// );
45+
$model = ['Post', 'Photo'];
46+
sort($model);
47+
$indexedModel = array_keys($result->indexByClassSchema());
48+
sort($indexedModel);
49+
self::assertEquals(
50+
$model,
51+
$indexedModel
3252
);
53+
3354
self::assertEquals('junction_PostAttaches', $result->addPrefix('PostAttaches'));
3455
self::assertEquals('PostAttaches', $result->trimPrefix('junction_PostAttaches'));
3556
self::assertTrue($result->isJunctionSchema('PostsAttaches'));

tests/unit/XDbTypeTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,8 @@ private function createTableForEditColumns()
209209

210210
public function testValidationRules()
211211
{
212-
$this->deleteTables();
213-
214212
// remove
215213
// $this->removeStaleMigrationsRecords();
216-
217214
$this->deleteTables();
218215
$testFile = Yii::getAlias("@specs/x_db_type/rules_and_more/x_db_type_mysql.php");
219216
$this->runGenerator($testFile, 'mysql');

0 commit comments

Comments
 (0)