DolibarrAccountCreatorTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace App\Tests\Service\Dolibarr;
  3. use App\Service\Dolibarr\DolibarrAccountCreator;
  4. use App\Service\Dolibarr\DolibarrApiService;
  5. use PHPUnit\Framework\TestCase;
  6. class DolibarrAccountCreatorTest extends TestCase
  7. {
  8. private DolibarrApiService $dolibarrApiService;
  9. private DolibarrAccountCreator $dolibarrAccountCreator;
  10. public function setUp(): void {
  11. $this->dolibarrApiService = $this->getMockBuilder(DolibarrApiService::class)
  12. ->disableOriginalConstructor()
  13. ->getMock();
  14. $this->dolibarrAccountCreator = new DolibarrAccountCreator($this->dolibarrApiService);
  15. }
  16. private function getJsonContentFromFixture(string $filename): array {
  17. $filepath = dirname(__FILE__) . '/fixtures/' . $filename;
  18. return json_decode(file_get_contents($filepath), true);
  19. }
  20. public function testGetDolibarrAccount() {
  21. $this->dolibarrApiService
  22. ->expects($this->once())
  23. ->method('getSociety')
  24. ->with(1)
  25. ->willReturn(
  26. $this->getJsonContentFromFixture('thirdparty.json')[0]
  27. );
  28. $this->dolibarrApiService
  29. ->expects($this->once())
  30. ->method('getActiveContract')
  31. ->with(1726)
  32. ->willReturn(
  33. $this->getJsonContentFromFixture('contract.json')[0]
  34. );
  35. $this->dolibarrApiService
  36. ->expects($this->once())
  37. ->method('getBills')
  38. ->with(1726)
  39. ->willReturn(
  40. $this->getJsonContentFromFixture('bills.json')
  41. );
  42. $dolibarrAccount = $this->dolibarrAccountCreator->getDolibarrAccount(1);
  43. $this->assertEquals(
  44. $dolibarrAccount->getClientNumber(),
  45. "001855"
  46. );
  47. $this->assertEquals(
  48. $dolibarrAccount->getContract()->getRef(),
  49. "0000037-C1_1"
  50. );
  51. $this->assertEquals(
  52. $dolibarrAccount->getContract()->getLines()[0]->getServiceRef(),
  53. "ABO_ART_PRE_CMF"
  54. );
  55. $this->assertEquals(
  56. $dolibarrAccount->getBills()[2]->getRef(),
  57. "FA2105-03135"
  58. );
  59. }
  60. public function testCreateDolibarrAccount() {
  61. $accountData = $this->getJsonContentFromFixture('thirdparty.json')[0];
  62. $dolibarrAccount = $this->dolibarrAccountCreator->createDolibarrAccount(1, $accountData);
  63. $this->assertEquals(
  64. $dolibarrAccount->getClientNumber(),
  65. "001855"
  66. );
  67. }
  68. public function testCreateDolibarrContract() {
  69. $contractData = $this->getJsonContentFromFixture('contract.json')[0];
  70. $dolibarrContract = $this->dolibarrAccountCreator->createDolibarrContract($contractData);
  71. $this->assertEquals(
  72. $dolibarrContract->getRef(),
  73. "0000037-C1_1"
  74. );
  75. $this->assertEquals(
  76. $dolibarrContract->getLines()[0]->getServiceRef(),
  77. "ABO_ART_PRE_CMF"
  78. );
  79. }
  80. public function testCreateDolibarrContractLine() {
  81. $lineData = $this->getJsonContentFromFixture('contract.json')[0]['lines'][0];
  82. $dolibarrContractLine = $this->dolibarrAccountCreator->createDolibarrContractLine($lineData);
  83. $this->assertEquals(
  84. $dolibarrContractLine->getServiceRef(),
  85. "ABO_ART_PRE_CMF"
  86. );
  87. }
  88. public function testCreateDolibarrBill() {
  89. $billData = $this->getJsonContentFromFixture('bills.json')[0];
  90. $dolibarrBill = $this->dolibarrAccountCreator->createDolibarrBill($billData);
  91. $this->assertEquals(
  92. $dolibarrBill->getRef(),
  93. "AV2106-02992"
  94. );
  95. }
  96. }