Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: Git Master
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      Ubuntu 12.04

      Description

      After reading DDC-1896 and DDC-136, I'm not exactly sure if this qualifies as a bug, but anyways, here's my code to reproduce:

          public function test_hash_collision()
          {
              $counter = 0;
              do
              {
                  $object = $this->create_object();
                  $counter++;
                  if ($counter > 1000)
                  {
                      //mark as skipped ? (I never hit this on PHP 5.3 at least)
                      break;
                  }
              }
              while ($object === false);
      
              // This fails with "Failed asserting that 1 matches expected 2."
              $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($object));
          }
      
          private function create_object()
          {
              static $hashes = array();
              $phone = new CmsPhonenumber();
              $phone->phonenumber = "1234";
              $hash = spl_object_hash($phone);
              $this->_em->persist($phone);
      
              if (!array_key_exists($hash, $hashes))
              {
                  $hashes[$hash] = true;
                  $this->_em->flush($phone);
                  $this->_em->remove($phone);
                  $this->_em->flush($phone);
                  return false;
              }
              // Bingo! We have a new object with a recycled hash
              return $phone;
          }
      

        Activity

        Hide
        Marco Pivetta added a comment -

        Are you able to reproduce the test also without statics?

        Show
        Marco Pivetta added a comment - Are you able to reproduce the test also without statics?
        Hide
        flack added a comment -

        Yes, if I switch to $this->hashes (private $hashes = array()), the result is the same

        Show
        flack added a comment - Yes, if I switch to $this->hashes (private $hashes = array()), the result is the same
        Hide
        flack added a comment -

        Here's the complete test without statics & according to Doctrine CS (AFAICT):

        <?php
        
        namespace Doctrine\Tests\ORM\Functional\Ticket;
        
        use Doctrine\Tests\Models\CMS\CmsPhonenumber;
        
        require_once __DIR__ . '/../../../TestInit.php';
        
        /**
         * @group DDC-2785
         */
        class DDC2785Test extends \Doctrine\Tests\OrmFunctionalTestCase
        {
            public function setUp()
            {
                $this->useModelSet('cms');
                parent::setUp();
            }
        
            private $hashes = array();
        
            public function testIssue()
            {
                $counter = 0;
                do
                {
                    $object = $this->createObject();
                    $counter++;
                    if ($counter > 1000)
                    {
                        //mark as skipped ? (I never hit this on PHP 5.3 at least)
                        break;
                    }
                }
                while ($object === false);
        
                $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($object));
            }
        
            private function createObject()
            {
                $phone = new CmsPhonenumber();
                $phone->phonenumber = "1234";
                $hash = spl_object_hash($phone);
                $this->_em->persist($phone);
        
                if (!array_key_exists($hash, $this->hashes))
                {
                    $this->hashes[$hash] = true;
                    $this->_em->flush();
                    $this->_em->remove($phone);
                    $this->_em->flush();
                    return false;
                }
        
                return $phone;
            }
        }
        

        I can try and send this as a pull request, if it helps

        Show
        flack added a comment - Here's the complete test without statics & according to Doctrine CS (AFAICT): <?php namespace Doctrine\Tests\ORM\Functional\Ticket; use Doctrine\Tests\Models\CMS\CmsPhonenumber; require_once __DIR__ . '/../../../TestInit.php'; /** * @group DDC-2785 */ class DDC2785Test extends \Doctrine\Tests\OrmFunctionalTestCase { public function setUp() { $ this ->useModelSet('cms'); parent::setUp(); } private $hashes = array(); public function testIssue() { $counter = 0; do { $object = $ this ->createObject(); $counter++; if ($counter > 1000) { //mark as skipped ? (I never hit this on PHP 5.3 at least) break ; } } while ($object === false ); $ this ->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_NEW, $ this ->_em->getUnitOfWork()->getEntityState($object)); } private function createObject() { $phone = new CmsPhonenumber(); $phone->phonenumber = "1234" ; $hash = spl_object_hash($phone); $ this ->_em->persist($phone); if (!array_key_exists($hash, $ this ->hashes)) { $ this ->hashes[$hash] = true ; $ this ->_em->flush(); $ this ->_em->remove($phone); $ this ->_em->flush(); return false ; } return $phone; } } I can try and send this as a pull request, if it helps

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            flack
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: