| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace App\Tests\Service\Dolibarr;
- use App\Service\Dolibarr\DolibarrService;
- use PHPUnit\Framework\TestCase;
- use Symfony\Contracts\HttpClient\HttpClientInterface;
- use Symfony\Contracts\HttpClient\ResponseInterface;
- class DolibarrServiceTest extends TestCase
- {
- private HttpClientInterface $client;
- private DolibarrService $dolibarrService;
- public function setUp(): void {
- $this->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
- );
- }
- }
|