-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathBetweenTest.php
More file actions
58 lines (48 loc) · 2.21 KB
/
BetweenTest.php
File metadata and controls
58 lines (48 loc) · 2.21 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace Rakit\Validation\Tests\Rules;
use Rakit\Validation\Rules\Between;
use PHPUnit\Framework\TestCase;
class BetweenTest extends TestCase
{
public function setUp()
{
$this->rule = new Between;
}
public function testValids()
{
$this->assertTrue($this->rule->fillParameters([6, 10])->check('foobar'));
$this->assertTrue($this->rule->fillParameters([6, 10])->check('футбол'));
$this->assertTrue($this->rule->fillParameters([2, 3])->check([1,2,3]));
$this->assertTrue($this->rule->fillParameters([100, 150])->check(123));
$this->assertTrue($this->rule->fillParameters([100, 150])->check(123.4));
}
public function testInvalids()
{
$this->assertFalse($this->rule->fillParameters([2, 5])->check('foobar'));
$this->assertFalse($this->rule->fillParameters([2, 5])->check('футбол'));
$this->assertFalse($this->rule->fillParameters([4, 6])->check([1,2,3]));
$this->assertFalse($this->rule->fillParameters([50, 100])->check(123));
$this->assertFalse($this->rule->fillParameters([50, 100])->check(123.4));
}
public function testUploadedFileValue()
{
$mb = function ($n) {
return $n * 1024 * 1024;
};
$sampleFile = [
'name' => pathinfo(__FILE__, PATHINFO_BASENAME),
'type' => 'text/plain',
'size' => $mb(2),
'tmp_name' => __FILE__,
'error' => 0
];
$this->assertTrue($this->rule->fillParameters([$mb(2), $mb(5)])->check($sampleFile));
$this->assertTrue($this->rule->fillParameters(['2M', '5M'])->check($sampleFile));
$this->assertTrue($this->rule->fillParameters([$mb(1), $mb(2)])->check($sampleFile));
$this->assertTrue($this->rule->fillParameters(['1M', '2M'])->check($sampleFile));
$this->assertFalse($this->rule->fillParameters([$mb(2.1), $mb(5)])->check($sampleFile));
$this->assertFalse($this->rule->fillParameters(['2.1M', '5M'])->check($sampleFile));
$this->assertFalse($this->rule->fillParameters([$mb(1), $mb(1.9)])->check($sampleFile));
$this->assertFalse($this->rule->fillParameters(['1M', '1.9M'])->check($sampleFile));
}
}