MobytUserStatusCreatorTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. public function setUp(): void {
  14. $this->mobytService = $this->getMockBuilder(MobytService::class)
  15. ->disableOriginalConstructor()
  16. ->getMock();
  17. $this->organizationRepository = $this->getMockBuilder(OrganizationRepository::class)
  18. ->disableOriginalConstructor()
  19. ->getMock();
  20. }
  21. public function testGetUserStatus(): void
  22. {
  23. $mobytUserStatusCreator = $this->getMockBuilder(MobytUserStatusCreator::class)
  24. ->setConstructorArgs([$this->mobytService, $this->organizationRepository])
  25. ->setMethodsExcept(['getUserStatus'])
  26. ->getMock();
  27. $organizationId = 123;
  28. $mobytLogin = 'foo';
  29. $mobytPassword = 'bar';
  30. $organization = $this->getMockBuilder(Organization::class)->getMock();
  31. $this->organizationRepository
  32. ->expects($this->once())
  33. ->method('find')
  34. ->with($organizationId)
  35. ->willReturn($organization);
  36. $parameters = $this->getMockBuilder(Parameters::class)->getMock();
  37. $organization->expects($this->once())->method('getParameters')->willReturn($parameters);
  38. $parameters->expects($this->once())->method('getUsernameSMS')->willReturn($mobytLogin);
  39. $parameters->expects($this->once())->method('getPasswordSMS')->willReturn($mobytPassword);
  40. $this->mobytService
  41. ->expects($this->once())
  42. ->method('getUserStatus')
  43. ->with($mobytLogin, $mobytPassword)
  44. ->willReturn(
  45. [
  46. 'money' => 33.0,
  47. 'sms' => [
  48. ['type' => 'N', 'quantity' => '300'],
  49. ['type' => 'EE', 'quantity' => '301'], // this type of sms should be ignored by the method
  50. ],
  51. 'email' => null
  52. ]
  53. );
  54. $mobytUserStatus = $mobytUserStatusCreator->getUserStatus($organizationId);
  55. $this->assertEquals(
  56. $mobytUserStatus->getMoney(),
  57. 33.0
  58. );
  59. // check that top-level amoung is taken in account, and only it
  60. $this->assertEquals(
  61. $mobytUserStatus->getAmount(),
  62. 300
  63. );
  64. }
  65. }