Skip to content

Commit

Permalink
BC break: allow room based teacher when creating perma class
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Zukowski committed Nov 26, 2015
1 parent 78786ad commit e980946
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
8 changes: 6 additions & 2 deletions docs/virtual-classroom-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ $gateway = new Wiziq\API\Gateway($auth);
$api = new Wiziq\API\ClassroomApi($gateway);

try {
$classroom = Wiziq\Entity\Classroom::build('Class title', '[email protected]', 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));
Expand Down Expand Up @@ -61,7 +63,9 @@ $gateway = new Wiziq\API\Gateway($auth);
$api = new Wiziq\API\ClassroomApi($gateway);

try {
$classroom = Wiziq\Entity\PermaClassroom::build('Class title', '[email protected]');
$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));
Expand Down
23 changes: 14 additions & 9 deletions src/Entity/PermaClassroom.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,28 @@ 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);
}

/**
* @return array
*/
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,
Expand All @@ -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;
}
}
27 changes: 25 additions & 2 deletions tests/Entity/PermaClassroomTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,49 @@ class PermaClassroomTest extends \PHPUnit_Framework_TestCase
/** @var array */
private $expected = [
'title' => 'Title',
'presenter_email' => '[email protected]',
'attendee_limit' => '',
'presenter_default_controls' => '',
'attendee_default_controls' => '',
'create_recording' => '',
'return_url' => '',
'status_ping_url' => '',
'language_culture_name' => '',
'presenter_id' => '',
'presenter_name' => '',
];

public function setUp()
{
$this->entity = PermaClassroom::build('Title', '[email protected]');
$this->entity = PermaClassroom::build('Title');
}

public function testBuildBasic()
{
$this->assertEquals($this->expected, $this->entity->toArray());
}

public function testBuildWithPresenter()
{
$this->expected['presenter_id'] = 100;
$this->expected['presenter_name'] = '[email protected]';
$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'] = '[email protected]';
$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';
Expand Down

0 comments on commit e980946

Please sign in to comment.