From e980946c58683756fe6f5de85a2c359892f79bcb Mon Sep 17 00:00:00 2001 From: Michal Zukowski Date: Thu, 26 Nov 2015 13:44:51 +0100 Subject: [PATCH] BC break: allow room based teacher when creating perma class --- docs/virtual-classroom-api.md | 8 ++++++-- src/Entity/PermaClassroom.php | 23 ++++++++++++++--------- tests/Entity/PermaClassroomTest.php | 27 +++++++++++++++++++++++++-- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/docs/virtual-classroom-api.md b/docs/virtual-classroom-api.md index c4c8e4e..f8f365a 100644 --- a/docs/virtual-classroom-api.md +++ b/docs/virtual-classroom-api.md @@ -10,7 +10,9 @@ $gateway = new Wiziq\API\Gateway($auth); $api = new Wiziq\API\ClassroomApi($gateway); try { - $classroom = Wiziq\Entity\Classroom::build('Class title', 'teacher@email.com', new \DateTime('now')); + $classroom = Wiziq\Entity\Classroom::build('Class title', new \DateTime('now')) + ->withPresenter(100, 'Presenter Name'); + $response = $api->create($classroom); printf('Class %s created: %s', $classroom, var_export($response, true)); @@ -61,7 +63,9 @@ $gateway = new Wiziq\API\Gateway($auth); $api = new Wiziq\API\ClassroomApi($gateway); try { - $classroom = Wiziq\Entity\PermaClassroom::build('Class title', 'teacher@email.com'); + $classroom = Wiziq\Entity\PermaClassroom::build('Class title') + ->withPresenter(100, 'Presenter Name'); + $response = $api->createPermaClass($classroom); printf('Perma class %s created: %s', $classroom, var_export($response, true)); diff --git a/src/Entity/PermaClassroom.php b/src/Entity/PermaClassroom.php index 5edf14d..ee0b532 100644 --- a/src/Entity/PermaClassroom.php +++ b/src/Entity/PermaClassroom.php @@ -9,22 +9,19 @@ class PermaClassroom /** * @param string $title - * @param string $presenterEmail */ - private function __construct($title, $presenterEmail) + private function __construct($title) { - $this->title = (string)$title; - $this->presenterEmail = (string)$presenterEmail; + $this->title = (string)$title; } /** * @param string $title - * @param string $presenterEmail * @return self */ - public static function build($title, $presenterEmail) + public static function build($title) { - return new self($title, $presenterEmail); + return new self($title); } /** @@ -32,9 +29,8 @@ public static function build($title, $presenterEmail) */ public function toArray() { - return [ + $params = [ 'title' => $this->title, - 'presenter_email' => $this->presenterEmail, 'attendee_limit' => $this->attendeeLimit, 'presenter_default_controls' => $this->presenterDefaultControls, 'attendee_default_controls' => $this->attendeeDefaultControls, @@ -43,5 +39,14 @@ public function toArray() 'return_url' => $this->returnUrl, 'status_ping_url' => $this->statusPingUrl, ]; + + if ($this->presenterEmail) { + $params['presenter_email'] = $this->presenterEmail; + } else { + $params['presenter_id'] = $this->presenterId; + $params['presenter_name'] = $this->presenterName; + } + + return $params; } } diff --git a/tests/Entity/PermaClassroomTest.php b/tests/Entity/PermaClassroomTest.php index c813fa8..ae88ab2 100644 --- a/tests/Entity/PermaClassroomTest.php +++ b/tests/Entity/PermaClassroomTest.php @@ -11,7 +11,6 @@ class PermaClassroomTest extends \PHPUnit_Framework_TestCase /** @var array */ private $expected = [ 'title' => 'Title', - 'presenter_email' => 'mike@test.com', 'attendee_limit' => '', 'presenter_default_controls' => '', 'attendee_default_controls' => '', @@ -19,11 +18,13 @@ class PermaClassroomTest extends \PHPUnit_Framework_TestCase 'return_url' => '', 'status_ping_url' => '', 'language_culture_name' => '', + 'presenter_id' => '', + 'presenter_name' => '', ]; public function setUp() { - $this->entity = PermaClassroom::build('Title', 'mike@test.com'); + $this->entity = PermaClassroom::build('Title'); } public function testBuildBasic() @@ -31,6 +32,28 @@ public function testBuildBasic() $this->assertEquals($this->expected, $this->entity->toArray()); } + public function testBuildWithPresenter() + { + $this->expected['presenter_id'] = 100; + $this->expected['presenter_name'] = 'mike@test.com'; + $newEntity = $this->entity->withPresenter($this->expected['presenter_id'], $this->expected['presenter_name']); + + $this->assertEquals($this->expected, $newEntity->toArray()); + $this->assertNotSame($newEntity, $this->entity); + } + + public function testBuildWithPresenterEmail() + { + unset($this->expected['presenter_id']); + unset($this->expected['presenter_name']); + + $this->expected['presenter_email'] = 'mike@test.com'; + $newEntity = $this->entity->withPresenterEmail($this->expected['presenter_email']); + + $this->assertEquals($this->expected, $newEntity->toArray()); + $this->assertNotSame($newEntity, $this->entity); + } + public function testBuildWithLanguageCultureName() { $this->expected['language_culture_name'] = 'en-EN';