client = $this->getMockBuilder(HttpClientInterface::class) ->disableOriginalConstructor() ->getMock(); $this->dolibarrService = new DolibarrService($this->client); } private function getContentFromFixture(string $filename): string { $filepath = dirname(__FILE__) . '/fixtures/' . $filename; return file_get_contents($filepath); } /** * @see DolibarrService::getSociety() */ public function testGetSociety(): void { $responseContent = $this->getContentFromFixture('thirdparty.json'); $response = $this->getMockBuilder(ResponseInterface::class) ->disableOriginalConstructor() ->getMock(); $response->method('getContent')->willReturn($responseContent); $this->client ->expects($this->once()) ->method('request') ->with("GET", "thirdparties?sqlfilters=ref_int%3D1") ->willReturn($response); $data = $this->dolibarrService->getSociety(1); $this->assertEquals( $data['id'], 1726 ); } /** * @see DolibarrService::getActiveContract() */ public function testGetActiveContract(): void { $responseContent = $this->getContentFromFixture('contract.json'); $response = $this->getMockBuilder(ResponseInterface::class) ->disableOriginalConstructor() ->getMock(); $response->method('getContent')->willReturn($responseContent); $this->client ->expects($this->once()) ->method('request') ->with("GET", "contracts?limit=1&sqlfilters=statut%3D1&thirdparty_ids=1") ->willReturn($response); $this->assertEquals( $this->dolibarrService->getActiveContract(1)['socid'], 43 ); } /** * @see DolibarrService::getBills() */ public function testGetBills(): void { $responseContent = $this->getContentFromFixture('bills.json'); $response = $this->getMockBuilder(ResponseInterface::class) ->disableOriginalConstructor() ->getMock(); $response->method('getContent')->willReturn($responseContent); $this->client ->expects($this->once()) ->method('request') ->with("GET", "invoices?sortfield=datef&sortorder=DESC&limit=5&sqlfilters=fk_soc%3D1") ->willReturn($response); $this->assertEquals( $this->dolibarrService->getBills(1)[2]['socid'], 284 ); } }