associateWithCompany() public method

public associateWithCompany ( integer $dealId, integer | int[] $companyIds ) : mixed
$dealId integer
$companyIds integer | int[]
return mixed
Example #1
0
 /**
  * @group now
  */
 public function associateWithCompany()
 {
     $dealId = $this->createDeal()->dealId;
     $firstCompanyId = $this->createCompany();
     $secondCompanyId = $this->createCompany();
     $thirdCompanyId = $this->createCompany();
     $response = $this->deals->associateWithCompany($dealId, [$firstCompanyId, $secondCompanyId, $thirdCompanyId]);
     $this->assertSame(204, $response->getStatusCode());
     //Check what was associated
     $response = $this->deals->getById($dealId);
     $associatedCompanies = $response->associations->associatedCompanyIds;
     $expectedAssociatedCompanies = [$firstCompanyId, $secondCompanyId, $thirdCompanyId];
     //sorting as order is not predicatable
     sort($associatedCompanies);
     sort($expectedAssociatedCompanies);
     $this->assertEquals($expectedAssociatedCompanies, $associatedCompanies);
     //Now disassociate
     $response = $this->deals->disassociateFromCompany($dealId, [$firstCompanyId, $thirdCompanyId]);
     $this->assertSame(204, $response->getStatusCode());
     //Ensure that only one associated company left
     $response = $this->deals->getById($dealId);
     $this->assertSame([$secondCompanyId], $response->associations->associatedCompanyIds);
 }