Testreihe für die Datenbank-Klasse hinzu gefügt
authorMarkus Bröker <broeker.markus@googlemail.com>
Fri, 13 Nov 2015 17:01:04 +0100
changeset 12 66b604c61e62
parent 11 16e5372a872e
child 13 4690a1ccb7cc
Testreihe für die Datenbank-Klasse hinzu gefügt
.idea/php.xml
config/config.php
config/log4php.xml
data/import/test_users.csv
tests/bfw/DatabaseTest.php
--- a/.idea/php.xml
+++ b/.idea/php.xml
@@ -1,4 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
   <component name="PhpProjectSharedConfiguration" php_language_level="5.4.0" />
+  <component name="PhpUnit">
+    <phpunit_settings>
+      <PhpUnitSettings />
+    </phpunit_settings>
+  </component>
 </project>
\ No newline at end of file
--- a/config/config.php
+++ b/config/config.php
@@ -18,7 +18,7 @@
     $classPath = sprintf('classes/%s.php', $nsClass);
 
     if (file_exists($filename)) {
-        require_once "$classPath";
+        require_once BFW_PATH . "/$classPath";
 
         return true;
     }
@@ -26,7 +26,7 @@
     return false;
 }
 
-require_once 'library/log4php/Logger.php';
+require_once BFW_PATH . '/library/log4php/Logger.php';
 Logger::configure(BFW_PATH . '/config/log4php.xml');
 
 spl_autoload_register('bfw_autoLoader');
--- a/config/log4php.xml
+++ b/config/log4php.xml
@@ -2,7 +2,7 @@
 <configuration xmlns="http://logging.apache.org/log4php/">
     <appender name="default" class="LoggerAppenderFile">
         <layout class="LoggerLayoutSimple"/>
-        <param name="file" value="/var/www/vhosts/TicketSystem/logs/bfw.log"/>
+        <param name="file" value="/var/www/vhosts/BFW_APP/logs/bfw.log"/>
         <param name="append" value="true"/>
     </appender>
     <root>
--- a/data/import/test_users.csv
+++ b/data/import/test_users.csv
@@ -1,12 +1,2 @@
 group_id;username;password;firstname;lastname
-3;manager1@testbox.de;098f6bcd4621d373cade4e832627b4f6;Manager1;Testbox
-4;supporter1@testbox.de;098f6bcd4621d373cade4e832627b4f6;supporter1;Testbox
-4;supporter2@testbox.de;098f6bcd4621d373cade4e832627b4f6;supporter2;Testbox
-4;supporter3@testbox.de;098f6bcd4621d373cade4e832627b4f6;supporter3;Testbox
-4;supporter4@testbox.de;098f6bcd4621d373cade4e832627b4f6;supporter4;Testbox
-4;supporter5@testbox.de;098f6bcd4621d373cade4e832627b4f6;supporter5;Testbox
-4;supporter6@testbox.de;098f6bcd4621d373cade4e832627b4f6;supporter6;Testbox
-4;supporter7@testbox.de;098f6bcd4621d373cade4e832627b4f6;supporter7;Testbox
-4;supporter8@testbox.de;098f6bcd4621d373cade4e832627b4f6;supporter8;Testbox
-4;supporter9@testbox.de;098f6bcd4621d373cade4e832627b4f6;supporter9;Testbox
-4;supporter10@testbox.de;098f6bcd4621d373cade4e832627b4f6;supporter10;Testbox
+3;test1@testbox.de;098f6bcd4621d373cade4e832627b4f6;Test1;Testbox
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/tests/bfw/DatabaseTest.php
@@ -0,0 +1,52 @@
+<?php
+
+require_once '../../config/config.php';
+
+use bfw\database\Database;
+
+class DatabaseTest extends \PHPUnit_Framework_TestCase {
+    private $object;
+
+    public function __construct() {
+        $this->object = Database::getInstance();
+    }
+
+    public function testStore() {
+        $data = array();
+        $data['password'] = md5(rand(0, 255));
+
+        $result = $this->object->store('t_user', 1, $data);
+        $this->assertTrue($result !== false);
+    }
+
+    public function testFetch() {
+        $data = $this->object->fetch('t_user', 'id = 1');
+
+        $this->assertEquals('system@testbox.de', $data['username']);
+    }
+
+    public function testFetchAll() {
+        $data = $this->object->fetchAll('t_user', 'id < 3');
+
+        $this->assertTrue(is_array($data));
+
+        foreach ($data as $row) {
+            echo sprintf("%s\n", implode(', ', $row));
+        }
+    }
+
+    public function testFind() {
+        $data = $this->object->find('t_user', -1);
+        $this->assertEquals(null, $data);
+
+        $data = $this->object->find('t_user', 1);
+        $this->assertEquals(1, $data['id']);
+    }
+
+    public function testFindAll() {
+        $data1 = $this->object->findAll('t_user', true);
+        $data2 = $this->object->findAll('t_user', false);
+
+        $this->assertTrue(count($data1) != count($data2));
+    }
+}