| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace App\Tests\Service\Dolibarr;
- use App\Service\Dolibarr\DolibarrAccountCreator;
- use App\Service\Dolibarr\DolibarrApiService;
- use PHPUnit\Framework\TestCase;
- class DolibarrAccountCreatorTest extends TestCase
- {
- private DolibarrApiService $dolibarrApiService;
- private DolibarrAccountCreator $dolibarrAccountCreator;
- public function setUp(): void {
- $this->dolibarrApiService = $this->getMockBuilder(DolibarrApiService::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->dolibarrAccountCreator = new DolibarrAccountCreator($this->dolibarrApiService);
- }
- private function getJsonContentFromFixture(string $filename): array {
- $filepath = dirname(__FILE__) . '/fixtures/' . $filename;
- return json_decode(file_get_contents($filepath), true);
- }
- public function testGetDolibarrAccount() {
- $this->dolibarrApiService
- ->expects($this->once())
- ->method('getSociety')
- ->with(1)
- ->willReturn(
- $this->getJsonContentFromFixture('thirdparty.json')[0]
- );
- $this->dolibarrApiService
- ->expects($this->once())
- ->method('getActiveContract')
- ->with(1726)
- ->willReturn(
- $this->getJsonContentFromFixture('contract.json')[0]
- );
- $this->dolibarrApiService
- ->expects($this->once())
- ->method('getBills')
- ->with(1726)
- ->willReturn(
- $this->getJsonContentFromFixture('bills.json')
- );
- $dolibarrAccount = $this->dolibarrAccountCreator->getDolibarrAccount(1);
- $this->assertEquals(
- $dolibarrAccount->getClientNumber(),
- "001855"
- );
- $this->assertEquals(
- $dolibarrAccount->getContract()->getRef(),
- "0000037-C1_1"
- );
- $this->assertEquals(
- $dolibarrAccount->getContract()->getLines()[0]->getServiceRef(),
- "ABO_ART_PRE_CMF"
- );
- $this->assertEquals(
- $dolibarrAccount->getBills()[2]->getRef(),
- "FA2105-03135"
- );
- }
- public function testCreateDolibarrAccount() {
- $accountData = $this->getJsonContentFromFixture('thirdparty.json')[0];
- $dolibarrAccount = $this->dolibarrAccountCreator->createDolibarrAccount(1, $accountData);
- $this->assertEquals(
- $dolibarrAccount->getClientNumber(),
- "001855"
- );
- }
- public function testCreateDolibarrContract() {
- $contractData = $this->getJsonContentFromFixture('contract.json')[0];
- $dolibarrContract = $this->dolibarrAccountCreator->createDolibarrContract($contractData);
- $this->assertEquals(
- $dolibarrContract->getRef(),
- "0000037-C1_1"
- );
- $this->assertEquals(
- $dolibarrContract->getLines()[0]->getServiceRef(),
- "ABO_ART_PRE_CMF"
- );
- }
- public function testCreateDolibarrContractLine() {
- $lineData = $this->getJsonContentFromFixture('contract.json')[0]['lines'][0];
- $dolibarrContractLine = $this->dolibarrAccountCreator->createDolibarrContractLine($lineData);
- $this->assertEquals(
- $dolibarrContractLine->getServiceRef(),
- "ABO_ART_PRE_CMF"
- );
- }
- public function testCreateDolibarrBill() {
- $billData = $this->getJsonContentFromFixture('bills.json')[0];
- $dolibarrBill = $this->dolibarrAccountCreator->createDolibarrBill($billData);
- $this->assertEquals(
- $dolibarrBill->getRef(),
- "AV2106-02992"
- );
- }
- }
|