Skip to content

Commit 4a052a4

Browse files
committed
WIP
1 parent 5b97c82 commit 4a052a4

11 files changed

+211
-46
lines changed

src/Parameters/HooksCreateParameters.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,20 @@
2222

2323
class HooksCreateParameters extends BaseParameters
2424
{
25-
private ?string $callbackUrl = null;
25+
private string $callbackUrl;
2626

2727
private ?string $meetingId = null;
2828

29+
private ?string $eventId = null;
30+
2931
private ?bool $getRaw = null;
3032

3133
public function __construct(string $callbackUrl)
3234
{
3335
$this->callbackUrl = $callbackUrl;
3436
}
3537

36-
public function getCallbackUrl(): ?string
38+
public function getCallbackUrl(): string
3739
{
3840
return $this->callbackUrl;
3941
}
@@ -57,6 +59,18 @@ public function setMeetingId(string $meetingId): self
5759
return $this;
5860
}
5961

62+
public function getEventId(): ?string
63+
{
64+
return $this->eventId;
65+
}
66+
67+
public function setEventId(string $eventId): self
68+
{
69+
$this->eventId = $eventId;
70+
71+
return $this;
72+
}
73+
6074
public function getRaw(): ?bool
6175
{
6276
return $this->getRaw;

src/Responses/HooksCreateResponse.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,30 @@
2525
*/
2626
class HooksCreateResponse extends BaseResponse
2727
{
28-
/**
29-
* @return int
30-
*/
31-
public function getHookId()
28+
public function getHookId(): ?int
3229
{
30+
if (!$this->rawXml->hookID) {
31+
return null;
32+
}
33+
3334
return (int) $this->rawXml->hookID->__toString();
3435
}
3536

36-
/**
37-
* @return null|bool
38-
*/
39-
public function isPermanentHook()
37+
public function isPermanentHook(): ?bool
4038
{
39+
if (!$this->rawXml->permanentHook) {
40+
return null;
41+
}
42+
4143
return 'true' === $this->rawXml->permanentHook->__toString();
4244
}
4345

44-
/**
45-
* @return null|bool
46-
*/
47-
public function hasRawData()
46+
public function hasRawData(): ?bool
4847
{
48+
if (!$this->rawXml->rawData) {
49+
return null;
50+
}
51+
4952
return 'true' === $this->rawXml->rawData->__toString();
5053
}
5154
}

src/Responses/HooksDestroyResponse.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525
*/
2626
class HooksDestroyResponse extends BaseResponse
2727
{
28-
/**
29-
* @return null|bool
30-
*/
31-
public function removed()
28+
public function removed(): ?bool
3229
{
30+
if (!$this->rawXml->removed) {
31+
return null;
32+
}
33+
3334
return 'true' === $this->rawXml->removed->__toString();
3435
}
3536
}

tests/BigBlueButtonTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626
use BigBlueButton\Parameters\EndMeetingParameters;
2727
use BigBlueButton\Parameters\GetMeetingInfoParameters;
2828
use BigBlueButton\Parameters\GetRecordingsParameters;
29+
use BigBlueButton\Parameters\HooksCreateParameters;
2930
use BigBlueButton\Parameters\IsMeetingRunningParameters;
3031
use BigBlueButton\Parameters\PublishRecordingsParameters;
3132
use BigBlueButton\Util\ParamsIterator;
3233
use Dotenv\Dotenv;
34+
use Tracy\Debugger;
3335

3436
/**
3537
* Class BigBlueButtonTest.
@@ -60,8 +62,9 @@ public function tearDown(): void
6062

6163
// close all existing meetings
6264
$meetingsResponse = $this->bbb->getMeetings();
63-
$meetings = $meetingsResponse->getMeetings();
65+
$this->assertTrue($meetingsResponse->success(), $meetingsResponse->getMessage());
6466

67+
$meetings = $meetingsResponse->getMeetings();
6568
foreach ($meetings as $meeting) {
6669
$endMeetingParameters = new EndMeetingParameters($meeting->getMeetingId(), $meeting->getModeratorPassword());
6770
$endMeetingResponse = $this->bbb->endMeeting($endMeetingParameters);
@@ -356,6 +359,16 @@ public function testUpdateRecordings(): void
356359
$this->assertTrue($result->failed());
357360
}
358361

362+
// Hooks: create
363+
364+
public function testHooksCreate(): void
365+
{
366+
// create a hook
367+
$hooksCreateParameters = new HooksCreateParameters($this->faker->url);
368+
$hooksCreateResponse = $this->bbb->hooksCreate($hooksCreateParameters);
369+
$this->assertEquals('SUCCESS', $hooksCreateResponse->getReturnCode(), $hooksCreateResponse->getMessage());
370+
}
371+
359372
/**
360373
* @see https://github.com/vlucas/phpdotenv
361374
*/

tests/Parameters/HooksCreateParametersTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
namespace BigBlueButton\Parameters;
2222

2323
use BigBlueButton\TestCase;
24+
use Tracy\Debugger;
2425

2526
/**
2627
* @internal
@@ -31,14 +32,25 @@ class HooksCreateParametersTest extends TestCase
3132
{
3233
public function testHooksCreateParameters(): void
3334
{
35+
// create string of eventIds
36+
$eventIds = [];
37+
for ($i = 0; $i < $this->faker->numberBetween(1, 5); ++$i) {
38+
$eventIds[] = $this->faker->uuid;
39+
}
40+
$eventIds = implode(',', $eventIds);
41+
42+
3443
$hooksCreateParameters = new HooksCreateParameters($callBackUrl = $this->faker->url);
3544

3645
$this->assertEquals($callBackUrl, $hooksCreateParameters->getCallbackUrl());
3746

47+
3848
// Test setters that are ignored by the constructor
3949
$hooksCreateParameters->setMeetingId($meetingId = $this->faker->uuid);
4050
$hooksCreateParameters->setGetRaw($getRaw = $this->faker->boolean);
51+
$hooksCreateParameters->setEventId($eventIds);
4152
$this->assertEquals($meetingId, $hooksCreateParameters->getMeetingId());
4253
$this->assertEquals($getRaw, $hooksCreateParameters->getRaw());
54+
$this->assertEquals($eventIds, $hooksCreateParameters->getEventId());
4355
}
4456
}

tests/Parameters/HooksDestroyParametersTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public function testHooksDestroyParameters(): void
3333
{
3434
$hookId = (string) $this->faker->numberBetween(1, 50);
3535

36-
$hooksCreateParameters = new HooksDestroyParameters($hookId);
36+
$hooksDestroyParameters = new HooksDestroyParameters($hookId);
3737

38-
$this->assertEquals($hookId, $hooksCreateParameters->getHookId());
38+
$this->assertEquals($hookId, $hooksDestroyParameters->getHookId());
3939
}
4040
}

tests/Responses/HooksCreateResponseTest.php

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,84 @@
2929
*/
3030
class HooksCreateResponseTest extends TestCase
3131
{
32-
private HooksCreateResponse $createResponse;
32+
private HooksCreateResponse $createResponseCreate;
33+
private HooksCreateResponse $createResponseError;
34+
private HooksCreateResponse $createResponseExisting;
35+
private HooksCreateResponse $createResponseNoHookId;
3336

3437
public function setUp(): void
3538
{
3639
parent::setUp();
3740

38-
$xml = $this->loadXmlFile(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'hooks_create.xml');
41+
$xmlCreate = $this->loadXmlFile(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'hooks_create.xml');
42+
$xmlCreateError = $this->loadXmlFile(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'hooks_create_error.xml');
43+
$xmlCreateExisting = $this->loadXmlFile(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'hooks_create_existing.xml');
44+
$xmlCreateNoHookId = $this->loadXmlFile(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'hooks_create_no_hook_id.xml');
3945

40-
$this->createResponse = new HooksCreateResponse($xml);
46+
$this->createResponseCreate = new HooksCreateResponse($xmlCreate);
47+
$this->createResponseError = new HooksCreateResponse($xmlCreateError);
48+
$this->createResponseExisting = new HooksCreateResponse($xmlCreateExisting);
49+
$this->createResponseNoHookId = new HooksCreateResponse($xmlCreateNoHookId);
4150
}
4251

43-
public function testHooksCreateResponseContent(): void
52+
public function testHooksCreateResponseCreateContent(): void
4453
{
45-
$this->assertEquals('SUCCESS', $this->createResponse->getReturnCode());
46-
$this->assertEquals(1, $this->createResponse->getHookId());
47-
$this->assertFalse($this->createResponse->isPermanentHook());
48-
$this->assertFalse($this->createResponse->hasRawData());
54+
$this->assertEquals('SUCCESS', $this->createResponseCreate->getReturnCode());
55+
$this->assertEquals('', $this->createResponseCreate->getMessageKey());
56+
$this->assertTrue($this->createResponseCreate->success());
57+
$this->assertFalse($this->createResponseCreate->failed());
58+
$this->assertEquals(1, $this->createResponseCreate->getHookId());
59+
$this->assertFalse($this->createResponseCreate->isPermanentHook());
60+
$this->assertFalse($this->createResponseCreate->hasRawData());
61+
}
62+
63+
public function testHooksCreateResponseErrorContent(): void
64+
{
65+
$this->assertEquals('FAILED', $this->createResponseError->getReturnCode());
66+
$this->assertEquals('createHookError', $this->createResponseError->getMessageKey());
67+
$this->assertFalse($this->createResponseError->success());
68+
$this->assertTrue($this->createResponseError->failed());
69+
$this->assertNull($this->createResponseError->getHookId());
70+
$this->assertNull($this->createResponseError->isPermanentHook());
71+
$this->assertNull($this->createResponseError->hasRawData());
72+
}
73+
74+
public function testHooksCreateResponseExistingContent(): void
75+
{
76+
$this->assertEquals('SUCCESS', $this->createResponseExisting->getReturnCode());
77+
$this->assertEquals('duplicateWarning', $this->createResponseExisting->getMessageKey());
78+
$this->assertTrue($this->createResponseExisting->success());
79+
$this->assertFalse($this->createResponseExisting->failed());
80+
$this->assertEquals(1, $this->createResponseExisting->getHookId());
81+
$this->assertNull($this->createResponseExisting->isPermanentHook());
82+
$this->assertNull($this->createResponseExisting->hasRawData());
83+
}
84+
85+
public function testHooksCreateResponseNoHookIdContent(): void
86+
{
87+
$this->assertEquals('FAILED', $this->createResponseNoHookId->getReturnCode());
88+
$this->assertEquals('missingParamHookID', $this->createResponseNoHookId->getMessageKey());
89+
$this->assertFalse($this->createResponseNoHookId->success());
90+
$this->assertTrue($this->createResponseNoHookId->failed());
91+
$this->assertNull($this->createResponseNoHookId->getHookId());
92+
$this->assertNull($this->createResponseNoHookId->isPermanentHook());
93+
$this->assertNull($this->createResponseNoHookId->hasRawData());
4994
}
5095

5196
public function testHooksCreateResponseTypes(): void
5297
{
53-
$this->assertEachGetterValueIsString($this->createResponse, ['getReturnCode']);
54-
$this->assertEachGetterValueIsInteger($this->createResponse, ['getHookId']);
55-
$this->assertEachGetterValueIsBoolean($this->createResponse, ['isPermanentHook', 'hasRawData']);
98+
$this->assertEachGetterValueIsString($this->createResponseCreate, ['getReturnCode']);
99+
$this->assertEachGetterValueIsInteger($this->createResponseCreate, ['getHookId']);
100+
$this->assertEachGetterValueIsBoolean($this->createResponseCreate, ['isPermanentHook', 'hasRawData']);
101+
102+
$this->assertEachGetterValueIsString($this->createResponseError, ['getReturnCode']);
103+
$this->assertEachGetterValueIsNull($this->createResponseError, ['getHookId', 'isPermanentHook', 'hasRawData']);
104+
105+
$this->assertEachGetterValueIsString($this->createResponseExisting, ['getReturnCode']);
106+
$this->assertEachGetterValueIsInteger($this->createResponseExisting, ['getHookId']);
107+
$this->assertEachGetterValueIsNull($this->createResponseExisting, ['isPermanentHook', 'hasRawData']);
108+
109+
$this->assertEachGetterValueIsString($this->createResponseNoHookId, ['getReturnCode']);
110+
$this->assertEachGetterValueIsNull($this->createResponseNoHookId, ['getHookId', 'isPermanentHook', 'hasRawData']);
56111
}
57112
}

tests/Responses/HooksDestroyResponseTest.php

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,65 @@
3030
class HooksDestroyResponseTest extends TestCase
3131
{
3232
private HooksDestroyResponse $destroyResponse;
33+
private HooksDestroyResponse $destroyResponseError;
34+
private HooksDestroyResponse $destroyResponseNotFound;
35+
private HooksDestroyResponse $destroyResponseParamsNoId;
3336

3437
public function setUp(): void
3538
{
3639
parent::setUp();
3740

38-
$xml = $this->loadXmlFile(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'hooks_destroy.xml');
41+
$xml = $this->loadXmlFile(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'hooks_destroy.xml');
42+
$xmlError = $this->loadXmlFile(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'hooks_destroy_error.xml');
43+
$xmlNotFound = $this->loadXmlFile(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'hooks_destroy_not_found.xml');
44+
$xmlParamsNoId = $this->loadXmlFile(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'hooks_destroy_params_no_id.xml');
3945

40-
$this->destroyResponse = new HooksDestroyResponse($xml);
46+
$this->destroyResponse = new HooksDestroyResponse($xml);
47+
$this->destroyResponseError = new HooksDestroyResponse($xmlError);
48+
$this->destroyResponseNotFound = new HooksDestroyResponse($xmlNotFound);
49+
$this->destroyResponseParamsNoId = new HooksDestroyResponse($xmlParamsNoId);
4150
}
4251

4352
public function testHooksDestroyResponseContent(): void
4453
{
4554
$this->assertEquals('SUCCESS', $this->destroyResponse->getReturnCode());
55+
$this->assertEquals('', $this->destroyResponse->getMessageKey());
4656
$this->assertTrue($this->destroyResponse->removed());
4757
}
4858

59+
public function testHooksDestroyErrorResponseContent(): void
60+
{
61+
$this->assertEquals('FAILED', $this->destroyResponseError->getReturnCode());
62+
$this->assertEquals('destroyHookError', $this->destroyResponseError->getMessageKey());
63+
$this->assertNull($this->destroyResponseError->removed());
64+
}
65+
66+
public function testHooksDestroyNotFoundResponseContent(): void
67+
{
68+
$this->assertEquals('FAILED', $this->destroyResponseNotFound->getReturnCode());
69+
$this->assertEquals('destroyMissingHook', $this->destroyResponseNotFound->getMessageKey());
70+
$this->assertNull($this->destroyResponseNotFound->removed());
71+
}
72+
73+
public function testHooksDestroyParamsNoIdContent(): void
74+
{
75+
$this->assertEquals('FAILED', $this->destroyResponseParamsNoId->getReturnCode());
76+
$this->assertEquals('missingParamHookID', $this->destroyResponseParamsNoId->getMessageKey());
77+
$this->assertNull($this->destroyResponseParamsNoId->removed());
78+
}
79+
4980
public function testHooksDestroyResponseTypes(): void
5081
{
5182
$this->assertEachGetterValueIsString($this->destroyResponse, ['getReturnCode']);
5283
$this->assertEachGetterValueIsBoolean($this->destroyResponse, ['removed']);
84+
85+
$this->assertEachGetterValueIsString($this->destroyResponseError, ['getReturnCode']);
86+
$this->assertEachGetterValueIsNull($this->destroyResponseError, ['removed']);
87+
88+
$this->assertEachGetterValueIsString($this->destroyResponseNotFound, ['getReturnCode']);
89+
$this->assertEachGetterValueIsNull($this->destroyResponseNotFound, ['removed']);
90+
91+
$this->assertEachGetterValueIsString($this->destroyResponseParamsNoId, ['getReturnCode']);
92+
$this->assertEachGetterValueIsNull($this->destroyResponseParamsNoId, ['removed']);
5393
}
5494
}

0 commit comments

Comments
 (0)