From 2480beda28cd0e4060f6908ff08a1b49906a2317 Mon Sep 17 00:00:00 2001 From: Ghazi Triki Date: Wed, 20 Jan 2016 10:50:33 +0100 Subject: [PATCH] Better XML to core objects conversion. --- .php_cs | 4 +- src/Core/Attendee.php | 16 +- src/Core/Meeting.php | 36 ++-- src/Core/MeetingInfo.php | 180 ++++-------------- src/Responses/ApiVersionResponse.php | 2 +- src/Responses/CreateMeetingResponse.php | 26 +-- src/Responses/IsMeetingRunningResponse.php | 2 +- .../Responses/GetMeetingInfoResponseTest.php | 44 ++++- tests/TestCase.php | 85 ++++++++- tests/fixtures/get_meeting_info.xml | 6 +- 10 files changed, 193 insertions(+), 208 deletions(-) diff --git a/.php_cs b/.php_cs index cc382f01..31ea9417 100644 --- a/.php_cs +++ b/.php_cs @@ -17,8 +17,8 @@ return Symfony\CS\Config\Config::create() 'multiple_use', 'parenthesis', 'php_closing_tag', 'trailing_spaces', 'visibility', 'array_element_no_space_before_comma', 'array_element_white_space_after_comma', 'blankline_after_open_tag', 'duplicate_semicolon', 'extra_empty_lines', 'function_typehint_space', 'include', 'list_commas ', 'namespace_no_leading_whitespace', 'no_blank_lines_after_class_opening ', - 'no_empty_lines_after_phpdocs ', 'object_operator', 'operators_spaces', 'phpdoc_indent', 'phpdoc_params', 'return', - 'self_accessor', 'single_array_no_trailing_comma', 'single_quote', 'spaces_cast', 'standardize_not_equal', + 'no_empty_lines_after_phpdocs ', 'object_operator', 'operators_spaces', 'phpdoc_indent', 'phpdoc_params', + 'return', 'self_accessor', 'single_array_no_trailing_comma', 'single_quote', 'spaces_cast', 'standardize_not_equal', 'ternary_spaces', 'unneeded_control_parentheses', 'unused_use', 'whitespacy_lines', 'short_array_syntax', 'align_double_arrow', 'align_equals' )) diff --git a/src/Core/Attendee.php b/src/Core/Attendee.php index 629205c0..986c6ad2 100644 --- a/src/Core/Attendee.php +++ b/src/Core/Attendee.php @@ -36,22 +36,22 @@ class Attendee private $role; /** - * @var boolean + * @var bool */ private $isPresenter; /** - * @var boolean + * @var bool */ private $isListeningOnly; /** - * @var boolean + * @var bool */ private $hasJoinedVoice; /** - * @var boolean + * @var bool */ private $hasVideo; @@ -95,7 +95,7 @@ public function getRole() } /** - * @return boolean + * @return bool */ public function isIsPresenter() { @@ -103,7 +103,7 @@ public function isIsPresenter() } /** - * @return boolean + * @return bool */ public function isIsListeningOnly() { @@ -111,7 +111,7 @@ public function isIsListeningOnly() } /** - * @return boolean + * @return bool */ public function isHasJoinedVoice() { @@ -119,7 +119,7 @@ public function isHasJoinedVoice() } /** - * @return boolean + * @return bool */ public function isHasVideo() { diff --git a/src/Core/Meeting.php b/src/Core/Meeting.php index 590d83ef..2c520d38 100644 --- a/src/Core/Meeting.php +++ b/src/Core/Meeting.php @@ -37,7 +37,7 @@ class Meeting private $meetingName; /** - * @var integer + * @var int */ private $creationTime; @@ -47,7 +47,7 @@ class Meeting private $creationDate; /** - * @var integer + * @var int */ private $voiceBridge; @@ -67,42 +67,42 @@ class Meeting private $moderatorPassword; /** - * @var boolean + * @var bool */ private $hasBeenForciblyEnded; /** - * @var boolean + * @var bool */ private $isRunning; /** - * @var integer + * @var int */ private $participantCount; /** - * @var integer + * @var int */ private $listenerCount; /** - * @var integer + * @var int */ private $voiceParticipantCount; /** - * @var integer + * @var int */ private $videoCount; /** - * @var integer + * @var int */ private $duration; /** - * @var boolean + * @var bool */ private $hasUserJoined; @@ -114,7 +114,7 @@ public function __construct($xml) { $this->meetingId = $xml->meetingID->__toString(); $this->meetingName = $xml->meetingName->__toString(); - $this->creationTime = intval($xml->createTime); + $this->creationTime = doubleval($xml->createTime); $this->creationDate = $xml->createDate->__toString(); $this->voiceBridge = intval($xml->voiceBridge); $this->dialNumber = $xml->dialNumber->__toString(); @@ -147,7 +147,7 @@ public function getMeetingName() } /** - * @return int + * @return double */ public function getCreationTime() { @@ -195,17 +195,17 @@ public function getModeratorPassword() } /** - * @return boolean + * @return bool */ - public function isHasBeenForciblyEnded() + public function hasBeenForciblyEnded() { return $this->hasBeenForciblyEnded; } /** - * @return boolean + * @return bool */ - public function isIsRunning() + public function isRunning() { return $this->isRunning; } @@ -251,9 +251,9 @@ public function getDuration() } /** - * @return boolean + * @return bool */ - public function isHasUserJoined() + public function hasUserJoined() { return $this->hasUserJoined; } diff --git a/src/Core/MeetingInfo.php b/src/Core/MeetingInfo.php index 59444e2f..0b1c0565 100644 --- a/src/Core/MeetingInfo.php +++ b/src/Core/MeetingInfo.php @@ -18,155 +18,75 @@ */ namespace BigBlueButton\Core; -class MeetingInfo +/** + * Class MeetingInfo + * @package BigBlueButton\Core + */ +class MeetingInfo extends Meeting { - private $internalMeetingId; - private $creationTime; - private $creationDate; - private $voiceBridge; - private $dialNumber; - private $attendeePassword; - private $moderatorPassword; - private $isRunning; - private $duration; - private $hasUserJoined; - private $isRecording; - private $hasBeenForciblyEnded; - private $startTime; - private $endTime; - private $participantCount; - private $listenerCount; - private $voiceParticipantCount; - private $videoCount; - private $maxUsers; - private $moderatorCount; - /** - * MeetingInfo constructor. - * @param $xml \SimpleXMLElement + * @var string */ - public function __construct($xml) - { - $this->internalMeetingId = $xml->internalMeetingID->__toString(); - $this->creationTime = intval($xml->createTime); - $this->creationDate = $xml->createDate->__toString(); - $this->voiceBridge = intval($xml->voiceBridge); - $this->dialNumber = $xml->dialNumber->__toString(); - $this->attendeePassword = $xml->attendeePW->__toString(); - $this->moderatorPassword = $xml->moderatorPW->__toString(); - $this->isRunning = $xml->running->__toString() == 'true'; - $this->duration = intval($xml->duration); - $this->hasUserJoined = $xml->hasUserJoined->__toString() == 'true'; - $this->isRecording = $xml->recording->__toString() == 'true'; - $this->hasBeenForciblyEnded = $xml->hasBeenForciblyEnded->__toString() == 'true'; - $this->startTime = intval($xml->startTime); - $this->endTime = intval($xml->endTime); - $this->participantCount = intval($xml->participantCount); - $this->listenerCount = intval($xml->listenerCount); - $this->voiceParticipantCount = intval($xml->voiceParticipantCount); - $this->videoCount = intval($xml->videoCount); - $this->maxUsers = intval($xml->maxUsers); - $this->moderatorCount = intval($xml->moderatorCount); - } - - /** - * @return mixed - */ - public function getInternalMeetingId() - { - return $this->internalMeetingId; - } - - /** - * @return int - */ - public function getCreationTime() - { - return $this->creationTime; - } - - /** - * @return mixed - */ - public function getCreationDate() - { - return $this->creationDate; - } + private $internalMeetingId; /** - * @return int + * @var bool */ - public function getVoiceBridge() - { - return $this->voiceBridge; - } + private $isRecording; /** - * @return mixed + * @var double */ - public function getDialNumber() - { - return $this->dialNumber; - } + private $startTime; /** - * @return mixed + * @var double */ - public function getAttendeePassword() - { - return $this->attendeePassword; - } + private $endTime; /** - * @return mixed + * @var int */ - public function getModeratorPassword() - { - return $this->moderatorPassword; - } + private $maxUsers; /** - * @return boolean + * @var int */ - public function isIsRunning() - { - return $this->isRunning; - } + private $moderatorCount; /** - * @return int + * MeetingInfo constructor. + * @param $xml \SimpleXMLElement */ - public function getDuration() + public function __construct($xml) { - return $this->duration; + parent::__construct($xml); + $this->internalMeetingId = $xml->internalMeetingID->__toString(); + $this->isRecording = $xml->recording->__toString() == 'true'; + $this->startTime = doubleval($xml->startTime); + $this->endTime = doubleval($xml->endTime); + $this->maxUsers = $xml->maxUsers->__toString() + 0; + $this->moderatorCount = $xml->moderatorCount->__toString() + 0; } /** - * @return boolean + * @return string */ - public function isHasUserJoined() + public function getInternalMeetingId() { - return $this->hasUserJoined; + return $this->internalMeetingId; } /** - * @return boolean + * @return bool */ - public function isIsRecording() + public function isRecording() { return $this->isRecording; } /** - * @return boolean - */ - public function isHasBeenForciblyEnded() - { - return $this->hasBeenForciblyEnded; - } - - /** - * @return int + * @return double */ public function getStartTime() { @@ -174,45 +94,13 @@ public function getStartTime() } /** - * @return int + * @return double */ public function getEndTime() { return $this->endTime; } - /** - * @return int - */ - public function getParticipantCount() - { - return $this->participantCount; - } - - /** - * @return int - */ - public function getListenerCount() - { - return $this->listenerCount; - } - - /** - * @return int - */ - public function getVoiceParticipantCount() - { - return $this->voiceParticipantCount; - } - - /** - * @return int - */ - public function getVideoCount() - { - return $this->videoCount; - } - /** * @return int */ diff --git a/src/Responses/ApiVersionResponse.php b/src/Responses/ApiVersionResponse.php index 801d558d..880b8490 100644 --- a/src/Responses/ApiVersionResponse.php +++ b/src/Responses/ApiVersionResponse.php @@ -29,6 +29,6 @@ class ApiVersionResponse extends BaseResponse */ public function getVersion() { - return $this->rawXml->version; + return $this->rawXml->version->__toString(); } } diff --git a/src/Responses/CreateMeetingResponse.php b/src/Responses/CreateMeetingResponse.php index 9dc50eb6..b07a567d 100644 --- a/src/Responses/CreateMeetingResponse.php +++ b/src/Responses/CreateMeetingResponse.php @@ -51,19 +51,19 @@ public function getModeratorPassword() /** * Creation timestamp. * - * @return int + * @return double */ public function getCreationTime() { - return $this->rawXml->createTime; + return doubleval($this->rawXml->createTime); } /** - * @return string + * @return int */ public function getVoiceBridge() { - return $this->rawXml->voiceBridge; + return intval($this->rawXml->voiceBridge); } /** @@ -71,7 +71,7 @@ public function getVoiceBridge() */ public function getDialNumber() { - return $this->rawXml->dialNumber; + return $this->rawXml->dialNumber->__toString(); } /** @@ -81,7 +81,7 @@ public function getDialNumber() */ public function getCreationDate() { - return $this->rawXml->createDate; + return $this->rawXml->createDate->__toString(); } /** @@ -89,23 +89,23 @@ public function getCreationDate() */ public function hasUserJoined() { - return $this->rawXml->hasUserJoined; + return $this->rawXml->hasUserJoined->__toString() == 'true'; } /** * @return int */ - public function getDurtation() + public function getDuration() { - return $this->rawXml->duration; + return intval($this->rawXml->duration); } /** - * @return true + * @return bool */ public function hasBeenForciblyEnded() { - return $this->rawXml->hasBeenForciblyEnded; + return $this->rawXml->hasBeenForciblyEnded->__toString() == 'true'; } /** @@ -113,7 +113,7 @@ public function hasBeenForciblyEnded() */ public function getMessageKey() { - return $this->rawXml->messageKey; + return $this->rawXml->messageKey->__toString(); } /** @@ -121,6 +121,6 @@ public function getMessageKey() */ public function getMessage() { - return $this->rawXml->message; + return $this->rawXml->message->__toString(); } } diff --git a/src/Responses/IsMeetingRunningResponse.php b/src/Responses/IsMeetingRunningResponse.php index d57b050d..d181eb5a 100644 --- a/src/Responses/IsMeetingRunningResponse.php +++ b/src/Responses/IsMeetingRunningResponse.php @@ -25,7 +25,7 @@ class IsMeetingRunningResponse extends BaseResponse { /** - * @return boolean + * @return bool */ public function isRunning() { diff --git a/tests/Responses/GetMeetingInfoResponseTest.php b/tests/Responses/GetMeetingInfoResponseTest.php index f406df75..a58aca7c 100644 --- a/tests/Responses/GetMeetingInfoResponseTest.php +++ b/tests/Responses/GetMeetingInfoResponseTest.php @@ -19,7 +19,6 @@ */ class GetMeetingInfoResponseTest extends \BigBlueButton\TestCase { - /** * @var \BigBlueButton\Responses\GetMeetingInfoResponse */ @@ -29,23 +28,52 @@ public function setUp() { parent::setUp(); - $xml = simplexml_load_string(file_get_contents((__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'get_meeting_info.xml'))); + $xml = $this->loadXmlFile(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'get_meeting_info.xml'); $this->meetingInfo = new \BigBlueButton\Responses\GetMeetingInfoResponse($xml); } public function testGetMeetingInfoResponseContent() { + $info = $this->meetingInfo->getMeetingInfo(); $this->assertEquals(2, sizeof($this->meetingInfo->getAttendees())); + $this->assertEquals('SUCCESS', $this->meetingInfo->getReturnCode()); + $this->assertEquals('Mock meeting for testing getMeetingInfo API method', $info->getMeetingName()); + $this->assertEquals('117b12ae2656972d330b6bad58878541-28-15', $info->getMeetingId()); + $this->assertEquals('178757fcedd9449054536162cdfe861ddebc70ba-1453206317376', $info->getInternalMeetingId()); + $this->assertEquals(1453206317376, $info->getCreationTime()); + $this->assertEquals('Tue Jan 19 07:25:17 EST 2016', $info->getCreationDate()); + $this->assertEquals(70100, $info->getVoiceBridge()); + $this->assertEquals('613-555-1234', $info->getDialNumber()); + $this->assertEquals('dbfc7207321527bbb870c82028', $info->getAttendeePassword()); + $this->assertEquals('4bfbbeeb4a65cacaefe3676633', $info->getModeratorPassword()); + $this->assertEquals(true, $info->isRunning()); + $this->assertEquals(20, $info->getDuration()); + $this->assertEquals(true, $info->hasUserJoined()); + $this->assertEquals(true, $info->isRecording()); + $this->assertEquals(false, $info->hasBeenForciblyEnded()); + $this->assertEquals(1453206317380, $info->getStartTime()); + $this->assertEquals(1453206325002, $info->getEndTime()); + $this->assertEquals(2, $info->getParticipantCount()); + $this->assertEquals(1, $info->getListenerCount()); + $this->assertEquals(2, $info->getVoiceParticipantCount()); + $this->assertEquals(1, $info->getVideoCount()); + $this->assertEquals(20, $info->getMaxUsers()); + $this->assertEquals(2, $info->getModeratorCount()); } - public function testGetMeetingInfoResponseTypes(){ + public function testGetMeetingInfoResponseTypes() + { $info = $this->meetingInfo->getMeetingInfo(); - $this->assertTrue(is_string($info->getInternalMeetingId())); - $this->assertTrue(is_string($info->getModeratorPassword())); - $this->assertTrue(is_string($info->getAttendeePassword())); - $this->assertTrue(is_string($info->getCreationDate())); - } + $this->assertEachGetterValueIsString($info, ['getMeetingName', 'getMeetingId', 'getInternalMeetingId', + 'getModeratorPassword', 'getAttendeePassword', 'getCreationDate', 'getDialNumber']); + $this->assertEachGetterValueIsInteger($info, ['getVoiceBridge', 'getDuration', 'getParticipantCount', + 'getListenerCount', 'getVoiceParticipantCount', 'getVideoCount', 'getMaxUsers', 'getModeratorCount']); + + $this->assertEachGetterValueIsDouble($info, ['getStartTime', 'getEndTime', 'getCreationTime']); + + $this->assertEachGetterValueIsBoolean($info, ['isRunning', 'isRecording', 'hasUserJoined', 'hasBeenForciblyEnded']); + } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 2c041b20..a257f4fe 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -100,12 +100,12 @@ protected function getCreateParamsMock($params) */ protected function generateJoinMeetingParams() { - return ['meetingId' => $this->faker->uuid, - 'userName' => $this->faker->name, - 'password' => $this->faker->password, - 'userId' => $this->faker->numberBetween(1, 1000), - 'webVoiceConf' => $this->faker->word, - 'creationTime' => $this->faker->unixTime, ]; + return ['meetingId' => $this->faker->uuid, + 'userName' => $this->faker->name, + 'password' => $this->faker->password, + 'userId' => $this->faker->numberBetween(1, 1000), + 'webVoiceConf' => $this->faker->word, + 'creationTime' => $this->faker->unixTime, ]; } /** @@ -125,8 +125,8 @@ protected function getJoinMeetingMock($params) */ protected function generateEndMeetingParams() { - return ['meetingId' => $this->faker->uuid, - 'password' => $this->faker->password]; + return ['meetingId' => $this->faker->uuid, + 'password' => $this->faker->password]; } /** @@ -138,4 +138,73 @@ protected function getEndMeetingMock($params) { return new EndMeetingParameters($params['meetingId'], $params['password']); } + + // Load fixtures + + protected function loadXmlFile($path) + { + return simplexml_load_string(file_get_contents(($path))); + } + + // Additional assertions + + public function assertIsString($actual, $message = '') + { + if (empty($message)) { + $message = 'Got a ' . gettype($actual) . ' instead of a string'; + } + $this->assertTrue(is_string($actual), $message); + } + + public function assertIsInteger($actual, $message = '') + { + if (empty($message)) { + $message = 'Got a ' . gettype($actual) . ' instead of an integer.'; + } + $this->assertTrue(is_integer($actual), $message); + } + + public function assertIsDouble($actual, $message = '') + { + if (empty($message)) { + $message = 'Got a ' . gettype($actual) . ' instead of a double.'; + } + $this->assertTrue(is_double($actual), $message); + } + + public function assertIsBoolean($actual, $message = '') + { + if (empty($message)) { + $message = 'Got a ' . gettype($actual) . ' instead of a boolean.'; + } + $this->assertTrue(is_bool($actual), $message); + } + + public function assertEachGetterValueIsString($obj, $getters) + { + foreach ($getters as $getterName) { + $this->assertIsString($obj->$getterName(), 'Got a ' . gettype($obj->$getterName()) . ' instead of a string for property -> ' . $getterName); + } + } + + public function assertEachGetterValueIsInteger($obj, $getters) + { + foreach ($getters as $getterName) { + $this->assertIsInteger($obj->$getterName(), 'Got a ' . gettype($obj->$getterName()) . ' instead of an integer for property -> ' . $getterName); + } + } + + public function assertEachGetterValueIsDouble($obj, $getters) + { + foreach ($getters as $getterName) { + $this->assertIsDouble($obj->$getterName(), 'Got a ' . gettype($obj->$getterName()) . ' instead of a double for property -> ' . $getterName); + } + } + + public function assertEachGetterValueIsBoolean($obj, $getters) + { + foreach ($getters as $getterName) { + $this->assertIsBoolean($obj->$getterName(), 'Got a ' . gettype($obj->$getterName()) . ' instead of a boolean for property -> ' . $getterName); + } + } } diff --git a/tests/fixtures/get_meeting_info.xml b/tests/fixtures/get_meeting_info.xml index cb029cbd..f74b7501 100644 --- a/tests/fixtures/get_meeting_info.xml +++ b/tests/fixtures/get_meeting_info.xml @@ -11,14 +11,14 @@ dbfc7207321527bbb870c82028 4bfbbeeb4a65cacaefe3676633 true - 0 + 20 true true false 1453206317380 - 0 + 1453206325002 2 - 0 + 1 2 1 20