From d097a872fe83181a5588e43e608a12249db73f2a Mon Sep 17 00:00:00 2001 From: Teromene Date: Mon, 1 Aug 2016 22:10:10 +0200 Subject: [PATCH] Add the basic testing functionnalities --- .gitignore | 1 + lib/Tests.php | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 lib/Tests.php diff --git a/.gitignore b/.gitignore index 9a267f6a..5ad3c0ac 100644 --- a/.gitignore +++ b/.gitignore @@ -227,3 +227,4 @@ pip-log.txt /cache /whitelist.txt DEBUG +phpunit*.phar diff --git a/lib/Tests.php b/lib/Tests.php new file mode 100644 index 00000000..fbe88c88 --- /dev/null +++ b/lib/Tests.php @@ -0,0 +1,99 @@ +setVar(array( + 'iniSettings' => '', + 'constants' => '', + 'included_files' => '', + 'globals' => '$GLOBALS[\'__PHPUNIT_BOOTSTRAP\'] = ' . var_export($GLOBALS['__PHPUNIT_BOOTSTRAP'], TRUE) . ";\n", + )); + } + + + public $bridgeName = ''; + public $parameters; + + public $bridgeDatas = null; + + private static $argNumber = 0; + + public static function setUpBeforeClass() { + + PHPUnit_Framework_Error_Warning::$enabled = FALSE; + PHPUnit_Framework_Error_Notice::$enabled = FALSE; + + ini_set('default_socket_timeout', 30); + + } + + public function setUp() { + + $parameters = []; + + if(method_exists($this, "loadParameters")) { + + $parameters = $this->loadParameters()[BridgeTest::$argNumber]; + + } + + $tested_bridge = Bridge::create($this->bridgeName); + + $tested_bridge->setDatas($parameters); + $this->bridgeDatas = $tested_bridge->getDatas(); + + BridgeTest::$argNumber++; + + } + + const TEST_TITLE = 0; + const TEST_TIMESTAMP = 1; + const TEST_CONTENT = 2; + const TEST_ID = 3; + const TEST_URI = 4; + const TEST_NAME = 5; + + public function defaultTest($datas, $parameters, $minElementCount = -1) { + + $this->assertNotEmpty($datas, "The bridge is returning empty datas"); + $this->assertGreaterThan($minElementCount, count($datas), "There is not enough elements in the bridge"); + + foreach($datas as $row) { + if(in_array(self::TEST_TITLE, $parameters)) { + $this->assertNotEmpty($row->title, "A row hasn't got a title !"); + } + if(in_array(self::TEST_TIMESTAMP, $parameters)) { + $this->assertNotNull($row->timestamp, "A row is missing a timestamp."); + $this->assertNotEquals($row->timestamp, 0, "A row has an invalid timestamp"); + } + if(in_array(self::TEST_CONTENT, $parameters)) { + $this->assertNotEmpty($row->content, "A row doesn't have content !"); + } + if(in_array(self::TEST_ID, $parameters)) { + $this->assertNotNull($row->id, "A row hasn't got an ID !"); + } + if(in_array(self::TEST_URI, $parameters)) { + $this->assertNotEmpty($row->uri, "A row is missing an URI"); + } + if(in_array(self::TEST_NAME, $parameters)) { + $this->assertNotEmpty($row->name, "A row hasn't got a name !"); + } + } + + } + +}