Пример #1
0
 public function setType(CustomerType $type)
 {
     $this->type = $type;
     if (!$type->getCustomers()->contains($this)) {
         $type->addCustomer($this);
     }
 }
Пример #2
0
 /**
  * This is a test case for issue #1209
  * @test
  */
 public function shouldRollbackPositionAfterExceptionOnDelete()
 {
     $repo = $this->em->getRepository(self::CUSTOMER_TYPE);
     $customerType1 = new CustomerType();
     $customerType1->setName("CustomerType1");
     $this->em->persist($customerType1);
     $customerType2 = new CustomerType();
     $customerType2->setName("CustomerType2");
     $this->em->persist($customerType2);
     $customerType3 = new CustomerType();
     $customerType3->setName("CustomerType3");
     $this->em->persist($customerType3);
     $customer = new Customer();
     $customer->setName("Customer");
     $customer->setType($customerType2);
     $this->em->persist($customer);
     $this->em->flush();
     try {
         // now delete the second customer type, which should fail
         // because of the foreign key reference
         $this->em->remove($customerType2);
         $this->em->flush();
         $this->fail('Foreign key constraint violation exception not thrown.');
     } catch (ForeignKeyConstraintViolationException $e) {
         $customerTypes = $repo->findAll();
         $this->assertCount(3, $customerTypes);
         $this->assertEquals(0, $customerTypes[0]->getPosition(), 'The sorting position has not been rolled back.');
         $this->assertEquals(1, $customerTypes[1]->getPosition(), 'The sorting position has not been rolled back.');
         $this->assertEquals(2, $customerTypes[2]->getPosition(), 'The sorting position has not been rolled back.');
     }
 }