Completed
Push — master ( 644c62...cdc390 )
by Max
01:16
created

UpdateHelperTest::testUpdate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 9.488
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 *  @copyright (c) 2019 Mendel <[email protected]>
5
 *  @license see license.txt
6
 */
7
8
namespace drycart\data\tests;
9
10
use drycart\data\UpdateHelper;
11
12
/**
13
 * Description of UpdateHelperTest
14
 *
15
 * @author mendel
16
 */
17
class UpdateHelperTest extends \PHPUnit\Framework\TestCase
18
{
19
    public function testUpdate()
20
    {
21
        $data = new \ArrayObject([
22
            'a'=>1,
23
            'b'=>100,
24
            'c'=>-100,
25
            'd'=>100500,
26
            'e'=>10,
27
        ]);
28
    
29
        UpdateHelper::updateAllFields($data, [
30
            'a'=>2,
31
            'set:b'=>0,
32
            'min:c'=>0,
33
            'max:d'=>100,
34
            'sum:e'=>5
35
        ]);
36
        
37
        $this->assertEquals(2, $data['a']);
38
        $this->assertEquals(0, $data['b']);
39
        $this->assertEquals(-100, $data['c']);
40
        $this->assertEquals(100500, $data['d']);
41
        $this->assertEquals(15, $data['e']);
42
        
43
        $this->expectException(\Exception::class);
44
        UpdateHelper::updateField($data, 'someValue', 'notExistRule:', 'a');
45
    }
46
}
47