|
3 | 3 | namespace Tests\Transformers;
|
4 | 4 |
|
5 | 5 | use Tests\TestCase;
|
| 6 | +use Marquine\Etl\Row; |
6 | 7 | use Marquine\Etl\Transformers\JsonEncode;
|
7 | 8 |
|
8 | 9 | class JsonEncodeTest extends TestCase
|
9 | 10 | {
|
10 |
| - protected $data = [ |
11 |
| - ['id' => '1', 'data' => ['name' => 'John Doe', 'email' => 'johndoe@email.com']], |
12 |
| - ['id' => '2', 'data' => ['name' => 'Jane Doe', 'email' => 'janedoe@email.com']], |
13 |
| - ]; |
| 11 | + protected function setUp() |
| 12 | + { |
| 13 | + parent::setUp(); |
| 14 | + |
| 15 | + $this->data = [ |
| 16 | + new Row(['id' => '1', 'data' => ['name' => 'John Doe', 'email' => 'johndoe@email.com']]), |
| 17 | + new Row(['id' => '2', 'data' => ['name' => 'Jane Doe', 'email' => 'janedoe@email.com']]), |
| 18 | + ]; |
| 19 | + } |
14 | 20 |
|
15 | 21 | /** @test */
|
16 | 22 | public function default_options()
|
17 | 23 | {
|
18 | 24 | $expected = [
|
19 |
| - ['id' => '"1"', 'data' => '{"name":"John Doe","email":"johndoe@email.com"}'], |
20 |
| - ['id' => '"2"', 'data' => '{"name":"Jane Doe","email":"janedoe@email.com"}'], |
| 25 | + new Row(['id' => '"1"', 'data' => '{"name":"John Doe","email":"johndoe@email.com"}']), |
| 26 | + new Row(['id' => '"2"', 'data' => '{"name":"Jane Doe","email":"janedoe@email.com"}']), |
21 | 27 | ];
|
22 | 28 |
|
23 | 29 | $transformer = new JsonEncode;
|
24 | 30 |
|
25 |
| - $this->assertEquals($expected, array_map($transformer->transform(), $this->data)); |
| 31 | + array_map([$transformer, 'transform'], $this->data); |
| 32 | + |
| 33 | + $this->assertEquals($expected, $this->data); |
26 | 34 | }
|
27 | 35 |
|
28 | 36 | /** @test */
|
29 | 37 | public function custom_columns()
|
30 | 38 | {
|
31 | 39 | $expected = [
|
32 |
| - ['id' => '1', 'data' => '{"name":"John Doe","email":"johndoe@email.com"}'], |
33 |
| - ['id' => '2', 'data' => '{"name":"Jane Doe","email":"janedoe@email.com"}'], |
| 40 | + new Row(['id' => '1', 'data' => '{"name":"John Doe","email":"johndoe@email.com"}']), |
| 41 | + new Row(['id' => '2', 'data' => '{"name":"Jane Doe","email":"janedoe@email.com"}']), |
34 | 42 | ];
|
35 | 43 |
|
36 | 44 | $transformer = new JsonEncode;
|
37 | 45 |
|
38 | 46 | $transformer->options(['columns' => ['data']]);
|
39 | 47 |
|
40 |
| - $this->assertEquals($expected, array_map($transformer->transform(), $this->data)); |
| 48 | + array_map([$transformer, 'transform'], $this->data); |
| 49 | + |
| 50 | + $this->assertEquals($expected, $this->data); |
41 | 51 | }
|
42 | 52 | }
|
0 commit comments