-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssocTest.php
More file actions
executable file
·43 lines (35 loc) · 1.33 KB
/
AssocTest.php
File metadata and controls
executable file
·43 lines (35 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace Utopia\Validator;
use PHPUnit\Framework\TestCase;
class AssocTest extends TestCase
{
protected ?Assoc $assoc;
public function setUp(): void
{
$this->assoc = new Assoc();
}
public function tearDown(): void
{
$this->assoc = null;
}
public function testCanValidateAssocArray(): void
{
$this->assertTrue($this->assoc->isValid(['1' => 'a', '0' => 'b', '2' => 'c']));
$this->assertTrue($this->assoc->isValid(['a' => 'a', 'b' => 'b', 'c' => 'c']));
$this->assertTrue($this->assoc->isValid([]));
$this->assertTrue($this->assoc->isValid(['value' => str_repeat('-', 62000)]));
$this->assertTrue($this->assoc->isArray());
$this->assertSame(\Utopia\Validator::TYPE_ARRAY, $this->assoc->getType());
}
public function testCantValidateSequentialArray(): void
{
$this->assertFalse($this->assoc->isValid([0 => 'string', 1 => 'string']));
$this->assertFalse($this->assoc->isValid(['a']));
$this->assertFalse($this->assoc->isValid(['a', 'b', 'c']));
$this->assertFalse($this->assoc->isValid(['0' => 'a', '1' => 'b', '2' => 'c']));
}
public function testCantValidateAssocArrayWithOver65kCharacters(): void
{
$this->assertFalse($this->assoc->isValid(['value' => str_repeat('-', 66000)]));
}
}