Skip to content

Commit

Permalink
Merge pull request #1 from open-source-contributions/test_improvement
Browse files Browse the repository at this point in the history
Test improvement
  • Loading branch information
DivineOmega authored May 25, 2020
2 parents 7243386 + b4784bf commit 5772d48
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 8 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
language: php
dist: trusty
php:
- '7.1'
- '7.2'
- '7.3'
- '7.4'
install:
- composer update
- composer install
script:
- ./vendor/bin/phpunit --coverage-clover ./tests/Logs/clover.xml
after_script:
- php vendor/bin/php-coveralls -v
- php vendor/bin/php-coveralls -v
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"require-dev": {
"phpunit/phpunit": "^7.0||^8.0",
"fzaninotto/faker": "^1.6",
"php-coveralls/php-coveralls": "^2.0"
"php-coveralls/php-coveralls": "^2.0",
"ext-sqlite3": "*",
"ext-pdo_sqlite": "*"
},
"require": {
"divineomega/uxdm": "^3.0.0",
Expand Down
59 changes: 55 additions & 4 deletions tests/Unit/EloquentDestinationTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace DivineOmega\uxdm\Objects\Tests;

use DivineOmega\uxdm\Objects\DataItem;
use DivineOmega\uxdm\Objects\DataRow;
use DivineOmega\uxdm\Objects\Destinations\EloquentDestination;
Expand All @@ -12,7 +14,7 @@ final class EloquentDestinationTest extends TestCase

private function getDestination()
{
$this->pdo = new PDO('sqlite:'.__DIR__.'/Data/destination.sqlite');
$this->pdo = new \PDO('sqlite:'.__DIR__.'/Data/destination.sqlite');

$sql = 'DROP TABLE IF EXISTS users';
$stmt = $this->pdo->prepare($sql);
Expand All @@ -29,7 +31,7 @@ private function getDestination()

private function createDataRows()
{
$faker = Faker\Factory::create();
$faker = \Faker\Factory::create();

$dataRows = [];

Expand All @@ -46,9 +48,21 @@ private function createDataRows()
return $dataRows;
}

private function createEmptyDataRows()
{
$dataRows = [];

$dataRow = new DataRow();
$dataRow->addDataItem(new DataItem('name'));
$dataRow->addDataItem(new DataItem('value'));
$dataRows[] = $dataRow;

return $dataRows;
}

private function alterDataRows(array $dataRows)
{
$faker = Faker\Factory::create();
$faker = \Faker\Factory::create();

foreach ($dataRows as $dataRow) {
$dataItem = $dataRow->getDataItemByFieldName('value');
Expand All @@ -64,11 +78,36 @@ private function getActualArray()
$stmt = $this->pdo->prepare($sql);
$stmt->execute();

$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$rows = $stmt->fetchAll(\PDO::FETCH_ASSOC);

return $rows;
}

private function getActualEmptyArray()
{
return [
[
'name' => '',
'value' => '',
],
];
}

private function getActualValueArray(array $dataRows)
{
$expectedArray = [];

foreach ($dataRows as $dataRow) {
$expectedArrayRow = [];
foreach ($dataRow->getDataItems() as $dataItem) {
$expectedArrayRow[$dataItem->fieldName] = $dataItem->value;
}
$expectedArray[] = $expectedArrayRow;
}

return $expectedArray;
}

private function getExpectedArray(array $dataRows)
{
$expectedArray = [];
Expand Down Expand Up @@ -100,6 +139,18 @@ public function testPutDataRows()

$this->assertEquals($this->getExpectedArray($dataRows), $this->getActualArray());

$dataRows = $this->createEmptyDataRows();

$destination->putDataRows($dataRows);

$this->assertEquals($this->getExpectedArray($dataRows), $this->getActualEmptyArray());

$dataRows = $this->alterDataRows($dataRows);

$destination->putDataRows($dataRows);

$this->assertEquals($this->getExpectedArray($dataRows), $this->getActualValueArray($dataRows));

$destination->finishMigration();
}
}
2 changes: 2 additions & 0 deletions tests/Unit/EloquentSourceTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace DivineOmega\uxdm\Objects\Tests;

use DivineOmega\uxdm\Objects\Sources\EloquentSource;
use DivineOmega\uxdm\TestClasses\Eloquent\User;
use PHPUnit\Framework\TestCase;
Expand Down

0 comments on commit 5772d48

Please sign in to comment.