Skip to content

Commit

Permalink
[doctrineGH-5728] Introduce functional test for insertable/updateable…
Browse files Browse the repository at this point in the history
… behaviors.
  • Loading branch information
beberlei committed Dec 18, 2021
1 parent 6ce1591 commit 057d8ca
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 35 deletions.
4 changes: 0 additions & 4 deletions lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -654,10 +654,6 @@ protected function prepareUpdateData($entity, $isInsert = false)
$columnName = $fieldMapping['columnName'];

if (! $isInsert && isset($fieldMapping['notUpdateable'])) {
if ($change[0] !== $change[1]) {
throw NonUpdateableField::byName($field);
}

continue;
}

Expand Down
17 changes: 0 additions & 17 deletions lib/Doctrine/ORM/Persisters/Exception/NonUpdateableField.php

This file was deleted.

8 changes: 1 addition & 7 deletions tests/Doctrine/Tests/Models/Upsertable/Insertable.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Insertable

/**
* @var string
* @Column(type="string", insertable=false)
* @Column(type="string", insertable=false, options={"default": "1234"})
*/
public $nonInsertableContent;

Expand All @@ -35,10 +35,4 @@ class Insertable
* @Column(type="string", insertable=true)
*/
public $insertableContent;

/**
* @var string
* @Column(type="string")
*/
public $insertableContentDefault;
}
6 changes: 0 additions & 6 deletions tests/Doctrine/Tests/Models/Upsertable/Updateable.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,4 @@ class Updateable
* @Column(type="string", updateable=true)
*/
public $updateableContent;

/**
* @var string
* @Column(type="string")
*/
public $updateableContentDefault;
}
62 changes: 61 additions & 1 deletion tests/Doctrine/Tests/ORM/Functional/InsertableUpdateableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,67 @@

namespace Doctrine\Tests\ORM\Functional;

class InsertableUpdateableTest
use Doctrine\ORM\Tools\ToolsException;
use Doctrine\Tests\Models\Upsertable\Insertable;
use Doctrine\Tests\Models\Upsertable\Updateable;
use Doctrine\Tests\OrmFunctionalTestCase;

class InsertableUpdateableTest extends OrmFunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();

try {
$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(Updateable::class),
$this->_em->getClassMetadata(Insertable::class),
]
);
} catch (ToolsException $e) {}
}

public function testNotInsertableIsFetchedFromDatabase(): void
{
$insertable = new Insertable();
$insertable->insertableContent = 'abcdefg';

$this->_em->persist($insertable);
$this->_em->flush();

// gets inserted from default value and fetches value from database
self::assertEquals('1234', $insertable->nonInsertableContent);

$insertable->nonInsertableContent = '5678';

$this->_em->flush();
$this->_em->clear();

$insertable = $this->_em->find(Insertable::class, $insertable->id);

// during UPDATE statement it is not ignored
self::assertEquals('5678', $insertable->nonInsertableContent);
}

public function testNotUpdateableIsFetched(): void
{
$updateable = new Updateable();
$updateable->updateableContent = 'foo';
$updateable->nonUpdateableContent = 'foo';

$this->_em->persist($updateable);
$this->_em->flush();

$updateable->updateableContent = 'bar';
$updateable->nonUpdateableContent = 'bar';

$this->_em->flush();
$this->_em->clear();

$updateable = $this->_em->find(Updateable::class, $updateable->id);

self::assertEquals('bar', $updateable->updateableContent);
self::assertEquals('foo', $updateable->nonUpdateableContent);
}
}

0 comments on commit 057d8ca

Please sign in to comment.