Skip to content

Commit

Permalink
Simplify response succes and failure return code (#47)
Browse files Browse the repository at this point in the history
Simplify response succes and failure return code
  • Loading branch information
GhaziTriki authored Nov 14, 2019
2 parents fb419ba + 27c8f2f commit 73d7257
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Responses/BaseResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
*/
abstract class BaseResponse
{
const SUCCESS = 'SUCCESS';
const FAILED = 'FAILED';

/**
* @var \SimpleXMLElement
*/
Expand Down Expand Up @@ -70,4 +73,14 @@ public function getMessage()
{
return $this->rawXml->message->__toString();
}

public function success()
{
return $this->getReturnCode() === self::SUCCESS;
}

public function failed()
{
return $this->getReturnCode() === self::FAILED;
}
}
17 changes: 17 additions & 0 deletions tests/BigBlueButtonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function testApiVersion()
$apiVersion = $this->bbb->getApiVersion();
$this->assertEquals('SUCCESS', $apiVersion->getReturnCode());
$this->assertEquals('2.0', $apiVersion->getVersion());
$this->assertTrue($apiVersion->success());
}

/* Create Meeting */
Expand Down Expand Up @@ -91,6 +92,7 @@ public function testCreateMeeting()
$params = $this->generateCreateParams();
$result = $this->bbb->createMeeting($this->getCreateMock($params));
$this->assertEquals('SUCCESS', $result->getReturnCode());
$this->assertTrue($result->success());
}

/**
Expand All @@ -105,6 +107,7 @@ public function testCreateMeetingWithDocumentUrl()

$this->assertCount(1, $params->getPresentations());
$this->assertEquals('SUCCESS', $result->getReturnCode());
$this->assertTrue($result->success());
}

/**
Expand All @@ -119,6 +122,7 @@ public function testCreateMeetingWithDocumentUrlAndFileName()

$this->assertCount(1, $params->getPresentations());
$this->assertEquals('SUCCESS', $result->getReturnCode());
$this->assertTrue($result->success());
}

/**
Expand All @@ -133,6 +137,7 @@ public function testCreateMeetingWithDocumentEmbedded()

$this->assertCount(1, $params->getPresentations());
$this->assertEquals('SUCCESS', $result->getReturnCode());
$this->assertTrue($result->success());
}

/**
Expand All @@ -148,6 +153,7 @@ public function testCreateMeetingWithMultiDocument()

$this->assertCount(2, $params->getPresentations());
$this->assertEquals('SUCCESS', $result->getReturnCode());
$this->assertTrue($result->success());
}

/* Join Meeting */
Expand Down Expand Up @@ -182,6 +188,7 @@ public function testJoinMeeting()

$joinMeeting = $this->bbb->joinMeeting($joinMeetingMock);
$this->assertEquals('SUCCESS', $joinMeeting->getReturnCode());
$this->assertTrue($joinMeeting->success());
$this->assertNotEmpty($joinMeeting->getAuthToken());
$this->assertNotEmpty($joinMeeting->getUserId());
$this->assertNotEmpty($joinMeeting->getSessionToken());
Expand Down Expand Up @@ -222,6 +229,7 @@ public function testSetConfigXML()
$params = $this->generateCreateParams();
$createMeetingResponse = $this->bbb->createMeeting($this->getCreateMock($params));
$this->assertEquals('SUCCESS', $createMeetingResponse->getReturnCode());
$this->assertTrue($createMeetingResponse->success());

// Execute setConfigXML request
$params = ['meetingId' => $createMeetingResponse->getMeetingId()];
Expand All @@ -231,6 +239,7 @@ public function testSetConfigXML()

$result = $this->bbb->setConfigXML($setConfigXMLParams);
$this->assertEquals('SUCCESS', $result->getReturnCode());
$this->assertTrue($result->success());
$this->assertNotEmpty($result->getToken());
}

Expand Down Expand Up @@ -258,13 +267,15 @@ public function testEndMeeting()
$endMeeting = new EndMeetingParameters($meeting->getMeetingId(), $meeting->getModeratorPassword());
$result = $this->bbb->endMeeting($endMeeting);
$this->assertEquals('SUCCESS', $result->getReturnCode());
$this->assertTrue($result->success());
}

public function testEndNonExistingMeeting()
{
$params = $this->generateEndMeetingParams();
$result = $this->bbb->endMeeting($this->getEndMeetingMock($params));
$this->assertEquals('FAILED', $result->getReturnCode());
$this->assertTrue($result->failed());
}

/* Is Meeting Running */
Expand All @@ -273,6 +284,7 @@ public function testIsMeetingRunning()
{
$result = $this->bbb->isMeetingRunning(new IsMeetingRunningParameters($this->faker->uuid));
$this->assertEquals('SUCCESS', $result->getReturnCode());
$this->assertTrue($result->success());
$this->assertEquals(false, $result->isRunning());
}

Expand Down Expand Up @@ -307,6 +319,7 @@ public function testGetMeetingInfo()

$result = $this->bbb->getMeetingInfo(new GetMeetingInfoParameters($meeting->getMeetingId(), $meeting->getModeratorPassword()));
$this->assertEquals('SUCCESS', $result->getReturnCode());
$this->assertTrue($result->success());
}

public function testGetRecordingsUrl()
Expand All @@ -319,6 +332,7 @@ public function testGetRecordings()
{
$result = $this->bbb->getRecordings(new GetRecordingsParameters());
$this->assertEquals('SUCCESS', $result->getReturnCode());
$this->assertTrue($result->success());
}

public function testPublishRecordingsUrl()
Expand All @@ -331,6 +345,7 @@ public function testPublishRecordings()
{
$result = $this->bbb->publishRecordings(new PublishRecordingsParameters('non-existing-id-' . $this->faker->sha1, true));
$this->assertEquals('FAILED', $result->getReturnCode());
$this->assertTrue($result->failed());
}

public function testDeleteRecordingsUrl()
Expand All @@ -343,6 +358,7 @@ public function testDeleteRecordings()
{
$result = $this->bbb->deleteRecordings(new DeleteRecordingsParameters('non-existing-id-' . $this->faker->sha1));
$this->assertEquals('FAILED', $result->getReturnCode());
$this->assertTrue($result->failed());
}

public function testUpdateRecordingsUrl()
Expand All @@ -362,5 +378,6 @@ public function testUpdateRecordings()
$params = $this->generateUpdateRecordingsParams();
$result = $this->bbb->updateRecordings($this->getUpdateRecordingsParamsMock($params));
$this->assertEquals('FAILED', $result->getReturnCode());
$this->assertTrue($result->failed());
}
}

0 comments on commit 73d7257

Please sign in to comment.