|
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
|
|
|
|