ExporterTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 4
eloc 31
c 4
b 0
f 1
dl 0
loc 50
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testExport() 0 5 1
A attributesToExport() 0 10 1
A expectedExport() 0 13 1
A exportable() 0 12 1
1
<?php
2
3
namespace MathieuTu\Exporter\Tests;
4
5
use MathieuTu\Exporter\Tests\Fixtures\Model;
6
use PHPUnit\Framework\TestCase;
7
8
class ExporterTest extends TestCase
9
{
10
    public function testExport()
11
    {
12
        $this->assertSame(
13
            $this->expectedExport(),
14
            $this->exportable()->export($this->attributesToExport())->toArray()
15
        );
16
    }
17
18
    protected function expectedExport(): array
19
    {
20
        return [
21
            'test' => 'testTUDISCO',
22
            'bar' => ['bar2' => 'testBar2'],
23
            'bar.bar1' => 'testBar1',
24
            'foobar' => 'testFooBar2',
25
            'baz' => [
26
                ['baz1' => 'baz1A', 'baz3' => 'baz3A'],
27
                ['baz1' => 'baz1B', 'baz3' => 'baz3B'],
28
                ['baz1' => 'baz1C', 'baz3' => 'baz3C'],
29
            ],
30
            'otherProperty' => ['otherPropery1' => 'testOtherProperty1'],
31
        ];
32
    }
33
34
    protected function exportable(): Model
35
    {
36
        return new Model([
37
            'foo' => 'testFoo',
38
            'bar' => ['bar1' => 'testBar1', 'bar2' => 'testBar2'],
39
            'foobar' => ['foobar1' => 'testFooBar1', 'foobar2' => 'testFooBar2'],
40
            'baz' => [
41
                ['baz1' => 'baz1A', 'baz2' => 'baz2A', 'baz3' => 'baz3A'],
42
                ['baz1' => 'baz1B', 'baz2' => 'baz2B', 'baz3' => 'baz3B'],
43
                ['baz1' => 'baz1C', 'baz2' => 'baz2C', 'baz3' => 'baz3C'],
44
            ],
45
        ], ['otherPropery1' => 'testOtherProperty1', 'otherPropery2' => 'testOtherProperty2']);
46
    }
47
48
    protected function attributesToExport(): array
49
    {
50
        return [
51
            'test(Mathieu)',
52
            'test(TUDISCO)',
53
            'bar' => ['bar2'],
54
            'bar.bar1',
55
            'foobar' => 'foobar2',
56
            'baz' => ['*' => ['baz1', 'baz3']],
57
            'otherProperty' => ['otherPropery1'],
58
        ];
59
    }
60
}
61