Skip to content

Commit

Permalink
Add helper to execute steps
Browse files Browse the repository at this point in the history
  • Loading branch information
leomarquine committed Nov 5, 2018
1 parent 4869a79 commit d5b86f4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 19 deletions.
21 changes: 20 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,28 @@

namespace Tests;

use Marquine\Etl\Loaders\Loader;
use Marquine\Etl\Transformers\Transformer;
use PHPUnit\Framework\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
//
protected function execute($step, $data)
{
if ($step instanceof Transformer) {
$method = 'transform';
}

if ($step instanceof Loader) {
$method = 'load';
}

$step->initialize();

foreach ($data as $row) {
$step->$method($row);
}

$step->finalize();
}
}
16 changes: 4 additions & 12 deletions tests/Transformers/ConvertCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ public function lowercase()

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

$transformer->initialize();

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

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

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

$transformer->initialize();

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

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

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

$transformer->initialize();

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

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

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

$transformer->initialize();

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

$this->assertEquals($expected, $this->data);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Transformers/JsonDecodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function default_options()

$transformer = new JsonDecode;

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

$this->assertEquals($expected, $this->data);
}
Expand All @@ -45,7 +45,7 @@ public function converting_objects_to_associative_arrays()

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

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

$this->assertEquals($expected, $this->data);
}
Expand All @@ -62,7 +62,7 @@ public function custom_columns()

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

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

$this->assertEquals($expected, $this->data);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Transformers/JsonEncodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function default_options()

$transformer = new JsonEncode;

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

$this->assertEquals($expected, $this->data);
}
Expand All @@ -45,7 +45,7 @@ public function custom_columns()

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

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

$this->assertEquals($expected, $this->data);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Transformers/RenameColumnsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function rename_column()

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

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

$this->assertEquals($expected, $data);
}
Expand Down

0 comments on commit d5b86f4

Please sign in to comment.