<commit_before><?php
namespace Neos\Flow\Tests\Functional\Persistence\Doctrine;

use Neos\Flow\Persistence\Doctrine\PersistenceManager;
use Neos\Flow\Persistence\Doctrine\Query;
use Neos\Flow\Tests\Functional\Persistence\Fixtures\TestEntity;
use Neos\Flow\Tests\Functional\Persistence\Fixtures\TestValueObject;
use Neos\Flow\Tests\FunctionalTestCase;

class ValueObjectTest extends FunctionalTestCase
{
    /**
     * @var boolean
     */
    protected static $testablePersistenceEnabled = true;

    /**
     * @return void
     */
    protected function setUp(): void
    {
        parent::setUp();
        if (!$this->persistenceManager instanceof PersistenceManager) {
            $this->markTestSkipped('Doctrine persistence is not enabled');
        }
    }

    public function testValueObjectDeduplication()
    {
        for ($i = 0; $i < 2; $i++) {
            $testEntity = new TestEntity();
            $testEntity->setRelatedValueObject(new TestValueObject('deduplicate'));
            $this->persistenceManager->add($testEntity);
            $this->persistenceManager->persistAll();
            $this->persistenceManager->update($testEntity);
            $this->persistenceManager->persistAll();
        }
        $query = new Query(TestEntity::class);
        self::assertEquals(2, $query->count());
    }
}<commit_msg>TASK: Improving test documentation by explaining why it is there<commit_after><?php
namespace Neos\Flow\Tests\Functional\Persistence\Doctrine;

use Neos\Flow\Persistence\Doctrine\PersistenceManager;
use Neos\Flow\Persistence\Doctrine\Query;
use Neos\Flow\Tests\Functional\Persistence\Fixtures\TestEntity;
use Neos\Flow\Tests\Functional\Persistence\Fixtures\TestValueObject;
use Neos\Flow\Tests\FunctionalTestCase;

class ValueObjectTest extends FunctionalTestCase
{
    /**
     * @var boolean
     */
    protected static $testablePersistenceEnabled = true;

    /**
     * @return void
     */
    protected function setUp(): void
    {
        parent::setUp();
        if (!$this->persistenceManager instanceof PersistenceManager) {
            $this->markTestSkipped('Doctrine persistence is not enabled');
        }
    }

    /**
     * This test is here to beware us from regressing again.
     *
     * If you update an object, which holds a relation to ValueObjects the deduplication listener breaks Doctrines
     * internal state of the UnitOfWork so one cannot persist again, depending on prior actions in the same request.
     *
     * The exception thrown is an ORMInvalidArgumentException with message:
     * "A managed+dirty entity test can not be scheduled for insertion."
     *
     * @test
     */
    public function valueObjectsGetDeduplicatedAndCanBePersisted()
    {
        for ($i = 0; $i < 2; $i++) {
            $testEntity = new TestEntity();
            $testEntity->setRelatedValueObject(new TestValueObject('deduplicate'));
            $this->persistenceManager->add($testEntity);
            $this->persistenceManager->persistAll();
            $this->persistenceManager->update($testEntity);
            $this->persistenceManager->persistAll();
        }
        $query = new Query(TestEntity::class);
        self::assertEquals(2, $query->count(), 'It should be exactly two TestEntities');
    }
}
{'fraction_non_alphanumeric': 0.11138310893512852, 'fraction_numerical': 0.0018359853121175031, 'mean_word_length': 3.0811485642946317, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3750927', 'n_tokens_mistral': 891, 'n_tokens_neox': 888, 'n_words': 203}