diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 15deb812..7d67d101 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,7 @@ jobs: strategy: fail-fast: false matrix: - php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1'] # TODO add '8.2' https://github.com/cebe/yii2-openapi/issues/142 + php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] # TODO use cache steps: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 695ac503..e1a62b7d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,10 +10,12 @@ cd yii2-openapi make clean_all make up make installdocker +sudo chmod -R 777 tests/tmp/ # https://github.com/cebe/yii2-openapi/issues/156 make migrate # to check everything is setup up correctly ensure all tests passes make cli +# in Docker container ./vendor/bin/phpunit # create new branch from master and Happy contributing! diff --git a/composer.json b/composer.json index 4fbfc425..29cdff30 100644 --- a/composer.json +++ b/composer.json @@ -20,9 +20,9 @@ "require": { "php": ">=7.2.0", "cebe/php-openapi": "^1.5.0", - "yiisoft/yii2": "~2.0.15", + "yiisoft/yii2": "~2.0.48", "yiisoft/yii2-gii": "~2.0.0 | ~2.1.0 | ~2.2.0| ~2.3.0", - "laminas/laminas-code": "^3.4 | ^4.0", + "laminas/laminas-code": ">=3.4 <=4.13", "insolita/yii2-fractal": "^1.0.0", "fakerphp/faker": "^1.9", "sam-it/yii2-mariadb": "^2.0" diff --git a/src/lib/ColumnToCode.php b/src/lib/ColumnToCode.php index f624bfd9..fb4f8748 100644 --- a/src/lib/ColumnToCode.php +++ b/src/lib/ColumnToCode.php @@ -299,7 +299,7 @@ public static function wrapQuotes(string $str, string $quotes = "'", bool $escap public static function enumToString(array $enum):string { - $items = implode(", ", array_map('self::wrapQuotes', $enum)); + $items = implode(", ", array_map(self::class.'::wrapQuotes', $enum)); return self::escapeQuotes($items); } diff --git a/src/lib/FakerStubResolver.php b/src/lib/FakerStubResolver.php index a0e029b8..03ab132e 100644 --- a/src/lib/FakerStubResolver.php +++ b/src/lib/FakerStubResolver.php @@ -53,8 +53,13 @@ public function resolve():?string // column name ends with `_id` if (substr($this->attribute->columnName, -strlen('_id'))==='_id') { - return '$faker->randomElement(\\'.$this->config->modelNamespace - . ($this->config->modelNamespace ? '\\' : '') + $config = $this->config; + if (!$config) { + $config = new Config; + } + $mn = $config->modelNamespace; + return '$faker->randomElement(\\'.$mn + . ($mn ? '\\' : '') . ucfirst($this->attribute->reference).'::find()->select("id")->column())'; } diff --git a/tests/docker/Dockerfile b/tests/docker/Dockerfile index 796c1f68..84875f3b 100644 --- a/tests/docker/Dockerfile +++ b/tests/docker/Dockerfile @@ -35,7 +35,7 @@ RUN apt-get update && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \ # https://xdebug.org/docs/compat \ - && if [ "$BUILD_PHP_VERSION" = "8.2" ] ; then pecl install xdebug ; else pecl install xdebug-3.1.5 ; fi \ + && if [ "$BUILD_PHP_VERSION" = "8.2" ] || [ "$BUILD_PHP_VERSION" = "8.3" ] ; then pecl install xdebug ; else pecl install xdebug-3.1.5 ; fi \ && docker-php-ext-enable xdebug \ && docker-php-ext-install \ zip \ diff --git a/tests/fixtures/blog.php b/tests/fixtures/blog.php index 9fa874a5..e7e02534 100644 --- a/tests/fixtures/blog.php +++ b/tests/fixtures/blog.php @@ -73,13 +73,13 @@ ->asReference('Category') ->setRequired() ->setDescription('Category of posts') - ->setFakerStub('$faker->randomElement(\Category::find()->select("id")->column())'), + ->setFakerStub('$faker->randomElement(\app\models\Category::find()->select("id")->column())'), 'created_at' => (new Attribute('created_at', ['phpType' => 'string', 'dbType' => 'date'])) ->setFakerStub('$faker->dateTimeThisCentury->format(\'Y-m-d\')'), 'created_by' => (new Attribute('created_by', ['phpType' => 'int', 'dbType' => 'integer'])) ->asReference('User') ->setDescription('The User') - ->setFakerStub('$faker->randomElement(\User::find()->select("id")->column())'), + ->setFakerStub('$faker->randomElement(\app\models\User::find()->select("id")->column())'), ], 'relations' => [ 'category' => new AttributeRelation('category', @@ -110,12 +110,12 @@ ->setSize(128) ->asReference('Post') ->setDescription('A blog post (uid used as pk for test purposes)') - ->setFakerStub('$faker->randomElement(\Post::find()->select("id")->column())'), + ->setFakerStub('$faker->randomElement(\app\models\Post::find()->select("id")->column())'), 'author' => (new Attribute('author', ['phpType' => 'int', 'dbType' => 'integer'])) ->setRequired() ->asReference('User') ->setDescription('The User') - ->setFakerStub('$faker->randomElement(\User::find()->select("id")->column())'), + ->setFakerStub('$faker->randomElement(\app\models\User::find()->select("id")->column())'), 'message' => (new Attribute('message', ['phpType' => 'array', 'dbType' => 'json', 'xDbType' => 'json'])) ->setRequired()->setDefault([])->setFakerStub('[]'), 'meta_data' => (new Attribute('meta_data', ['phpType' => 'array', 'dbType' => 'json', 'xDbType' => 'json'])) diff --git a/tests/unit/MultiDbFreshMigrationTest.php b/tests/unit/MultiDbFreshMigrationTest.php index 5fbd2d49..366bfb0b 100644 --- a/tests/unit/MultiDbFreshMigrationTest.php +++ b/tests/unit/MultiDbFreshMigrationTest.php @@ -185,8 +185,11 @@ public function testAfterKeyword() $dbSchema, 'tableName', $columnSchema, false, false ); - $this->assertStringContainsString('AFTER username', $column->getCode()); - $this->assertStringNotContainsString('AFTER username', $columnWithoutPreviousCol->getCode()); + // https://github.com/cebe/yii2-openapi/pull/141/files#diff-d2ab9925cad7eac58e0ff4cc0d251a937ecf49e4b6bf57f8b95aab76648a9d34R33 + $this->assertSame(strpos($column->getCode(), 'AFTER username'), 28); + // $this->assertStringContainsString('AFTER username', $column->getCode()); + // $this->assertStringNotContainsString('AFTER username', $columnWithoutPreviousCol->getCode()); + $this->assertFalse(strpos($columnWithoutPreviousCol->getCode(), 'AFTER username')); // test `after` for fluent part in function call `after()` unset($column, $columnWithoutPreviousCol); @@ -198,7 +201,12 @@ public function testAfterKeyword() $dbSchema, 'tableName', $columnSchema, true, false ); - $this->assertStringContainsString("->after('username')", $column->getCode()); - $this->assertStringNotContainsString("->after('username')", $columnWithoutPreviousCol->getCode()); + // https://github.com/cebe/yii2-openapi/pull/141/files#diff-d2ab9925cad7eac58e0ff4cc0d251a937ecf49e4b6bf57f8b95aab76648a9d34R33 + // $this->assertStringContainsString("->after('username')", $column->getCode()); + $this->assertSame(strpos($column->getCode(), "->after('username')"), 41); + + // https://github.com/cebe/yii2-openapi/pull/141/files#diff-d2ab9925cad7eac58e0ff4cc0d251a937ecf49e4b6bf57f8b95aab76648a9d34R33 + // $this->assertStringNotContainsString("->after('username')", $columnWithoutPreviousCol->getCode()); + $this->assertFalse(strpos($columnWithoutPreviousCol->getCode(), "->after('username')")); } } diff --git a/tests/unit/SchemaToDatabaseTest.php b/tests/unit/SchemaToDatabaseTest.php index 4a8441bd..e18a5c0b 100644 --- a/tests/unit/SchemaToDatabaseTest.php +++ b/tests/unit/SchemaToDatabaseTest.php @@ -22,14 +22,35 @@ public function testFindJunctionSchemas() //VarDumper::dump($result->indexByJunctionRef()); //VarDumper::dump($result->indexByJunctionSchema()); self::assertInstanceOf(JunctionSchemas::class, $result); - self::assertEqualsCanonicalizing( - ['junction_Photos2Posts', 'junction_PostsGallery', 'junction_PostsAttaches'], - array_keys($result->indexByJunctionSchema()) + + // https://github.com/cebe/yii2-openapi/pull/141/files#diff-d2ab9925cad7eac58e0ff4cc0d251a937ecf49e4b6bf57f8b95aab76648a9d34R33 + // self::assertEqualsCanonicalizing( + // ['junction_Photos2Posts', 'junction_PostsGallery', 'junction_PostsAttaches'], + // array_keys($result->indexByJunctionSchema()) + // ); + $juncs = ['junction_Photos2Posts', 'junction_PostsGallery', 'junction_PostsAttaches']; + sort($juncs); + $indexedJuncs = array_keys($result->indexByJunctionSchema()); + sort($indexedJuncs); + self::assertEquals( + $juncs, + $indexedJuncs ); - self::assertEqualsCanonicalizing( - ['Post', 'Photo'], - array_keys($result->indexByClassSchema()) + + // https://github.com/cebe/yii2-openapi/pull/141/files#diff-d2ab9925cad7eac58e0ff4cc0d251a937ecf49e4b6bf57f8b95aab76648a9d34R33 + // self::assertEqualsCanonicalizing( + // ['Post', 'Photo'], + // array_keys($result->indexByClassSchema()) + // ); + $model = ['Post', 'Photo']; + sort($model); + $indexedModel = array_keys($result->indexByClassSchema()); + sort($indexedModel); + self::assertEquals( + $model, + $indexedModel ); + self::assertEquals('junction_PostAttaches', $result->addPrefix('PostAttaches')); self::assertEquals('PostAttaches', $result->trimPrefix('junction_PostAttaches')); self::assertTrue($result->isJunctionSchema('PostsAttaches')); diff --git a/tests/unit/XDbTypeTest.php b/tests/unit/XDbTypeTest.php index 202afed6..2f8149d3 100644 --- a/tests/unit/XDbTypeTest.php +++ b/tests/unit/XDbTypeTest.php @@ -209,11 +209,8 @@ private function createTableForEditColumns() public function testValidationRules() { - $this->deleteTables(); - // remove // $this->removeStaleMigrationsRecords(); - $this->deleteTables(); $testFile = Yii::getAlias("@specs/x_db_type/rules_and_more/x_db_type_mysql.php"); $this->runGenerator($testFile, 'mysql');