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\Formatters; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
use PHPUnit\Framework\TestCase; |
16
|
|
|
use RoadBunch\Csv\Formatters\Formatter; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class FormatterTest |
20
|
|
|
* |
21
|
|
|
* @author Dan McAdams |
22
|
|
|
* @package RoadBunch\Csv\Tests\Formatters |
23
|
|
|
*/ |
24
|
|
|
class FormatterTest extends TestCase |
25
|
|
|
{ |
26
|
|
|
public function testArrayOfNonStrings() |
27
|
|
|
{ |
28
|
|
|
$this->expectException(\InvalidArgumentException::class); |
29
|
|
|
|
30
|
|
|
$formatter = new Formatter(function ($var) { |
31
|
|
|
return strtoupper($var); |
32
|
|
|
}); |
33
|
|
|
|
34
|
|
|
$multiArray = [ |
35
|
|
|
['an array'], |
36
|
|
|
new \stdClass(), |
37
|
|
|
$this |
38
|
|
|
]; |
39
|
|
|
$formatter->format($multiArray); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testFormatUpperCase() |
43
|
|
|
{ |
44
|
|
|
$formatter = new Formatter(function ($var) { |
45
|
|
|
return strtoupper($var); |
46
|
|
|
}); |
47
|
|
|
|
48
|
|
|
$testArray = ['one', 'two', 'three']; |
49
|
|
|
$this->assertEquals(['ONE', 'TWO', 'THREE'], $formatter->format($testArray)); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testFormatReplaceUnderscoreWithSpace() |
53
|
|
|
{ |
54
|
|
|
$formatter = new Formatter(function ($var) { |
55
|
|
|
return str_replace('_', ' ', $var); |
56
|
|
|
}); |
57
|
|
|
|
58
|
|
|
$testArray = ['first_name', '1_2_3_4', 'email-address']; |
59
|
|
|
$formattedArray = $formatter->format($testArray); |
60
|
|
|
$this->assertEquals(['first name', '1 2 3 4', 'email-address'], $formattedArray); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|