|
@@ -0,0 +1,118 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+
|
|
|
|
|
+namespace App\Tests\Service\Dolibarr;
|
|
|
|
|
+
|
|
|
|
|
+use App\Service\Dolibarr\DolibarrAccountCreator;
|
|
|
|
|
+use App\Service\Dolibarr\DolibarrService;
|
|
|
|
|
+use PHPUnit\Framework\TestCase;
|
|
|
|
|
+
|
|
|
|
|
+class DolibarrAccountCreatorTest extends TestCase
|
|
|
|
|
+{
|
|
|
|
|
+ private DolibarrService $dolibarrService;
|
|
|
|
|
+ private DolibarrAccountCreator $dolibarrAccountCreator;
|
|
|
|
|
+
|
|
|
|
|
+ public function setUp(): void {
|
|
|
|
|
+ $this->dolibarrService = $this->getMockBuilder(DolibarrService::class)
|
|
|
|
|
+ ->disableOriginalConstructor()
|
|
|
|
|
+ ->getMock();
|
|
|
|
|
+
|
|
|
|
|
+ $this->dolibarrAccountCreator = new DolibarrAccountCreator($this->dolibarrService);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function getJsonContentFromFixture(string $filename): array {
|
|
|
|
|
+ $filepath = dirname(__FILE__) . '/fixtures/' . $filename;
|
|
|
|
|
+ return json_decode(file_get_contents($filepath), true);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function testGetDolibarrAccount() {
|
|
|
|
|
+ $this->dolibarrService
|
|
|
|
|
+ ->expects($this->once())
|
|
|
|
|
+ ->method('getSociety')
|
|
|
|
|
+ ->with(1)
|
|
|
|
|
+ ->willReturn(
|
|
|
|
|
+ $this->getJsonContentFromFixture('thirdparty.json')[0]
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ $this->dolibarrService
|
|
|
|
|
+ ->expects($this->once())
|
|
|
|
|
+ ->method('getActiveContract')
|
|
|
|
|
+ ->with(1726)
|
|
|
|
|
+ ->willReturn(
|
|
|
|
|
+ $this->getJsonContentFromFixture('contract.json')[0]
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ $this->dolibarrService
|
|
|
|
|
+ ->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"
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|