Completed
Push — master ( 0456c5...25ee32 )
by Oleg
04:45
created

RegexpObscuredStrategyTest::testHydrate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace DataFlow\Tests\Unit\Doctrine\Hydrator\Strategy;
5
6
use SlayerBirden\DataFlowServer\Doctrine\Hydrator\Strategy\RegexpObscuredStrategy;
7
use Zend\Hydrator\HydratorInterface;
8
use Zend\Hydrator\ObjectProperty;
9
10
class Unit
11
{
12
    public $name;
13
    public $code;
14
}
15
16
final class RegexpObscuredStrategyTest extends \Codeception\Test\Unit
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
17
{
18
    /**
19
     * @var HydratorInterface
20
     */
21
    private $hydrator;
22
23
    protected function setUp()
24
    {
25
        $this->hydrator = new ObjectProperty();
26
        $this->hydrator->addStrategy('code', new RegexpObscuredStrategy('/[abc]{2}/', '**'));
27
    }
28
29
    public function testExtract(): void
30
    {
31
        $obj = new Unit();
32
        $obj->name = 'Alfred';
33
        $obj->code = 'abruptly';
34
35
        $this->assertSame([
36
            'name' => 'Alfred',
37
            'code' => '**ruptly',
38
        ], $this->hydrator->extract($obj));
39
    }
40
41
    public function testHydrate(): void
42
    {
43
        $obj = new Unit();
44
        $obj->name = 'Alfred';
45
        $obj->code = 'aa';
46
        $this->assertEquals($obj, $this->hydrator->hydrate([
47
            'name' => 'Alfred',
48
            'code' => 'aa',
49
        ], new Unit()));
50
    }
51
}
52