|
|
@@ -0,0 +1,73 @@
|
|
|
+<?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;
|
|
|
+ private MobytUserStatusCreator $mobytUserStatusCreator;
|
|
|
+
|
|
|
+ public function setUp(): void {
|
|
|
+ $this->mobytService = $this->getMockBuilder(MobytService::class)
|
|
|
+ ->disableOriginalConstructor()
|
|
|
+ ->getMock();
|
|
|
+
|
|
|
+ $this->organizationRepository = $this->getMockBuilder(OrganizationRepository::class)
|
|
|
+ ->disableOriginalConstructor()
|
|
|
+ ->getMock();
|
|
|
+
|
|
|
+ $this->mobytUserStatusCreator = new MobytUserStatusCreator(
|
|
|
+ $this->mobytService,
|
|
|
+ $this->organizationRepository
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getJsonContentFromFixture(string $filename): array {
|
|
|
+ $filepath = dirname(__FILE__) . '/fixtures/' . $filename;
|
|
|
+ return json_decode(file_get_contents($filepath), true);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testGetUserStatus() {
|
|
|
+ $parameters = $this->getMockBuilder(Parameters::class)->getMock();
|
|
|
+ $parameters->expects($this->once())->method('getUsernameSMS')->willReturn('user');
|
|
|
+ $parameters->expects($this->once())->method('getPasswordSMS')->willReturn('pwd');
|
|
|
+
|
|
|
+ $organization = $this->getMockBuilder(Organization::class)->getMock();
|
|
|
+ $organization->expects($this->once())->method('getParameters')->willReturn($parameters);
|
|
|
+
|
|
|
+ $this->organizationRepository
|
|
|
+ ->expects($this->once())
|
|
|
+ ->method('find')
|
|
|
+ ->with(1)
|
|
|
+ ->willReturn($organization);
|
|
|
+
|
|
|
+ $this->mobytService
|
|
|
+ ->expects($this->once())
|
|
|
+ ->method('getUserStatus')
|
|
|
+ ->with(1, 'user', 'pwd')
|
|
|
+ ->willReturn(
|
|
|
+ $this->getJsonContentFromFixture('user_status.json')
|
|
|
+ );
|
|
|
+
|
|
|
+ $mobytUserStatus = $this->mobytUserStatusCreator->getUserStatus(1);
|
|
|
+
|
|
|
+ $this->assertEquals(
|
|
|
+ $mobytUserStatus->getMoney(),
|
|
|
+ 33.0
|
|
|
+ );
|
|
|
+
|
|
|
+ // check that top-level amoung is taken in account, and only it
|
|
|
+ $this->assertEquals(
|
|
|
+ $mobytUserStatus->getAmount(),
|
|
|
+ 300
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|