Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[DDC-2984] Provide TestCase to reproduce bug #961

Closed
wants to merge 1 commit into from

3 participants

@codeliner

No description provided.

@doctrinebot
Collaborator

Hello,

thank you for creating this pull request. I have automatically opened an issue
on our Jira Bug Tracker for you. See the issue link:

http://www.doctrine-project.org/jira/browse/DDC-2998

We use Jira to track the state of pull requests and the versions they got
included in.

@guilhermeblanco

As of 5ce6dab this issue was fixed.

@guilhermeblanco

@beberlei merge in 2.4 and 2.3 (if possible).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 24, 2014
  1. @codeliner
This page is out of date. Refresh to see the latest.
View
59 tests/Doctrine/Tests/Models/DDC2984/DDC2984DomainUserId.php
@@ -0,0 +1,59 @@
+<?php
+/*
+ * This file is part of the codeliner/doctrine2.
+ * (c) Alexander Miertsch <kontakt@codeliner.ws>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ *
+ * Date: 24.02.14 - 18:32
+ */
+
+namespace Doctrine\Tests\Models\DDC2984;
+
+/**
+ * Class DDC2984DomainUserId ValueObject
+ *
+ * @package Doctrine\Tests\Models\DDC2372
+ * @author Alexander Miertsch <kontakt@codeliner.ws>
+ */
+class DDC2984DomainUserId
+{
+ /**
+ * @var string
+ */
+ private $userIdString;
+
+ /**
+ * @param string $aUserIdString
+ */
+ public function __construct($aUserIdString)
+ {
+ $this->userIdString = $aUserIdString;
+ }
+
+ /**
+ * @return string
+ */
+ public function toString()
+ {
+ return $this->userIdString;
+ }
+
+ /**
+ * @return string
+ */
+ public function __toString()
+ {
+ return $this->toString();
+ }
+
+ /**
+ * @param DDC2984DomainUserId $other
+ * @return bool
+ */
+ public function sameValueAs(DDC2984DomainUserId $other)
+ {
+ return $this->toString() === $other->toString();
+ }
+}
View
58 tests/Doctrine/Tests/Models/DDC2984/DDC2984User.php
@@ -0,0 +1,58 @@
+<?php
+
+namespace Doctrine\Tests\Models\DDC2984;
+
+use Doctrine\ORM\Mapping as ORM;
+
+/** @ORM\Entity @ORM\Table(name="users") */
+class DDC2984User
+{
+ /**
+ * @ORM\Id @ORM\Column(type="ddc2984_domain_user_id")
+ * @ORM\GeneratedValue(strategy="NONE")
+ *
+ * @var DDC2984DomainUserId
+ */
+ private $userId;
+
+ /** @ORM\Column(type="string", length=50) */
+ private $name;
+
+ public function __construct(DDC2984DomainUserId $aUserId)
+ {
+ $this->userId = $aUserId;
+ }
+
+ /**
+ * @return DDC2984DomainUserId
+ */
+ public function userId()
+ {
+ return $this->userId;
+ }
+
+ /**
+ * @return string
+ */
+ public function name()
+ {
+ return $this->name;
+ }
+
+ /**
+ * @param string $name
+ */
+ public function applyName($name)
+ {
+ $this->name = $name;
+ }
+
+ /**
+ * @param DDC2984User $other
+ * @return bool
+ */
+ public function sameIdentityAs(DDC2984User $other)
+ {
+ return $this->userId()->sameValueAs($other->userId());
+ }
+}
View
61 tests/Doctrine/Tests/Models/DDC2984/DDC2984UserIdCustomDbalType.php
@@ -0,0 +1,61 @@
+<?php
+/*
+ * This file is part of the codeliner/doctrine2.
+ * (c) Alexander Miertsch <kontakt@codeliner.ws>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ *
+ * Date: 24.02.14 - 18:39
+ */
+
+namespace Doctrine\Tests\Models\DDC2984;
+
+use Doctrine\DBAL\Platforms\AbstractPlatform;
+use Doctrine\DBAL\Types\ConversionException;
+use Doctrine\DBAL\Types\StringType;
+
+/**
+ * Class DDC2984UserIdCustomDbalType
+ *
+ * @package Doctrine\Tests\Models\DDC2984
+ * @author Alexander Miertsch <kontakt@codeliner.ws>
+ */
+class DDC2984UserIdCustomDbalType extends StringType
+{
+ public function getName()
+ {
+ return 'ddc2984_domain_user_id';
+ }
+ /**
+ * {@inheritDoc}
+ */
+ public function convertToPHPValue($value, AbstractPlatform $platform)
+ {
+ if (empty($value)) {
+ return null;
+ }
+
+ return new DDC2984DomainUserId($value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function convertToDatabaseValue($value, AbstractPlatform $platform)
+ {
+ if (empty($value)) {
+ return null;
+ }
+
+ if (is_string($value)) {
+ return $value;
+ }
+
+ if (!$value instanceof DDC2984DomainUserId) {
+ throw ConversionException::conversionFailed($value, $this->getName());
+ }
+
+ return $value->toString();
+ }
+}
View
60 tests/Doctrine/Tests/ORM/UnitOfWorkTest.php
@@ -2,11 +2,14 @@
namespace Doctrine\Tests\ORM;
+use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\UnitOfWork;
use Doctrine\Tests\Mocks\ConnectionMock;
use Doctrine\Tests\Mocks\EntityManagerMock;
use Doctrine\Tests\Mocks\UnitOfWorkMock;
use Doctrine\Tests\Mocks\EntityPersisterMock;
+use Doctrine\Tests\Models\DDC2984\DDC2984DomainUserId;
+use Doctrine\Tests\Models\DDC2984\DDC2984User;
use Doctrine\Tests\Models\Forum\ForumUser;
use Doctrine\Tests\Models\Forum\ForumAvatar;
@@ -229,6 +232,63 @@ public function testLockWithoutEntityThrowsException()
$this->setExpectedException('InvalidArgumentException');
$this->_unitOfWork->lock(null, null, null);
}
+
+ /**
+ * @group DDC-2984
+ */
+ public function testIllegalOffsetTypeWarningWhenUsingCustomDBALTypeAsIdentifier()
+ {
+ if(!Type::hasType('ddc2984_domain_user_id')) {
+ Type::addType('ddc2984_domain_user_id', 'Doctrine\Tests\Models\DDC2984\DDC2984UserIdCustomDbalType');
+ }
+
+ //sorry, could not reproduce the bug with all the mocked classes... so I use my own test setup for demonstration
+ $config = new \Doctrine\ORM\Configuration();
+
+ $config->setAutoGenerateProxyClasses(true);
+ $config->setProxyDir(\sys_get_temp_dir());
+ $config->setProxyNamespace(get_class($this) . '\Entities');
+ $config->setMetadataDriverImpl(
+ new \Doctrine\ORM\Mapping\Driver\AnnotationDriver(
+ new \Doctrine\Common\Annotations\IndexedReader(
+ new \Doctrine\Common\Annotations\AnnotationReader()
+ )
+ )
+ );
+
+ $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
+ $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
+
+ $em = \Doctrine\ORM\EntityManager::create(array(
+ 'driver' => 'pdo_sqlite',
+ 'memory' => true
+ ), $config);
+
+ $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em);
+
+ $schema = $em->getClassMetadata("Doctrine\Tests\Models\DDC2984\DDC2984User");
+ $schemaTool->createSchema(array($schema));
+
+ //ok, lets start reproducing the bug
+ $user = new DDC2984User(new DDC2984DomainUserId('unique_id_within_a_vo'));
+ $user->applyName('Alex');
+
+ $em->persist($user);
+ $em->flush($user);
+
+ $sameUser = $em->getRepository("Doctrine\Tests\Models\DDC2984\DDC2984User")->find(new DDC2984DomainUserId('unique_id_within_a_vo'));
+
+ //Until know, everything works as expected
+ $this->assertTrue($user->sameIdentityAs($sameUser));
+
+ $em->clear();
+
+ //After clearing the identity map, the UnitOfWork produces the warning described in DDC-2984
+ $equalUser = $em->getRepository("Doctrine\Tests\Models\DDC2984\DDC2984User")->find(new DDC2984DomainUserId('unique_id_within_a_vo'));
+
+ $this->assertNotSame($user, $equalUser);
+ $this->assertTrue($user->sameIdentityAs($equalUser));
+ }
}
/**
Something went wrong with that request. Please try again.