Passed
Push — master ( 14b05a...fa6902 )
by Daniel
02:41
created

FormatterTest::testFormatArrayStrings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
/**
4
 * This file is part of the Csv-Machine package.
5
 *
6
 * (c) Dan McAdams <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace RoadBunch\Csv\Tests\Formatter;
13
14
15
use function foo\func;
16
use PHPUnit\Framework\TestCase;
17
use RoadBunch\Csv\Exception\FormatterResultException;
18
use RoadBunch\Csv\Formatter\Formatter;
19
20
/**
21
 * Class FormatterTest
22
 *
23
 * @author  Dan McAdams
24
 * @package RoadBunch\Csv\Tests\Formatters
25
 */
26
class FormatterTest extends TestCase
27
{
28
    public function testArrayOfNonStrings()
29
    {
30
        $this->expectException(\InvalidArgumentException::class);
31
32
        $formatter = new Formatter(function ($var) {
33
            return strtoupper($var);
34
        });
35
36
        $multiArray = [
37
            ['an array'],
38
            new \stdClass(),
39
            $this
40
        ];
41
        $formatter->format($multiArray);
42
    }
43
44
    public function testFormatArrayStrings()
45
    {
46
        $formatter = new Formatter(function ($var) {
47
            return strtoupper($var);
48
        });
49
50
        $testArray = ['one', 'two', 'three'];
51
        $this->assertEquals(['ONE', 'TWO', 'THREE'], $formatter->format($testArray));
52
    }
53
54
    public function testFormatterReturnsNonArray()
55
    {
56
        $this->expectException(FormatterResultException::class);
57
        $formatter = new Formatter(function ($var) {
58
            return explode('_', $var);
59
        });
60
61
        $testArray = ['first_name'];
62
        $formatter->format($testArray);
63
    }
64
}
65