From 0f30028f0879700667675e0c7710fb364ec4645a Mon Sep 17 00:00:00 2001 From: Guillaume Date: Fri, 4 Sep 2020 15:53:50 +0200 Subject: [PATCH 01/10] ScalarBeanPropertyDescriptor: Fix variable for resource null check --- src/Utils/ScalarBeanPropertyDescriptor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utils/ScalarBeanPropertyDescriptor.php b/src/Utils/ScalarBeanPropertyDescriptor.php index 9bfbd360..94dd70cb 100644 --- a/src/Utils/ScalarBeanPropertyDescriptor.php +++ b/src/Utils/ScalarBeanPropertyDescriptor.php @@ -224,7 +224,7 @@ public function getGetterSetterCode(): array if ($normalizedType === 'resource') { $checkNullable = ''; if ($isNullable) { - $checkNullable = sprintf('$%s !== null && ', $this->column->getName()); + $checkNullable = sprintf('$%s !== null && ', $variableName); } $resourceTypeCheck .= << Date: Thu, 24 Sep 2020 15:15:47 +0200 Subject: [PATCH 02/10] Deeper Composite FK: Test Case --- tests/TDBMAbstractServiceTest.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/TDBMAbstractServiceTest.php b/tests/TDBMAbstractServiceTest.php index 97608fda..60cdcdfb 100644 --- a/tests/TDBMAbstractServiceTest.php +++ b/tests/TDBMAbstractServiceTest.php @@ -458,8 +458,12 @@ private static function initSchema(Connection $connection): void ->column('id')->integer()->primaryKey()->autoIncrement() ->column('base_object_id')->references('base_objects')->unique()->comment('@JsonCollection'); + $db->table('composite_fk_target_reference') + ->column('id')->integer()->primaryKey()->autoIncrement() + ->column('label')->string(); + $targetTable = $db->table('composite_fk_target') - ->column('id_1')->integer() + ->column('id_1')->references('composite_fk_target_reference') ->column('id_2')->integer() ->then()->primaryKey(['id_1', 'id_2']); $db->table('composite_fk_source') @@ -800,6 +804,10 @@ private static function initSchema(Connection $connection): void 'person_id' => 1, 'boat_id' => 1, ]); + self::insert($connection, 'composite_fk_target_reference', [ + 'id' => 1, + 'label' => 'test' + ]); self::insert($connection, 'composite_fk_target', [ 'id_1' => 1, 'id_2' => 1 From 94e51b0fbe4eaccf98ed605e81abf5803765462b Mon Sep 17 00:00:00 2001 From: Guillaume Date: Thu, 24 Sep 2020 15:16:19 +0200 Subject: [PATCH 03/10] Deeper Composite FK: Implementation --- src/Utils/ObjectBeanPropertyDescriptor.php | 11 ++++++++--- tests/TDBMDaoGeneratorTest.php | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Utils/ObjectBeanPropertyDescriptor.php b/src/Utils/ObjectBeanPropertyDescriptor.php index 8a14be67..55bb0690 100644 --- a/src/Utils/ObjectBeanPropertyDescriptor.php +++ b/src/Utils/ObjectBeanPropertyDescriptor.php @@ -261,11 +261,13 @@ private function getLazySerializeCode(string $propertyAccess): string if ($descriptor instanceof InheritanceReferencePropertyDescriptor) { $descriptor = $descriptor->getNonScalarReferencedPropertyDescriptor(); } + $indexName = ltrim($descriptor->getVariableName(), '$'); + $columnGetterName = $descriptor->getGetterName(); if ($descriptor instanceof ObjectBeanPropertyDescriptor) { - $rows[] = trim($descriptor->getLazySerializeCode($propertyAccess), '[]'); + $varName = '$o' . lcfirst($indexName); + $lazySerializeCode = $descriptor->getLazySerializeCode($varName); + $rows[] = "'$indexName' => ($varName = $propertyAccess->$columnGetterName()) ? $lazySerializeCode : null"; } elseif ($descriptor instanceof ScalarBeanPropertyDescriptor) { - $indexName = ltrim($descriptor->getVariableName(), '$'); - $columnGetterName = $descriptor->getGetterName(); $rows[] = "'$indexName' => $propertyAccess->$columnGetterName()"; } else { throw new TDBMException('PropertyDescriptor of class `' . get_class($descriptor) . '` cannot be serialized.'); @@ -277,6 +279,9 @@ private function getLazySerializeCode(string $propertyAccess): string private function getBeanPropertyDescriptor(string $column): AbstractBeanPropertyDescriptor { foreach ($this->foreignBeanDescriptor->getBeanPropertyDescriptors() as $descriptor) { + if ($descriptor instanceof ObjectBeanPropertyDescriptor && in_array($column, $descriptor->getForeignKey()->getLocalColumns(), true)) { + return $descriptor; + } if ($descriptor instanceof ScalarBeanPropertyDescriptor && $descriptor->getColumnName() === $column) { return $descriptor; } diff --git a/tests/TDBMDaoGeneratorTest.php b/tests/TDBMDaoGeneratorTest.php index c4bc19f2..1d18f56c 100644 --- a/tests/TDBMDaoGeneratorTest.php +++ b/tests/TDBMDaoGeneratorTest.php @@ -2165,7 +2165,7 @@ public function testLazyStopRecursionOnCompositeForeignKey(): void $compositeFkSourceDao = new CompositeFkSourceDao($this->tdbmService); $compositeFkSourceBean = $compositeFkSourceDao->getById(1); $json = $compositeFkSourceBean->jsonSerialize(true); - $this->assertEquals(1, $json['compositeFkTarget']['id1']); + $this->assertEquals(1, $json['compositeFkTarget']['1']['id']); $this->assertEquals(1, $json['compositeFkTarget']['id2']); } From bd3f65349e086fcc7e3b4ebf7c8d5c817a8cda9d Mon Sep 17 00:00:00 2001 From: Guillaume Date: Thu, 24 Sep 2020 17:53:58 +0200 Subject: [PATCH 04/10] Deeper Composite FK: Fix flatten in case of inheritance --- src/Utils/AbstractBeanPropertyDescriptor.php | 2 +- src/Utils/ObjectBeanPropertyDescriptor.php | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Utils/AbstractBeanPropertyDescriptor.php b/src/Utils/AbstractBeanPropertyDescriptor.php index c8e559c3..3c949905 100644 --- a/src/Utils/AbstractBeanPropertyDescriptor.php +++ b/src/Utils/AbstractBeanPropertyDescriptor.php @@ -67,7 +67,7 @@ abstract public function getPhpType(): string; */ public function getParamAnnotation(): ParamTag { - return new ParamTag($this->getVariableName(), [ $this->getPhpType() ]); + return new ParamTag($this->getSafeVariableName(), [ $this->getPhpType() ]); } public function getVariableName(): string diff --git a/src/Utils/ObjectBeanPropertyDescriptor.php b/src/Utils/ObjectBeanPropertyDescriptor.php index 55bb0690..f2009564 100644 --- a/src/Utils/ObjectBeanPropertyDescriptor.php +++ b/src/Utils/ObjectBeanPropertyDescriptor.php @@ -258,15 +258,22 @@ private function getLazySerializeCode(string $propertyAccess): string $rows = []; foreach ($this->getForeignKey()->getUnquotedForeignColumns() as $column) { $descriptor = $this->getBeanPropertyDescriptor($column); + $shouldFlatten = false; if ($descriptor instanceof InheritanceReferencePropertyDescriptor) { $descriptor = $descriptor->getNonScalarReferencedPropertyDescriptor(); + $shouldFlatten = true; } + $indexName = ltrim($descriptor->getVariableName(), '$'); $columnGetterName = $descriptor->getGetterName(); if ($descriptor instanceof ObjectBeanPropertyDescriptor) { - $varName = '$o' . lcfirst($indexName); - $lazySerializeCode = $descriptor->getLazySerializeCode($varName); - $rows[] = "'$indexName' => ($varName = $propertyAccess->$columnGetterName()) ? $lazySerializeCode : null"; + if ($shouldFlatten) { + $rows[] = trim($descriptor->getLazySerializeCode($propertyAccess), '[]'); + } else { + $varName = $descriptor->getSafeVariableName(); + $lazySerializeCode = $descriptor->getLazySerializeCode($varName); + $rows[] = "'$indexName' => ($varName = $propertyAccess->$columnGetterName()) ? $lazySerializeCode : null"; + } } elseif ($descriptor instanceof ScalarBeanPropertyDescriptor) { $rows[] = "'$indexName' => $propertyAccess->$columnGetterName()"; } else { @@ -279,10 +286,10 @@ private function getLazySerializeCode(string $propertyAccess): string private function getBeanPropertyDescriptor(string $column): AbstractBeanPropertyDescriptor { foreach ($this->foreignBeanDescriptor->getBeanPropertyDescriptors() as $descriptor) { - if ($descriptor instanceof ObjectBeanPropertyDescriptor && in_array($column, $descriptor->getForeignKey()->getLocalColumns(), true)) { + if ($descriptor instanceof ScalarBeanPropertyDescriptor && $descriptor->getColumnName() === $column) { return $descriptor; } - if ($descriptor instanceof ScalarBeanPropertyDescriptor && $descriptor->getColumnName() === $column) { + if ($descriptor instanceof ObjectBeanPropertyDescriptor && in_array($column, $descriptor->getForeignKey()->getLocalColumns(), true)) { return $descriptor; } } From 9d060fc5f70705b5d604a60c42d72444a79334e0 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Thu, 24 Sep 2020 18:02:23 +0200 Subject: [PATCH 05/10] Deeper Composite FK: Fix ternary --- src/Utils/ObjectBeanPropertyDescriptor.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Utils/ObjectBeanPropertyDescriptor.php b/src/Utils/ObjectBeanPropertyDescriptor.php index f2009564..c5ac455b 100644 --- a/src/Utils/ObjectBeanPropertyDescriptor.php +++ b/src/Utils/ObjectBeanPropertyDescriptor.php @@ -270,9 +270,8 @@ private function getLazySerializeCode(string $propertyAccess): string if ($shouldFlatten) { $rows[] = trim($descriptor->getLazySerializeCode($propertyAccess), '[]'); } else { - $varName = $descriptor->getSafeVariableName(); - $lazySerializeCode = $descriptor->getLazySerializeCode($varName); - $rows[] = "'$indexName' => ($varName = $propertyAccess->$columnGetterName()) ? $lazySerializeCode : null"; + $lazySerializeCode = $descriptor->getLazySerializeCode("$propertyAccess->$columnGetterName()"); + $rows[] = "'$indexName' => $lazySerializeCode"; } } elseif ($descriptor instanceof ScalarBeanPropertyDescriptor) { $rows[] = "'$indexName' => $propertyAccess->$columnGetterName()"; From c66408b1d77793b80560f345dcbafccbbe2c0465 Mon Sep 17 00:00:00 2001 From: Alpha Date: Fri, 9 Oct 2020 11:50:04 +0200 Subject: [PATCH 06/10] handle multi-line expression in unchecked OrderBy (#233) * handle multi-line expression in unchecked OrderBy --- src/OrderByAnalyzer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrderByAnalyzer.php b/src/OrderByAnalyzer.php index 6055baec..7e499c5c 100644 --- a/src/OrderByAnalyzer.php +++ b/src/OrderByAnalyzer.php @@ -131,7 +131,7 @@ private function analyzeOrderByNoCache(string $orderBy) : array */ private function trimDirection(string $sql) : string { - preg_match('/^(.*)(\s+(DESC|ASC|))*$/Ui', $sql, $matches); + preg_match('/^((.|\n)*)(\s+(DESC|ASC))?$/Ui', $sql, $matches); return $matches[1]; } From 074e7d00cfe00a9893606538ef89c32b9729e5d0 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Thu, 16 Jan 2020 14:10:38 +0100 Subject: [PATCH 07/10] Inheritance - FK save: test case --- tests/TDBMDaoGeneratorTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/TDBMDaoGeneratorTest.php b/tests/TDBMDaoGeneratorTest.php index 1d18f56c..a141c871 100644 --- a/tests/TDBMDaoGeneratorTest.php +++ b/tests/TDBMDaoGeneratorTest.php @@ -62,6 +62,8 @@ use TheCodingMachine\TDBM\Test\Dao\Bean\Generated\BoatBaseBean; use TheCodingMachine\TDBM\Test\Dao\Bean\Generated\FileBaseBean; use TheCodingMachine\TDBM\Test\Dao\Bean\Generated\UserBaseBean; +use TheCodingMachine\TDBM\Test\Dao\Bean\InheritanceAgencyBean; +use TheCodingMachine\TDBM\Test\Dao\Bean\InheritanceSocietyBean; use TheCodingMachine\TDBM\Test\Dao\Bean\InheritedObjectBean; use TheCodingMachine\TDBM\Test\Dao\Bean\NodeBean; use TheCodingMachine\TDBM\Test\Dao\Bean\PersonBean; @@ -78,6 +80,8 @@ use TheCodingMachine\TDBM\Test\Dao\DogDao; use TheCodingMachine\TDBM\Test\Dao\FileDao; use TheCodingMachine\TDBM\Test\Dao\Generated\UserBaseDao; +use TheCodingMachine\TDBM\Test\Dao\InheritanceAgencyDao; +use TheCodingMachine\TDBM\Test\Dao\InheritanceSocietyDao; use TheCodingMachine\TDBM\Test\Dao\InheritedObjectDao; use TheCodingMachine\TDBM\Test\Dao\NodeDao; use TheCodingMachine\TDBM\Test\Dao\PersonDao; @@ -2208,4 +2212,15 @@ public function testFindFromRawSQLOnInheritance(): void $this->assertNotNull($objects->first()); $this->assertEquals(6, $objects->count()); } + + public function testInheritanceFkWithDifferentPkName(): void + { + $inheritanceSocietyDao = new InheritanceSocietyDao($this->tdbmService); + $inheritanceAgencyDao = new InheritanceAgencyDao($this->tdbmService); + $society = new InheritanceSocietyBean(); + $inheritanceSocietyDao->save($society); + $this->assertIsInt($society->getId()); + $agency = new InheritanceAgencyBean($society); + $inheritanceAgencyDao->save($agency); + } } From b32a138f28d92728fc2e1933df59d79b38dffc93 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Thu, 16 Jan 2020 16:33:32 +0100 Subject: [PATCH 08/10] Inheritance - FK save: Ensure column name is the base one --- src/Utils/BeanDescriptor.php | 77 ++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 25 deletions(-) diff --git a/src/Utils/BeanDescriptor.php b/src/Utils/BeanDescriptor.php index d7f73df4..24c2a79d 100644 --- a/src/Utils/BeanDescriptor.php +++ b/src/Utils/BeanDescriptor.php @@ -1223,7 +1223,6 @@ private function removeDuplicateIndexes(array $indexes): array private function generateFindByDaoCodeForIndex(Index $index, string $beanNamespace, string $beanClassName): ?MethodGenerator { $columns = $index->getColumns(); - $usedBeans = []; /** * The list of elements building this index (expressed as columns or foreign keys) @@ -1249,42 +1248,26 @@ private function generateFindByDaoCodeForIndex(Index $index, string $beanNamespa } $parameters = []; - //$functionParameters = []; $first = true; /** @var AbstractBeanPropertyDescriptor $element */ foreach ($elements as $element) { $parameter = new ParameterGenerator(ltrim($element->getSafeVariableName(), '$')); if (!$first && !($element->isCompulsory() && $index->isUnique())) { $parameterType = '?'; - //$functionParameter = '?'; } else { $parameterType = ''; - //$functionParameter = ''; } $parameterType .= $element->getPhpType(); $parameter->setType($parameterType); if (!$first && !($element->isCompulsory() && $index->isUnique())) { $parameter->setDefaultValue(null); } - //$functionParameter .= $element->getPhpType(); - $elementClassName = $element->getClassName(); - if ($elementClassName) { - $usedBeans[] = $beanNamespace.'\\'.$elementClassName; - } - //$functionParameter .= ' '.$element->getVariableName(); if ($first) { $first = false; - } /*else { - $functionParameter .= ' = null'; - }*/ - //$functionParameters[] = $functionParameter; + } $parameters[] = $parameter; } - //$functionParametersString = implode(', ', $functionParameters); - - $count = 0; - $params = []; $filterArrayCode = ''; $commentArguments = []; @@ -1306,12 +1289,11 @@ private function generateFindByDaoCodeForIndex(Index $index, string $beanNamespa } elseif ($element instanceof ObjectBeanPropertyDescriptor) { $foreignKey = $element->getForeignKey(); $columns = SafeFunctions::arrayCombine($foreignKey->getLocalColumns(), $foreignKey->getForeignColumns()); - ++$count; $foreignTable = $this->schema->getTable($foreignKey->getForeignTableName()); foreach ($columns as $localColumn => $foreignColumn) { // TODO: a foreign key could point to another foreign key. In this case, there is no getter for the pointed column. We don't support this case. $targetedElement = new ScalarBeanPropertyDescriptor($foreignTable, $foreignTable->getColumn($foreignColumn), $this->namingStrategy, $this->annotationParser); - if ($first || $element->isCompulsory() && $index->isUnique()) { + if ($first || ($element->isCompulsory() && $index->isUnique())) { // First parameter for index is not nullable $filterArrayCode .= ' '.var_export($localColumn, true).' => '.$element->getSafeVariableName().'->'.$targetedElement->getGetterName()."(),\n"; } else { @@ -1326,9 +1308,6 @@ private function generateFindByDaoCodeForIndex(Index $index, string $beanNamespa } } - //$paramsString = implode("\n", $params); - - $methodName = $this->namingStrategy->getFindByIndexMethodName($index, $elements); $method = new MethodGenerator($methodName); @@ -1408,7 +1387,11 @@ private function generateOnDeleteCode(): ?MethodGenerator foreach ($relationships as $relationship) { if ($relationship instanceof ObjectBeanPropertyDescriptor) { $tdbmFk = ForeignKey::createFromFk($relationship->getForeignKey()); - $code .= '$this->setRef('.var_export($tdbmFk->getCacheKey(), true).', null, '.var_export($this->table->getName(), true).");\n"; + $code .= sprintf( + "\$this->setRef(%s, null, %s);\n", + var_export($tdbmFk->getCacheKey(), true), + var_export($this->table->getName(), true) + ); } } @@ -1607,10 +1590,21 @@ private function generateGetForeignKeys(array $fks): MethodGenerator foreach ($fks as $fk) { $tdbmFk = ForeignKey::createFromFk($fk); + + // Override column name in case of inheritance + $foreignTableName = $fk->getForeignTableName(); + $foreignColumns = $fk->getUnquotedForeignColumns(); + foreach ($foreignColumns as $key => $foreignColumn) { + $descriptor = $this->findScalarPropertyDescriptorInTable($foreignTableName, $foreignColumn); + if ($descriptor instanceof InheritanceReferencePropertyDescriptor) { + $foreignColumns[$key] = $this->foreignColumnNameInInheritance($descriptor, $foreignColumn); + } + } + $fkArray[$tdbmFk->getCacheKey()] = [ ForeignKey::FOREIGN_TABLE => $fk->getForeignTableName(), ForeignKey::LOCAL_COLUMNS => $fk->getUnquotedLocalColumns(), - ForeignKey::FOREIGN_COLUMNS => $fk->getUnquotedForeignColumns(), + ForeignKey::FOREIGN_COLUMNS => $foreignColumns, ]; } @@ -1646,6 +1640,39 @@ private function generateGetForeignKeys(array $fks): MethodGenerator return $method; } + private function findScalarPropertyDescriptorInTable(string $tableName, string $columnName): ?ScalarBeanPropertyDescriptor + { + $beanDescriptor = $this->registry->getBeanForTableName($tableName); + foreach ($beanDescriptor->getBeanPropertyDescriptors() as $descriptor) { + if ($descriptor instanceof ScalarBeanPropertyDescriptor && $descriptor->getColumnName() === $columnName) { + return $descriptor; + } + } + return null; + } + + /** + * Extract the foreign column name from a InheritanceReferencePropertyDescriptor + */ + private function foreignColumnNameInInheritance(InheritanceReferencePropertyDescriptor $descriptor, string $column): string + { + $nonReferenceDescriptor = $descriptor->getNonScalarReferencedPropertyDescriptor(); + if ($nonReferenceDescriptor instanceof ScalarBeanPropertyDescriptor) { + return $nonReferenceDescriptor->getColumnName(); + } + if ($nonReferenceDescriptor instanceof ObjectBeanPropertyDescriptor) { + $foreignKey = $nonReferenceDescriptor->getForeignKey(); + $localColumns = $foreignKey->getLocalColumns(); + $foreignColumns = $foreignKey->getForeignColumns(); + foreach ($localColumns as $key => $localColumn) { + if ($localColumn === $column) { + return $foreignColumns[$key]; + } + } + } + return $column; + } + /** * @param mixed $var * @param string $indent From a4815788fd3ad978136cd031ad0ff1ae3b1816f1 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Thu, 16 Jan 2020 16:43:52 +0100 Subject: [PATCH 09/10] Inheritance - FK save: Fix lowest phpunit --- tests/TDBMDaoGeneratorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TDBMDaoGeneratorTest.php b/tests/TDBMDaoGeneratorTest.php index a141c871..207b6cde 100644 --- a/tests/TDBMDaoGeneratorTest.php +++ b/tests/TDBMDaoGeneratorTest.php @@ -2219,7 +2219,7 @@ public function testInheritanceFkWithDifferentPkName(): void $inheritanceAgencyDao = new InheritanceAgencyDao($this->tdbmService); $society = new InheritanceSocietyBean(); $inheritanceSocietyDao->save($society); - $this->assertIsInt($society->getId()); + $this->assertNotNull($society->getId()); $agency = new InheritanceAgencyBean($society); $inheritanceAgencyDao->save($agency); } From 0d0bf4ed42ab46e88fbe16fee49f0261c3fd9d6c Mon Sep 17 00:00:00 2001 From: Guillaume Date: Wed, 22 Jan 2020 16:51:22 +0100 Subject: [PATCH 10/10] Inheritance - FK save: Fix postgres test --- tests/TDBMAbstractServiceTest.php | 6 +++--- tests/TDBMDaoGeneratorTest.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/TDBMAbstractServiceTest.php b/tests/TDBMAbstractServiceTest.php index 60cdcdfb..678fc1ba 100644 --- a/tests/TDBMAbstractServiceTest.php +++ b/tests/TDBMAbstractServiceTest.php @@ -476,10 +476,10 @@ private static function initSchema(Connection $connection): void // - `inheritance_agency` have an FK to `inheritance_society.**id_entity**` // - `inheritance_society` have an FK to `inheritance_entity.**id**` $db->table('inheritance_entity') - ->column('id')->integer()->primaryKey()->autoIncrement(); + ->column('id')->integer()->primaryKey()->autoIncrement() + ->column('name')->string(); $db->table('inheritance_society') - ->column('id_entity')->references('inheritance_entity')->primaryKey() - ->then(); + ->column('id_entity')->references('inheritance_entity')->primaryKey(); $db->table('inheritance_agency') ->column('id')->integer()->primaryKey()->autoIncrement() ->column('id_parent_society')->references('inheritance_society'); diff --git a/tests/TDBMDaoGeneratorTest.php b/tests/TDBMDaoGeneratorTest.php index 207b6cde..65b9a507 100644 --- a/tests/TDBMDaoGeneratorTest.php +++ b/tests/TDBMDaoGeneratorTest.php @@ -2217,7 +2217,7 @@ public function testInheritanceFkWithDifferentPkName(): void { $inheritanceSocietyDao = new InheritanceSocietyDao($this->tdbmService); $inheritanceAgencyDao = new InheritanceAgencyDao($this->tdbmService); - $society = new InheritanceSocietyBean(); + $society = new InheritanceSocietyBean('test'); $inheritanceSocietyDao->save($society); $this->assertNotNull($society->getId()); $agency = new InheritanceAgencyBean($society);