/**
  * Sets up the tests
  */
 public function setUp()
 {
     $builder = $this->createMock(EntityBuilder::class);
     $idAccessorRegistry = new IdAccessorRegistry();
     $idAccessorRegistry->registerIdAccessors(User::class, function ($user) {
         /** @var User $user */
         return $user->getId();
     }, function ($user, $id) {
         /** @var User $user */
         $user->setId($id);
     });
     $this->entityRegistry = new EntityRegistry($builder);
     /*
      * The Ids are purposely unique so that we can identify them as such without having to first insert them to
      * assign unique Ids
      * They are also purposely set to 724, 1987, and 345 so that they won't potentially overlap with any default
      * values set to the Ids
      */
     $this->entity1 = new User(724, "foo");
     $this->entity2 = new User(1987, "bar");
     $this->entity3 = new User(345, "baz");
     $this->entity1HashId = $this->entityRegistry->getObjectHashId($this->entity1);
     $this->entity2HashId = $this->entityRegistry->getObjectHashId($this->entity2);
     $this->entity3HashId = $this->entityRegistry->getObjectHashId($this->entity3);
 }
예제 #2
0
 /**
  * Tests an unsuccessful commit
  */
 public function testUnsuccessfulCommit()
 {
     $exceptionThrown = false;
     $idAccessorRegistry = new IdAccessorRegistry();
     $idAccessorRegistry->registerIdAccessors(User::class, function (User $user) {
         return $user->getId();
     }, function (User $user, $id) {
         $user->setId($id);
     });
     try {
         $connection = null;
         $this->unitOfWork = new UnitOfWork($this->entityRegistry, $connection);
         $this->entity1 = new User(1, "foo");
         $this->entity2 = new User(2, "bar");
         $className = $this->entityRegistry->getClassName($this->entity1);
         $this->unitOfWork->registerDataMapper($className, $this->dataMapper);
         $this->unitOfWork->scheduleForInsertion($this->entity1);
         $this->unitOfWork->scheduleForInsertion($this->entity2);
         $this->unitOfWork->commit();
     } catch (OrmException $e) {
         $exceptionThrown = true;
     }
     $this->assertTrue($exceptionThrown);
     $this->assertEquals(1, $this->entity1->getId());
     $this->assertEquals(2, $this->entity2->getId());
 }