| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace App\Tests\Service\Mobyt;
- use App\Entity\Organization\Organization;
- use App\Entity\Organization\Parameters;
- use App\Repository\Organization\OrganizationRepository;
- use App\Service\Mobyt\MobytService;
- use App\Service\Mobyt\MobytUserStatusCreator;
- use PHPUnit\Framework\TestCase;
- class MobytUserStatusCreatorTest extends TestCase
- {
- private MobytService $mobytService;
- private OrganizationRepository $organizationRepository;
- public function setUp(): void {
- $this->mobytService = $this->getMockBuilder(MobytService::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->organizationRepository = $this->getMockBuilder(OrganizationRepository::class)
- ->disableOriginalConstructor()
- ->getMock();
- }
- public function testGetUserStatus(): void
- {
- $mobytUserStatusCreator = $this->getMockBuilder(MobytUserStatusCreator::class)
- ->setConstructorArgs([$this->mobytService, $this->organizationRepository])
- ->setMethodsExcept(['getUserStatus'])
- ->getMock();
- $organizationId = 123;
- $mobytLogin = 'foo';
- $mobytPassword = 'bar';
- $organization = $this->getMockBuilder(Organization::class)->getMock();
- $this->organizationRepository
- ->expects($this->once())
- ->method('find')
- ->with($organizationId)
- ->willReturn($organization);
- $parameters = $this->getMockBuilder(Parameters::class)->getMock();
- $organization->expects($this->once())->method('getParameters')->willReturn($parameters);
- $parameters->expects($this->once())->method('getUsernameSMS')->willReturn($mobytLogin);
- $parameters->expects($this->once())->method('getPasswordSMS')->willReturn($mobytPassword);
- $this->mobytService
- ->expects($this->once())
- ->method('getUserStatus')
- ->with($mobytLogin, $mobytPassword)
- ->willReturn(
- [
- 'money' => 33.0,
- 'sms' => [
- ['type' => 'N', 'quantity' => '300'],
- ['type' => 'EE', 'quantity' => '301'], // this type of sms should be ignored by the method
- ],
- 'email' => null
- ]
- );
- $mobytUserStatus = $mobytUserStatusCreator->getUserStatus($organizationId);
- $this->assertEquals(
- $mobytUserStatus->getMoney(),
- 33.0
- );
- // check that top-level amoung is taken in account, and only it
- $this->assertEquals(
- $mobytUserStatus->getAmount(),
- 300
- );
- }
- }
|