summaryrefslogtreecommitdiffstats
path: root/tests/TestDataHelper.php
diff options
context:
space:
mode:
authorsten <stenmarsh938@gmail.com>2016-03-17 12:54:26 +0300
committersten <stenmarsh938@gmail.com>2016-03-17 12:54:26 +0300
commit61650522ee83433656535a48dde9be2d9b86bd35 (patch)
treebe9b527234c88394c2d2ad92c27f7dd72a4610f3 /tests/TestDataHelper.php
parent888ede15fc86db7001fa4d28bc2a686ed41315a3 (diff)
downloadscheduler-helper-php-61650522ee83433656535a48dde9be2d9b86bd35.zip
scheduler-helper-php-61650522ee83433656535a48dde9be2d9b86bd35.tar.gz
scheduler-helper-php-61650522ee83433656535a48dde9be2d9b86bd35.tar.bz2
initialLoad
Diffstat (limited to 'tests/TestDataHelper.php')
-rw-r--r--tests/TestDataHelper.php83
1 files changed, 83 insertions, 0 deletions
diff --git a/tests/TestDataHelper.php b/tests/TestDataHelper.php
new file mode 100644
index 0000000..7f9f8d9
--- /dev/null
+++ b/tests/TestDataHelper.php
@@ -0,0 +1,83 @@
+<?php
+require_once "TestConfig.php";
+
+class TestDataHelper
+{
+ const DATA_FOLDER_PREFIX = "Data_";
+ const SOURCE_NAME = "source.json";
+ const TARGET_NAME = "target.json";
+
+ private $_dataFolder;
+
+ private function getJSONDataFromFile($name, $type)
+ {
+ $file = dirname(__FILE__) . "/" . $this->_dataFolder . "/" . $name . "/" . $type;
+ if (!file_exists($file)) return null;
+
+ return json_decode(file_get_contents($file));
+ }
+
+ public function __construct($testName)
+ {
+ $this->_dataFolder = self::DATA_FOLDER_PREFIX . $testName;
+ }
+
+ public function getTestDataList()
+ {
+ $dir = dirname(__FILE__) . "/" . $this->_dataFolder;
+ if (!file_exists($dir)) return null;
+ $folderItems = scandir($dir);
+ $folders = array();
+ foreach ($folderItems as $item) {
+ if ($item === '.' || $item === '..') continue;
+ if (is_dir($dir . "/" . $item))
+ array_push($folders, $item);
+ }
+ return $folders;
+ }
+
+ public function getTestSourceData($name)
+ {
+ return $this->getJSONDataFromFile($name, self::SOURCE_NAME);
+ }
+
+ public function getTestTargetData($name)
+ {
+ return $this->getJSONDataFromFile($name, self::TARGET_NAME);
+ }
+
+ public function compareDataObjects($helperObj, $schedObj, $fields)
+ {
+ foreach($fields as $key=>$value){
+ print($helperObj[$key]." _ ".$schedObj -> {$key}."\n");
+ if($helperObj[$key] !== $schedObj -> {$key})
+ return false;
+ }
+ return true;
+ }
+
+ public function compareDataBunches($helperData, $schedData, $fields)
+ {
+ $helpLength = count($helperData);
+ $schedLength = count($schedData);
+
+ if($helpLength != $schedLength) return false;
+
+ for($i = 0; $i < $helpLength; $i++){
+ $objHasSame = false;
+ for($j = 0; $j < $schedLength; $j++){
+ if($this->compareDataObjects($helperData[$i], $schedData[$j], $fields)) {
+ array_splice($schedData, $j, 1);
+ $schedLength = count($schedData);
+ $objHasSame = true;
+ break;
+ }
+ }
+ if(!$objHasSame){
+ return false;
+ }
+ }
+
+ return true;
+ }
+} \ No newline at end of file