Skip to content

Commit

Permalink
Codecov additions, and refactored some of that terrible default handling
Browse files Browse the repository at this point in the history
  • Loading branch information
SecondeJK committed Aug 17, 2023
1 parent e1a2a94 commit 3008c4a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
23 changes: 11 additions & 12 deletions src/OpenTok/Broadcast.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,10 @@ public function __construct($broadcastData, $options = array())
);

$options = array_merge($defaults, array_intersect_key($options, $defaults));
list($apiKey, $apiSecret, $apiUrl, $client, $isStopped, $streamMode, $hasAudio, $hasVideo) = array_values($options);

// validate params
Validators::validateBroadcastData($broadcastData);
Validators::validateClient($client);
Validators::validateHasStreamMode($streamMode);
Validators::validateClient($options['client']);
Validators::validateHasStreamMode($options['streamMode']);

$this->data = $broadcastData;

Expand All @@ -129,21 +127,22 @@ public function __construct($broadcastData, $options = array())
$this->status = $this->data['status'];
}

$this->isStopped = $isStopped;
$this->isStopped = $options['isStopped'];
$this->resolution = $this->data['resolution'];
$this->isHls = isset($this->data['settings']['hls']);
$this->isLowLatency = $this->data['settings']['hls']['lowLatency'] ?? false;
$this->isDvr = $this->data['settings']['hls']['dvr'] ?? false;
$this->hasAudio = $hasAudio;
$this->hasVideo = $hasVideo;
$this->hasAudio = $options['hasAudio'];
$this->hasVideo = $options['hasVideo'];

$this->client = $options['client'] ?? new Client();

$this->client = isset($client) ? $client : new Client();
if (!$this->client->isConfigured()) {
Validators::validateApiKey($apiKey);
Validators::validateApiSecret($apiSecret);
Validators::validateApiUrl($apiUrl);
Validators::validateApiKey($options['apiKey']);
Validators::validateApiSecret($options['apiSecret']);
Validators::validateApiUrl($options['apiUrl']);

$this->client->configure($apiKey, $apiSecret, $apiUrl);
$this->client->configure($options['apiKey'], $options['apiSecret'], $options['apiUrl']);
}
}

Expand Down
25 changes: 21 additions & 4 deletions tests/OpenTokTest/BroadcastTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function setUp(): void
'updatedAt' => 1394394801000,
'partnerId' => 685,
'sessionId' => '2_MX44NTQ1MTF-flR1ZSBOb3YgMTIgMDk6NDA6NTkgUFNUIDIwMTN-MC43NjU0Nzh-',
'multiBroadcastTag' => 'broadcast-1234b',
'layout' => [
'type' => 'custom',
'stylesheet' => 'a layout stylesheet',
Expand All @@ -42,8 +43,9 @@ public function setUp(): void
'maxDuration' => 5400,
'resolution' => '640x480',
'streamMode' => StreamMode::AUTO,
'isAudio' => true,
'isVideo' => true
'status' => 'started',
'hasAudio' => true,
'hasVideo' => true
];
}

Expand Down Expand Up @@ -134,12 +136,12 @@ private function setupOT()
return $this->setupOTWithMocks([]);
}

public function testInitializes()
public function testInitializes(): void
{
// Arrange
$this->setupOT();
$this->setupBroadcasts(StreamMode::AUTO);
$this->assertInstanceOf(Broadcast::class, $this->broadcast);

}

public function testCannotAddStreamToBroadcastInAutoMode(): void
Expand Down Expand Up @@ -238,5 +240,20 @@ public function testCannotRemoveStreamFromBroadcastOnAuto(): void
'5dfds4-asdda4asf4'
);
}

public function testGetters(): void
{
$broadcastObject = new Broadcast($this->broadcastData, [
'apiKey' => 'abc',
'apiSecret' => 'efg',
'client' => $this->client
]);

$this->assertTrue($broadcastObject->hasAudio);
$this->assertTrue($broadcastObject->hasVideo);
$this->assertEquals('broadcast-1234b', $broadcastObject->multiBroadcastTag);
$this->assertEquals('started', $broadcastObject->status);
$this->assertNull($broadcastObject->wrongKey);
}
}

0 comments on commit 3008c4a

Please sign in to comment.