Skip to content

Commit eb57509

Browse files
committed
increase test coverage
1 parent 44e85aa commit eb57509

File tree

3 files changed

+72
-16
lines changed

3 files changed

+72
-16
lines changed

src/OpenTok/Util/Validators.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,11 @@ public static function validateLayoutClassListItem($layoutClassList)
428428
if (!is_array($layoutClassList)) {
429429
throw new InvalidArgumentException('Each element in the streamClassArray must have a layoutClassList array.');
430430
}
431+
432+
if (!isset($layoutClassList['layoutClassList'])) {
433+
throw new InvalidArgumentException('layoutClassList not set in array');
434+
}
435+
431436
if (!is_array($layoutClassList['layoutClassList'])) {
432437
throw new InvalidArgumentException('Each element in the layoutClassList array must be a string (defining class names).');
433438
}

tests/OpenTokTest/LayoutTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace OpenTokTest;
44

55
use OpenTok\Layout;
6+
use OpenTok\Util\Validators;
67
use PHPStan\Testing\TestCase;
78

89
class LayoutTest extends TestCase
@@ -21,6 +22,14 @@ public function testStylesheetIsNotInSerializedArrayIfNotCustom()
2122
}
2223
}
2324

25+
public function testWillValidateLayout(): void
26+
{
27+
$this->expectException(\InvalidArgumentException::class);
28+
$object = ['bestFit' => true];
29+
30+
Validators::validateLayout($object);
31+
}
32+
2433
public function testStylesheetIsInSerializedArrayIfCustom()
2534
{
2635
$layout = Layout::createCustom(['stylesheet' => 'foo']);

tests/OpenTokTest/Validators/ValidatorsTest.php

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,28 +72,28 @@ public function testWillPassCorrectForceMutePayload(): void
7272
Validators::validateForceMuteAllOptions($options);
7373
}
7474

75-
public function testIsAssocWithValidArray(): void
75+
public function testIsAssocWithIndexedArray(): void
7676
{
77-
$haystack = [
78-
'one' => '1',
79-
'two' => '2',
80-
'three' => '3',
81-
'four' => '4'
82-
];
77+
$array = [1, 2, 3, 4];
78+
$this->assertFalse(Validators::isAssoc($array));
79+
}
8380

84-
$this->assertTrue(Validators::isAssoc($haystack));
81+
public function testIsAssocWithAssociativeArray(): void
82+
{
83+
$array = ['a' => 1, 'b' => 2, 'c' => 3];
84+
$this->assertTrue(Validators::isAssoc($array));
8585
}
8686

87-
public function testIsAssocWithInvalidArray(): void
87+
public function testIsAssocWithMixedKeysArray(): void
8888
{
89-
$haystack = [
90-
'one',
91-
'two',
92-
'three',
93-
'four'
94-
];
89+
$array = [1, 'a' => 2, 3];
90+
$this->assertTrue(Validators::isAssoc($array));
91+
}
9592

96-
$this->assertFalse(Validators::isAssoc($haystack));
93+
public function testIsAssocWithEmptyArray(): void
94+
{
95+
$array = [];
96+
$this->assertFalse(Validators::isAssoc($array));
9797
}
9898

9999
public function testWillFailWhenStreamIdsAreNotCorrect(): void
@@ -178,6 +178,48 @@ public function testValidResolutions($resolution, $isValid): void
178178
Validators::validateResolution($resolution);
179179
}
180180

181+
public function testValidLayoutClassListItem(): void
182+
{
183+
$layoutClassList = [
184+
'id' => 'example_id',
185+
'layoutClassList' => ['class1', 'class2']
186+
];
187+
188+
$this->assertNull(Validators::validateLayoutClassListItem($layoutClassList));
189+
}
190+
191+
public function testInvalidIdType(): void
192+
{
193+
$this->expectException(InvalidArgumentException::class);
194+
$layoutClassList = [
195+
'id' => 123,
196+
'layoutClassList' => ['class1', 'class2']
197+
];
198+
199+
Validators::validateLayoutClassListItem($layoutClassList);
200+
}
201+
202+
public function testMissingLayoutClassList(): void
203+
{
204+
$this->expectException(InvalidArgumentException::class);
205+
$layoutClassList = [
206+
'id' => 'example_id'
207+
];
208+
209+
Validators::validateLayoutClassListItem($layoutClassList);
210+
}
211+
212+
public function testInvalidLayoutClassListType(): void
213+
{
214+
$this->expectException(InvalidArgumentException::class);
215+
$layoutClassList = [
216+
'id' => 'example_id',
217+
'layoutClassList' => 'invalid_class'
218+
];
219+
220+
Validators::validateLayoutClassListItem($layoutClassList);
221+
}
222+
181223
public function resolutionProvider(): array
182224
{
183225
return [

0 commit comments

Comments
 (0)