diff --git a/.github/workflows/main.yml b/.github/workflows/php.yml similarity index 97% rename from .github/workflows/main.yml rename to .github/workflows/php.yml index 01ea241..af40bc4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/php.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: - php-version: ["8.0"] + php-version: ["8.3"] operating-system: ["ubuntu-latest"] fail-fast: false @@ -80,11 +80,11 @@ jobs: runs-on: "${{ matrix.operating-system }}" strategy: matrix: - php-version: ["8.1"] + php-version: ["8.3"] operating-system: ["ubuntu-latest"] composer-args: [ "" ] include: - - php-version: "8.0" + - php-version: "8.1" operating-system: "ubuntu-latest" composer-args: "--ignore-platform-reqs" fail-fast: false @@ -136,7 +136,7 @@ jobs: run: 'echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"' - name: "Tests" - run: "vendor/bin/phpunit" + run: "vendor/bin/phpunit tests" static-analysis: name: "Static analysis" @@ -144,7 +144,7 @@ jobs: strategy: matrix: - php-version: ["8.1"] + php-version: ["8.3"] operating-system: ["ubuntu-latest"] fail-fast: false @@ -200,7 +200,7 @@ jobs: strategy: matrix: - php-version: ["8.1"] + php-version: ["8.3"] operating-system: ["ubuntu-latest"] fail-fast: false diff --git a/composer.json b/composer.json index 1081ec9..5e8408e 100644 --- a/composer.json +++ b/composer.json @@ -21,13 +21,13 @@ } }, "require": { - "php": "^8.0", - "nette/utils": "^3.0", - "nette/php-generator": "^3.0", + "php": "^8.1", + "nette/utils": "^3.1", + "nette/php-generator": "^4.0", "doctrine/inflector": "^2.0" }, "require-dev": { - "contributte/qa": "^0.1", + "contributte/qa": "^0.3", "phpunit/phpunit": ">=9.0", "phpstan/phpstan-deprecation-rules": "^1.0", "phpstan/phpstan-strict-rules": "^1.0" diff --git a/phpunit.xml b/phpunit.xml index a0b92d3..4ebb3e6 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,8 +1,8 @@ - - + + src/ - + diff --git a/ruleset.xml b/ruleset.xml index 21c02d0..10f8e48 100644 --- a/ruleset.xml +++ b/ruleset.xml @@ -8,13 +8,11 @@ - - diff --git a/src/Generator/Generator.php b/src/Generator/Generator.php index dd20b2f..2eaf21c 100644 --- a/src/Generator/Generator.php +++ b/src/Generator/Generator.php @@ -79,7 +79,7 @@ public function generateEntity(string $table): void $phpDocProperties = []; if (!$this->config->rewrite && class_exists($fqnClassName)) { - $this->cloneEntityFromExistingEntity($entity, ClassType::from($fqnClassName)); + $this->cloneEntityFromExistingEntity($entity, ClassType::from($fqnClassName)); //@phpstan-ignore-line $phpDocProperties = Helper::getPhpDocComments($entity->getComment() ?? ''); } @@ -98,7 +98,7 @@ public function generateEntity(string $table): void $this->validateColumnName($table, $column); $this->generateColumnConstant($entity, $column); - if (isset($entity->properties[$column->getField()]) || in_array($column->getField(), $phpDocProperties, true)) { + if ($entity->hasProperty($column->getField()) || in_array($column->getField(), $phpDocProperties, true)) { continue; } @@ -107,7 +107,7 @@ public function generateEntity(string $table): void } if ($this->config->generateMapping) { - if (isset($entity->properties['mapping'])) { + if ($entity->hasProperty('mapping')) { $mapping += $entity->getProperty('mapping')->getValue(); } @@ -167,7 +167,7 @@ protected function generateColumn(ClassType $entity, Column $column): void if ($this->config->generateSetters) { $setter = $entity->addMethod('set' . $this->inflector->classify($column->getField())); $setter->setVisibility($this->config->setterVisibility); - $setter->addParameter('value')->setTypeHint($type)->setNullable($column->isNullable()); + $setter->addParameter('value')->setType($type)->setNullable($column->isNullable()); $setter->addBody(str_replace('__FIELD__', $column->getField(), $this->config->setterBody)); $setter->setReturnType('self'); } @@ -218,8 +218,9 @@ private function cloneEntityFromExistingEntity(ClassType $entity, ClassType $fro $entity->setProperties($from->getProperties()); $entity->setComment($from->getComment()); $entity->setMethods($from->getMethods()); + $methods = $entity->getMethods(); - foreach ($entity->methods as $method) { + foreach ($methods as $method) { $fqnClassName = '\\' . $this->config->namespace . '\\' . $entity->getName(); $body = $this->getMethodBody($fqnClassName, $method->getName()); $method->setBody($body); diff --git a/tests/Generator/GeneratorTest.php b/tests/Generator/GeneratorTest.php index 1457393..1fba136 100644 --- a/tests/Generator/GeneratorTest.php +++ b/tests/Generator/GeneratorTest.php @@ -126,8 +126,7 @@ public function testGenerate_WithoutParameters_ShouldGenerateEntitiesForWholeTab $this->config->path = __DIR__ . '/../TestEntities'; $this->repository->expects($this->once())->method('getTables')->willReturn(['table1', 'table2']); - $this->repository->expects($this->exactly(2))->method('getTableColumns') - ->withConsecutive(['table1'], ['table2'])->willReturn($this->tableColumns); + $this->repository->expects($this->exactly(2))->method('getTableColumns')->willReturn($this->tableColumns); $this->generator->generate(); $entityFile = $this->config->path . '/Table1Entity.php';