コード例 #1
0
ファイル: ModelFindersTest.php プロジェクト: scandio/troba
 public function testOtherFind()
 {
     $pq = EQM::query(Project::class)->where('companyId = ?', 2)->result();
     $pm = Project::findByCompanyId(2);
     $this->assertEquals($pq->count(), $pm->count());
     $this->assertEquals($pq->one()->name, $pm->one()->name);
 }
コード例 #2
0
ファイル: EQMQueryObjectTest.php プロジェクト: scandio/troba
 public function testAliasing()
 {
     $result = EQM::query()->select('*')->from('Company Firma')->where('Firma.id = ?', 2)->result()->one();
     $this->assertEquals(2, $result->id);
     $result = EQM::query('Company Firma')->innerJoin('Project Projekt', 'Firma.id = Projekt.companyId')->innerJoin('ProjectActivity Aktivitaet', 'Projekt.id = Aktivitaet.projectId')->where('Aktivitaet.id = :id', ['id' => 100])->groupBy('Firma.id')->result();
     $this->assertEquals(27, $result->count());
 }
コード例 #3
0
ファイル: ResultSetArrayTest.php プロジェクト: scandio/troba
 public function testResult()
 {
     $result = EQM::query(Company::class)->result();
     $count = $result->count();
     $all = $result->all();
     $this->assertEquals($all, $all->all());
     $this->assertInstanceOf(Company::class, $all->one());
     $this->assertEquals($all->count(), $count);
 }
コード例 #4
0
ファイル: EQMUpdateTest.php プロジェクト: scandio/troba
 public function testUpdateError()
 {
     $c = new Company();
     try {
         EQM::update($c);
         $r = true;
     } catch (EQMException $e) {
         $r = false;
     }
     $this->assertFalse($r);
 }
コード例 #5
0
ファイル: Persisters.php プロジェクト: scandio/troba
 /**
  * saves a record with a auto increment primary key which means if the key is null
  * it will be inserted and if a key exists it will be updated
  *
  * @return bool|object
  * @throws EQMException
  */
 public function save()
 {
     $tableMeta = EQM::tableMeta(get_class($this));
     if ($tableMeta->hasAutoIncrement()) {
         if (empty($this->{$tableMeta->getAutoIncrement()})) {
             return $this->insert();
         } else {
             return $this->update();
         }
     } else {
         throw new EQMException('save() is not possible for entities without auto increment primary key', 10001);
     }
 }
コード例 #6
0
ファイル: EQMInitializeTest.php プロジェクト: scandio/troba
 public function testInitialize()
 {
     try {
         EQM::initialize(null, [], 'test0');
     } catch (EQMException $e) {
         $this->assertEquals($e->getMessage(), 'The given paramter is not a valid PDO connection object');
     }
     EQM::initialize(new \PDO('mysql:host=localhost;dbname=orm_test', 'root', 'root'), [], 'test1');
     $this->assertTrue(EQM::isInitialized('test1'));
     EQM::initialize(new \PDO('mysql:host=localhost;dbname=orm_test', 'root', 'root'), [EQM::CONVENTION_HANDLER => new ClassicConventionHandler()], 'test2');
     $this->assertTrue(EQM::isInitialized('test2'));
     EQM::initialize(new \PDO('mysql:host=localhost;dbname=orm_test', 'root', 'root'), [EQM::SQL_BUILDER => new MySqlBuilder()], 'test3');
     $this->assertTrue(EQM::isInitialized('test3'));
 }
コード例 #7
0
ファイル: EQMTransactionTest.php プロジェクト: scandio/troba
 public function testComplex()
 {
     $companies = EQM::queryByArray(['entity' => 'Company']);
     $count = $companies->count();
     EQM::begin();
     foreach ($companies as $company) {
         $company->remark = 'Transaction remark';
         EQM::update($company);
         $projects = EQM::queryByArray(['entity' => Project::class, 'query' => 'id = ?', 'params' => $company->id]);
         foreach ($projects as $project) {
             $project->value = 999.99;
             EQM::update($project);
         }
     }
     EQM::rollBack();
     $companyCount = EQM::queryByArray(['entity' => 'Company'])->count();
     $this->assertEquals($count, $companyCount);
     $companies = EQM::queryByArray(['entity' => 'Company', 'query' => 'remark = ?', 'params' => 'Transaction remark']);
     $this->assertEquals(0, $companies->count());
 }
