MobytUserStatusCreatorTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace App\Tests\Service\Mobyt;
  3. use App\Entity\Organization\Organization;
  4. use App\Entity\Organization\Parameters;
  5. use App\Repository\Organization\OrganizationRepository;
  6. use App\Service\Mobyt\MobytService;
  7. use App\Service\Mobyt\MobytUserStatusCreator;
  8. use PHPUnit\Framework\TestCase;
  9. class MobytUserStatusCreatorTest extends TestCase
  10. {
  11. private MobytService $mobytService;
  12. private OrganizationRepository $organizationRepository;
  13. private MobytUserStatusCreator $mobytUserStatusCreator;
  14. public function setUp(): void {
  15. $this->mobytService = $this->getMockBuilder(MobytService::class)
  16. ->disableOriginalConstructor()
  17. ->getMock();
  18. $this->organizationRepository = $this->getMockBuilder(OrganizationRepository::class)
  19. ->disableOriginalConstructor()
  20. ->getMock();
  21. $this->mobytUserStatusCreator = new MobytUserStatusCreator(
  22. $this->mobytService,
  23. $this->organizationRepository
  24. );
  25. }
  26. private function getJsonContentFromFixture(string $filename): array {
  27. $filepath = dirname(__FILE__) . '/fixtures/' . $filename;
  28. return json_decode(file_get_contents($filepath), true);
  29. }
  30. public function testGetUserStatus() {
  31. $parameters = $this->getMockBuilder(Parameters::class)->getMock();
  32. $parameters->expects($this->once())->method('getUsernameSMS')->willReturn('user');
  33. $parameters->expects($this->once())->method('getPasswordSMS')->willReturn('pwd');
  34. $organization = $this->getMockBuilder(Organization::class)->getMock();
  35. $organization->expects($this->once())->method('getParameters')->willReturn($parameters);
  36. $this->organizationRepository
  37. ->expects($this->once())
  38. ->method('find')
  39. ->with(1)
  40. ->willReturn($organization);
  41. $this->mobytService
  42. ->expects($this->once())
  43. ->method('getUserStatus')
  44. ->with(1, 'user', 'pwd')
  45. ->willReturn(
  46. $this->getJsonContentFromFixture('user_status.json')
  47. );
  48. $mobytUserStatus = $this->mobytUserStatusCreator->getUserStatus(1);
  49. $this->assertEquals(
  50. $mobytUserStatus->getMoney(),
  51. 33.0
  52. );
  53. // check that top-level amoung is taken in account, and only it
  54. $this->assertEquals(
  55. $mobytUserStatus->getAmount(),
  56. 300
  57. );
  58. }
  59. }