Skip to content

Commit d5b86f4

Browse files
committed
Add helper to execute steps
1 parent 4869a79 commit d5b86f4

File tree

5 files changed

+30
-19
lines changed

5 files changed

+30
-19
lines changed

tests/TestCase.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,28 @@
22

33
namespace Tests;
44

5+
use Marquine\Etl\Loaders\Loader;
6+
use Marquine\Etl\Transformers\Transformer;
57
use PHPUnit\Framework\TestCase as BaseTestCase;
68

79
abstract class TestCase extends BaseTestCase
810
{
9-
//
11+
protected function execute($step, $data)
12+
{
13+
if ($step instanceof Transformer) {
14+
$method = 'transform';
15+
}
16+
17+
if ($step instanceof Loader) {
18+
$method = 'load';
19+
}
20+
21+
$step->initialize();
22+
23+
foreach ($data as $row) {
24+
$step->$method($row);
25+
}
26+
27+
$step->finalize();
28+
}
1029
}

tests/Transformers/ConvertCaseTest.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ public function lowercase()
3030

3131
$transformer->options(['mode' => 'lower']);
3232

33-
$transformer->initialize();
34-
35-
array_map([$transformer, 'transform'], $this->data);
33+
$this->execute($transformer, $this->data);
3634

3735
$this->assertEquals($expected, $this->data);
3836
}
@@ -49,9 +47,7 @@ public function uppercase()
4947

5048
$transformer->options(['mode' => 'upper']);
5149

52-
$transformer->initialize();
53-
54-
array_map([$transformer, 'transform'], $this->data);
50+
$this->execute($transformer, $this->data);
5551

5652
$this->assertEquals($expected, $this->data);
5753
}
@@ -68,9 +64,7 @@ public function titlecase()
6864

6965
$transformer->options(['mode' => 'title']);
7066

71-
$transformer->initialize();
72-
73-
array_map([$transformer, 'transform'], $this->data);
67+
$this->execute($transformer, $this->data);
7468

7569
$this->assertEquals($expected, $this->data);
7670
}
@@ -87,9 +81,7 @@ public function custom_columns()
8781

8882
$transformer->options(['columns' => ['name']]);
8983

90-
$transformer->initialize();
91-
92-
array_map([$transformer, 'transform'], $this->data);
84+
$this->execute($transformer, $this->data);
9385

9486
$this->assertEquals($expected, $this->data);
9587
}

tests/Transformers/JsonDecodeTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function default_options()
2828

2929
$transformer = new JsonDecode;
3030

31-
array_map([$transformer, 'transform'], $this->data);
31+
$this->execute($transformer, $this->data);
3232

3333
$this->assertEquals($expected, $this->data);
3434
}
@@ -45,7 +45,7 @@ public function converting_objects_to_associative_arrays()
4545

4646
$transformer->options(['assoc' => true]);
4747

48-
array_map([$transformer, 'transform'], $this->data);
48+
$this->execute($transformer, $this->data);
4949

5050
$this->assertEquals($expected, $this->data);
5151
}
@@ -62,7 +62,7 @@ public function custom_columns()
6262

6363
$transformer->options(['columns' => ['data']]);
6464

65-
array_map([$transformer, 'transform'], $this->data);
65+
$this->execute($transformer, $this->data);
6666

6767
$this->assertEquals($expected, $this->data);
6868
}

tests/Transformers/JsonEncodeTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function default_options()
2828

2929
$transformer = new JsonEncode;
3030

31-
array_map([$transformer, 'transform'], $this->data);
31+
$this->execute($transformer, $this->data);
3232

3333
$this->assertEquals($expected, $this->data);
3434
}
@@ -45,7 +45,7 @@ public function custom_columns()
4545

4646
$transformer->options(['columns' => ['data']]);
4747

48-
array_map([$transformer, 'transform'], $this->data);
48+
$this->execute($transformer, $this->data);
4949

5050
$this->assertEquals($expected, $this->data);
5151
}

tests/Transformers/RenameColumnsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function rename_column()
2525

2626
$transformer->options(['columns' => ['email_address' => 'email']]);
2727

28-
array_map([$transformer, 'transform'], $data);
28+
$this->execute($transformer, $data);
2929

3030
$this->assertEquals($expected, $data);
3131
}

0 commit comments

Comments
 (0)