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

RegexpObscuredStrategyTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 36
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testExtract() 0 11 1
A testHydrate() 0 10 1
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