Programming Language PHP

Namespace Oro\Bundle\SalesBundle\Entity

Class Opportunity

Method/Function setCustomerAssociation

Total Examples 1

1 code examples of PHP Oro\Bundle\SalesBundle\Entity\Opportunity::setCustomerAssociation extracted from open source projects

Was this example useful?
0
                                                    /**
     * @depends testChangeStatusAffectsLifetime
     */
    public function testCustomerChangeShouldUpdateBothCustomersIfValuable(Opportunity $opportunity): Opportunity
    {
        $em = $this->getEntityManager();
        /** @var B2bCustomer $b2bCustomer */
        $b2bCustomer = $opportunity->getCustomerAssociation()->getTarget();
        $this->assertEquals(100, $b2bCustomer->getLifetime());
        $newCustomer = new B2bCustomer();
        $newCustomer->setName(uniqid('name'));
        $account = $this->getReference('default_account');
        $newCustomer->setAccount($account);
        $em->persist($newCustomer);
        $em->flush();

        $this->assertEquals(0, $newCustomer->getLifetime());

        $accountCustomer = $this->getAccountCustomerManager()->getAccountCustomerByTarget($newCustomer);
        $opportunity->setCustomerAssociation($accountCustomer);
        $em->persist($opportunity);
        $em->flush();
        $em->refresh($b2bCustomer);
        $em->refresh($newCustomer);

        $this->assertEquals(0, $b2bCustomer->getLifetime());
        $this->assertEquals(100, $newCustomer->getLifetime());

        return $opportunity;
    }