コード例 #8
0
ファイル: EQMInsertTest.php プロジェクト: scandio/troba
 public function testInsertError()
 {
     $c = new Company();
     try {
         EQM::insert($c);
         $r = true;
     } catch (EQMException $e) {
         $r = false;
     }
     $this->assertFalse($r);
     $c = new Bootstrap\Company();
     try {
         EQM::insert($c);
         $r = true;
     } catch (EQMException $e) {
         $r = false;
     }
     $this->assertFalse($r);
     $c->name = null;
     $c->remark = 'no no not good';
     try {
         EQM::insert($c);
         $r = true;
     } catch (EQMException $e) {
         $r = false;
     }
     $this->assertFalse($r);
     $p = new Project();
     try {
         EQM::insert($p);
         $r = true;
     } catch (EQMException $e) {
         $r = false;
     }
     $this->assertFalse($r);
     $p->id = null;
     $p->name = 'not good as I said';
     $p->value = 999;
     try {
         EQM::insert($p);
         $r = true;
     } catch (EQMException $e) {
         $r = false;
     }
     $this->assertFalse($r);
     $p->companyId = 1;
     $p->name = 'not good as I said';
     $p->value = 9999;
     try {
         EQM::insert($p);
         $r = true;
     } catch (EQMException $e) {
         $r = false;
     }
     $this->assertFalse($r);
 }
コード例 #9
0
ファイル: Queries.php プロジェクト: scandio/troba
 /**
  * @return \troba\EQM\Query query object of the called class
  */
 public static function query()
 {
     return EQM::query(get_called_class());
 }
コード例 #10
0
ファイル: EQMQueryArrayTest.php プロジェクト: scandio/troba
 public function testQueryWithOrder()
 {
     $this->assertEquals(CNT_COMPANY, EQM::queryByArray(['entity' => \Bootstrap\Project::class, 'order' => 'companyId DESC'])->one()->companyId);
     $this->assertEquals(CNT_COMPANY, EQM::queryByArray(['entity' => AnotherCompany::class, 'order' => 'AnotherCompany.id DESC'])->one()->id);
     $this->assertEquals(1, EQM::queryByArray(['entity' => \Bootstrap\Project::class, 'order' => 'companyId'])->one()->companyId);
 }
コード例 #11
0
ファイル: bootstrap.php プロジェクト: scandio/troba
function generate($max_i, $max_j, $max_k)
{
    $c = new Company();
    for ($i = 0; $i < $max_i; $i++) {
        $c->name = (isset($c->id) ? $c->id + 1 : 1) . ' A Company Name';
        $c->remark = 'A remark for a company with the name ' . $c->name;
        EQM::insert($c);
        $p = new Project();
        for ($j = 0; $j < $max_j; $j++) {
            $p->id = $c->id . '_' . ($j + 1) . '_PROJECT';
            $p->companyId = $c->id;
            $p->name = 'A project with the id ' . $p->id;
            $p->value = $j % 10 * 100 + $c->id % $j / $j;
            EQM::insert($p);
            $pa = new ProjectActivity();
            for ($k = 0; $k < $max_k; $k++) {
                $pa->id = 100 + $k;
                $pa->projectId = $p->id;
                $pa->name = 'Activity for ' . $p->id . ' with ' . $pa->id;
                EQM::insert($pa);
            }
        }
    }
}
コード例 #12
0
ファイル: EQMDeleteTest.php プロジェクト: scandio/troba
 public function testDeleteError()
 {
     $company = new Company();
     try {
         EQM::delete($company);
         $r = true;
     } catch (EQMException $e) {
         $r = false;
     }
     $this->assertFalse($r);
     $projectActivity = new ProjectActivity();
     try {
         EQM::delete($projectActivity);
         $r = true;
     } catch (EQMException $e) {
         $r = false;
     }
     $this->assertFalse($r);
     $projectActivity->id = 999;
     try {
         EQM::delete($projectActivity);
         $r = true;
     } catch (EQMException $e) {
         $r = false;
     }
     $this->assertFalse($r);
     $projectActivity->id = 999;
     $projectActivity->projectId = 'WHAT_EVER';
     try {
         EQM::delete($projectActivity);
         # TODO zero result nothing has been deleted
         $r = true;
     } catch (EQMException $e) {
         $r = false;
     }
     $this->assertTrue($r);
 }
コード例 #13
0
ファイル: Finders.php プロジェクト: scandio/troba
 /**
  * find an object by it primary key(s)
  *
  * @param array|mixed $primaries a single value or an assoc array
  * @return object the requested entity
  */
 public static function find($primaries)
 {
     return EQM::queryByPrimary(get_called_class(), $primaries);
 }
コード例 #14
0
ファイル: EQMEventTest.php プロジェクト: scandio/troba
 public function testPostDelete()
 {
     $c = new CCompany();
     $c->name = 'NAME';
     EQM::insert($c);
     EQM::delete($c);
     $this->assertEquals($c->remark, 'DELETED');
 }