From d64ceed7e5b4ab9807b8d70ff24c4b73224277f4 Mon Sep 17 00:00:00 2001 From: Javier Spagnoletti Date: Thu, 5 Apr 2018 20:44:23 -0300 Subject: [PATCH] Add support for `null => true` in `CreateSchemaListener::postGenerateSchemaTable()` --- .travis.yml | 4 ++ .../EventListener/CreateSchemaListener.php | 7 ++- .../Fixtures/Issue/Issue318User.php | 43 +++++++++++++++++++ .../Tests/EntityAudit/IssueTest.php | 35 ++++++++++++--- 4 files changed, 80 insertions(+), 9 deletions(-) create mode 100644 tests/SimpleThings/Tests/EntityAudit/Fixtures/Issue/Issue318User.php diff --git a/.travis.yml b/.travis.yml index b050fc5e..0e0d1cd4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,8 @@ language: php sudo: false +dist: precise + branches: only: - 1.0 @@ -17,6 +19,8 @@ php: - 5.5 - 5.6 - 7.0 + - 7.1 + - 7.2 - nightly - hhvm diff --git a/src/SimpleThings/EntityAudit/EventListener/CreateSchemaListener.php b/src/SimpleThings/EntityAudit/EventListener/CreateSchemaListener.php index 23819e96..2403c4fd 100644 --- a/src/SimpleThings/EntityAudit/EventListener/CreateSchemaListener.php +++ b/src/SimpleThings/EntityAudit/EventListener/CreateSchemaListener.php @@ -83,10 +83,9 @@ public function postGenerateSchemaTable(GenerateSchemaTableEventArgs $eventArgs) foreach ($entityTable->getColumns() AS $column) { /* @var Column $column */ - $revisionTable->addColumn($column->getName(), $column->getType()->getName(), array_merge( - $column->toArray(), - array('notnull' => false, 'autoincrement' => false) - )); + $revisionTable->addColumn($column->getName(), $column->getType()->getName(), + array('notnull' => false, 'null' => true, 'autoincrement' => false) + $column->toArray() + ); } $revisionTable->addColumn($this->config->getRevisionFieldName(), $this->config->getRevisionIdFieldType()); $revisionTable->addColumn($this->config->getRevisionTypeFieldName(), 'string', array('length' => 4)); diff --git a/tests/SimpleThings/Tests/EntityAudit/Fixtures/Issue/Issue318User.php b/tests/SimpleThings/Tests/EntityAudit/Fixtures/Issue/Issue318User.php new file mode 100644 index 00000000..7f67016f --- /dev/null +++ b/tests/SimpleThings/Tests/EntityAudit/Fixtures/Issue/Issue318User.php @@ -0,0 +1,43 @@ +id; + } + + /** + * @return string + */ + public function getAlias() + { + return $this->alias; + } + + /** + * @param string $alias + * @return self + */ + public function setAlias($alias) + { + $this->alias = $alias; + return $this; + } +} diff --git a/tests/SimpleThings/Tests/EntityAudit/IssueTest.php b/tests/SimpleThings/Tests/EntityAudit/IssueTest.php index 487630f4..9c9db4b5 100644 --- a/tests/SimpleThings/Tests/EntityAudit/IssueTest.php +++ b/tests/SimpleThings/Tests/EntityAudit/IssueTest.php @@ -37,6 +37,7 @@ use SimpleThings\EntityAudit\Tests\Fixtures\Issue\Issue196Entity; use SimpleThings\EntityAudit\Tests\Fixtures\Issue\Issue31Reve; use SimpleThings\EntityAudit\Tests\Fixtures\Issue\Issue31User; +use SimpleThings\EntityAudit\Tests\Fixtures\Issue\Issue318User; use SimpleThings\EntityAudit\Tests\Fixtures\Issue\Issue87Organization; use SimpleThings\EntityAudit\Tests\Fixtures\Issue\Issue87Project; use SimpleThings\EntityAudit\Tests\Fixtures\Issue\Issue87ProjectComment; @@ -68,6 +69,7 @@ class IssueTest extends BaseTest 'SimpleThings\EntityAudit\Tests\Fixtures\Issue\Issue198Car', 'SimpleThings\EntityAudit\Tests\Fixtures\Issue\Issue198Owner', 'SimpleThings\EntityAudit\Tests\Fixtures\Issue\Issue196Entity', + 'SimpleThings\EntityAudit\Tests\Fixtures\Issue\Issue318User', 'SimpleThings\EntityAudit\Tests\Fixtures\Issue\ConvertToPHPEntity', ); @@ -92,6 +94,7 @@ class IssueTest extends BaseTest 'SimpleThings\EntityAudit\Tests\Fixtures\Issue\Issue196Entity', 'SimpleThings\EntityAudit\Tests\Fixtures\Issue\Issue198Car', 'SimpleThings\EntityAudit\Tests\Fixtures\Issue\Issue198Owner', + 'SimpleThings\EntityAudit\Tests\Fixtures\Issue\Issue318User', 'SimpleThings\EntityAudit\Tests\Fixtures\Issue\ConvertToPHPEntity', ); @@ -277,16 +280,16 @@ public function testIssue196() 'Current revision of audited entity is not equivalent to persisted entity:' ); } - + public function testIssue198() { $owner = new Issue198Owner(); $car = new Issue198Car(); - + $this->em->persist($owner); $this->em->persist($car); $this->em->flush(); - + $owner->addCar($car); $this->em->persist($owner); @@ -294,10 +297,10 @@ public function testIssue198() $this->em->flush(); $auditReader = $this->auditManager->createAuditReader($this->em); - + $car1 = $auditReader->find(get_class($car), $car->getId(), 1); $this->assertNull($car1->getOwner()); - + $car2 = $auditReader->find(get_class($car), $car->getId(), 2); $this->assertEquals($car2->getOwner()->getId(), $owner->getId()); } @@ -322,4 +325,26 @@ public function testConvertToPHP() 'Current revision of audited entity is not equivalent to persisted entity:' ); } + + public function testIssue318() + { + $user = new Issue318User(); + $user->setAlias('alias'); + $this->em->persist($user); + $this->em->flush(); + $userMetadata = $this->em->getClassMetadata(get_class($user)); + $classes = [$userMetadata]; + $schema = $this->getSchemaTool()->getSchemaFromMetadata($classes); + $schemaName = $schema->getName(); + $config = $this->getAuditManager()->getConfiguration(); + $entityTableUser = $schema->getTable(sprintf('%s.issue318user', $schemaName)); + $revisionsTableUser = $schema->getTable(sprintf('%s.%sissue318user%s', $schemaName, $config->getTablePrefix(), $config->getTableSuffix())); + $userNotNullColumnName = 'alias'; + + $this->assertTrue($entityTableUser->getColumn($userNotNullColumnName)->getNotnull()); + $this->assertFalse($revisionsTableUser->getColumn($userNotNullColumnName)->getNotnull()); + + $this->assertTrue($entityTableUser->getColumn('id')->getAutoincrement()); + $this->assertFalse($revisionsTableUser->getColumn('id')->getAutoincrement()); + } }