Passed
Pull Request — master (#415)
by
unknown
29:22 queued 26:39
created

ValidationContextTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstructor() 0 9 1
A testGetParameter() 0 7 1
A testSetParameter() 0 6 1
A testDefault() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Tests;
6
7
use PHPUnit\Framework\TestCase;
8
use Yiisoft\Validator\DataSet\ArrayDataSet;
9
use Yiisoft\Validator\Tests\Support\ValidatorFactory;
10
use Yiisoft\Validator\ValidationContext;
11
12
final class ValidationContextTest extends TestCase
13
{
14
    public function testDefault(): void
15
    {
16
        $context = new ValidationContext(ValidatorFactory::make());
17
        $this->assertNull($context->getDataSet());
18
        $this->assertNull($context->getAttribute());
19
        $this->assertSame([], $context->getParameters());
20
    }
21
22
    public function testConstructor(): void
23
    {
24
        $dataSet = new ArrayDataSet();
25
26
        $context = new ValidationContext(ValidatorFactory::make(), $dataSet, 'name', ['key' => 42]);
27
28
        $this->assertSame($dataSet, $context->getDataSet());
29
        $this->assertSame('name', $context->getAttribute());
30
        $this->assertSame(['key' => 42], $context->getParameters());
31
    }
32
33
    public function testSetParameter(): void
34
    {
35
        $context = new ValidationContext(ValidatorFactory::make());
36
        $context->setParameter('key', 42);
37
38
        $this->assertSame(['key' => 42], $context->getParameters());
39
    }
40
41
    public function testGetParameter(): void
42
    {
43
        $context = new ValidationContext(ValidatorFactory::make(), null, null, ['key' => 42]);
44
45
        $this->assertSame(42, $context->getParameter('key'));
46
        $this->assertNull($context->getParameter('non-exists'));
47
        $this->assertSame(7, $context->getParameter('non-exists', 7));
48
    }
49
}
50