123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- <?php
- use Luticate\Utils\Controller\LuticateApplication;
- use Illuminate\Database\Capsule\Manager as Capsule;
- use Luticate\Utils\DataAccess\LuDataAccess;
- use Luticate\Utils\DataAccess\PgSqlDataAccess;
- use Luticate\Utils\Dbo\LuDbo;
- use Luticate\Utils\Dbo\LuDboDeserializeException;
-
- /**
- * Created by PhpStorm.
- * User: robin
- * Date: 6/7/16
- * Time: 2:57 PM
- */
-
- class TestTableDbo extends LuDbo
- {
- /**
- * @var $_id int
- */
- private $_id;
-
- /**
- * @var $_someText string
- */
- private $_someText;
-
- /**
- * @var $_someIntegerArray int[]
- */
- private $_someIntegerArray;
-
- /**
- * @return int
- */
- public function getId()
- {
- return $this->_id;
- }
-
- /**
- * @param int $id
- */
- public function setId($id)
- {
- $this->_id = $id;
- }
-
- /**
- * @return string
- */
- public function getSomeText()
- {
- return $this->_someText;
- }
-
- /**
- * @param string $someText
- */
- public function setSomeText($someText)
- {
- $this->_someText = $someText;
- }
-
- /**
- * @return int[]
- */
- public function getSomeIntegerArray()
- {
- return $this->_someIntegerArray;
- }
-
- /**
- * @param int[] $someIntegerArray
- */
- public function setSomeIntegerArray($someIntegerArray)
- {
- $this->_someIntegerArray = $someIntegerArray;
- }
- }
-
- class TestTableDboArray extends LuDbo
- {
- /**
- * @var TestTableDbo[]
- */
- protected $_array;
- public function getArray()
- {
- return $this->_array;
- }
- public function setArray($value)
- {
- $this->_array = $value;
- }
-
- public function jsonSerialize()
- {
- return $this->_array;
- }
-
- public static function jsonDeserialize($json)
- {
- if (!is_array($json)) {
- throw new LuDboDeserializeException("Invalid array value");
- }
- $dbo = new static();
- $array = [];
- foreach ($json as $data) {
- $array[] = TestTableDbo::jsonDeserialize($data);
- }
- $dbo->setArray($array);
- return $dbo;
- }
-
- public static function generateSample()
- {
- return [
- TestTableDbo::generateSample(),
- TestTableDbo::generateSample()
- ];
- }
-
- }
-
- class TestTableDataAccess extends LuDataAccess
- {
- protected static $_connection = "mydb";
- protected static $_table = "test_table";
- protected static $_dboClass = TestTableDbo::class;
- protected static $_dboArrayClass = TestTableDboArray::class;
- }
-
- class DatabaseTest extends \PHPUnit_Framework_TestCase
- {
- public function testSetup()
- {
- // $config = ['databases' => [
- // [
- // 'name' => 'mydb',
- // 'driver' => 'pgsql',
- // 'host' => '172.17.0.1',
- // 'database' => 'intra_betaclean',
- // 'username' => 'dev',
- // 'password' => 'dev'
- // ]
- // ]];
- // $app = new LuticateApplication($config);
- // $app->setupDatabases();
-
- // $dbo = new TestTableDbo();
- // $dbo->setId(11);
- // $dbo->setSomeIntegerArray('{}');
- // $dbo->setSomeText("lol2");
-
- // var_dump(TestTableDataAccess::getSingleById(1));
- // var_dump(TestTableDataAccess::deleteMultiple(function($q)
- // {
- // return $q->where("some_text", "=", "lol");
- // }));
- // var_dump(TestTableDataAccess::addSingleId($dbo));
- // var_dump(TestTableDataAccess::addSingle($dbo, ['Id']));
- // var_dump(TestTableDataAccess::editSingleById($dbo));
- // var_dump(TestTableDataAccess::editMultiple($dbo, function($q)
- // {
- // return $q->where("some_text", "like", "lol%");
- // }, ['Id']));
-
-
- // $pdo = TestTableDataAccess::getPdo();
- // $pgsql = new PgSqlDataAccess();
- // $pgsql->getStoredProceduresFull($pdo);
- // var_dump($pgsql->getStoredProceduresFull($pdo));
- }
- }
|