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 ); } }