public function multipleJoinResultTest()
 {
     $rs = new MockResultSet([[JoinProcessor::FIRST . '_job_id' => '11', JoinProcessor::FIRST . '_title' => 'clean toilette', JoinProcessor::FIRST . '_valid_from' => new \util\Date(), JoinProcessor::FIRST . '_expire_at' => '', JoinProcessor::pathToKey(['PersonJob']) . '_person_id' => '11', JoinProcessor::pathToKey(['PersonJob']) . '_name' => 'Schultz', JoinProcessor::pathToKey(['PersonJob']) . '_job_id' => '21', JoinProcessor::pathToKey(['PersonJob']) . '_department_id' => '31'], [JoinProcessor::FIRST . '_job_id' => '11', JoinProcessor::FIRST . '_title' => 'clean toilette', JoinProcessor::FIRST . '_valid_from' => new \util\Date(), JoinProcessor::FIRST . '_expire_at' => '', JoinProcessor::pathToKey(['PersonJob']) . '_person_id' => '12', JoinProcessor::pathToKey(['PersonJob']) . '_name' => 'Müller', JoinProcessor::pathToKey(['PersonJob']) . '_job_id' => '11', JoinProcessor::pathToKey(['PersonJob']) . '_department_id' => '31'], [JoinProcessor::FIRST . '_job_id' => '12', JoinProcessor::FIRST . '_title' => 'second job', JoinProcessor::FIRST . '_valid_from' => new \util\Date(), JoinProcessor::FIRST . '_expire_at' => '', JoinProcessor::pathToKey(['PersonJob']) . '_person_id' => '11', JoinProcessor::pathToKey(['PersonJob']) . '_name' => 'Schultz', JoinProcessor::pathToKey(['PersonJob']) . '_job_id' => '21', JoinProcessor::pathToKey(['PersonJob']) . '_department_id' => '31'], [JoinProcessor::FIRST . '_job_id' => '13', JoinProcessor::FIRST . '_title' => 'third job', JoinProcessor::FIRST . '_valid_from' => new \util\Date(), JoinProcessor::FIRST . '_expire_at' => '', JoinProcessor::pathToKey(['PersonJob']) . '_person_id' => null, JoinProcessor::pathToKey(['PersonJob']) . '_name' => null, JoinProcessor::pathToKey(['PersonJob']) . '_job_id' => null, JoinProcessor::pathToKey(['PersonJob']) . '_department_id' => null]]);
     $jp = new JoinProcessor(Job::getPeer());
     $jp->setFetchModes(['PersonJob' => 'join']);
     $ji = new JoinIterator($jp, $rs);
     $this->assertTrue($ji->hasNext());
     $this->assertInstanceOf(Job::class, $job = $ji->next());
     $this->assertInstanceOf('var[]', $job->getPersonJobList());
     $this->assertInstanceOf(CachedResults::class, $pji = $job->getPersonJobIterator());
     $this->assertTrue($pji->hasNext());
     $this->assertInstanceOf(Person::class, $pji->next());
     $this->assertTrue($pji->hasNext());
     $this->assertInstanceOf(Person::class, $pji->next());
     $this->assertFalse($pji->hasNext());
     $this->assertTrue($ji->hasNext());
     $this->assertInstanceOf(Job::class, $job = $ji->next());
     $this->assertInstanceOf('var[]', $job->getPersonJobList());
     $this->assertInstanceOf(CachedResults::class, $pji = $job->getPersonJobIterator());
     $this->assertTrue($pji->hasNext());
     $this->assertInstanceOf(Person::class, $pji->next());
     $this->assertFalse($pji->hasNext());
     $this->assertTrue($ji->hasNext());
     $this->assertInstanceOf(Job::class, $job = $ji->next());
     $this->assertInstanceOf('var[]', $job->getPersonJobList());
     $this->assertInstanceOf(CachedResults::class, $pji = $job->getPersonJobIterator());
     $this->assertFalse($pji->hasNext());
     $this->assertFalse($ji->hasNext());
 }
Esempio n. 2
0
 public function extractTest()
 {
     $toJob = new JoinPart('j', Job::getPeer());
     $toPerson = new JoinPart('p', Person::getPeer());
     $toDepartment = new JoinPart('d', Department::getPeer());
     $toChief = new JoinPart('c', Person::getPeer());
     $toJob->addRelative($toPerson, 'JobPerson');
     $toPerson->addRelative($toDepartment, 'Department');
     $toDepartment->addRelative($toChief, 'DepartmentChief');
     $job = Job::getPeer()->objectFor(['job_id' => '21', 'title' => 'clean the toilette', 'valid_from' => new \util\Date(), 'expire_at' => '']);
     $toPerson->extract($job, ['p_person_id' => '11', 'p_name' => 'Schultz', 'p_job_id' => '21', 'p_department_id' => '31', 'd_department_id' => '31', 'd_name' => 'iDev', 'd_chief_id' => '12', 'c_person_id' => '12', 'c_name' => 'Friebe', 'c_job_id' => '22', 'c_department_id' => '31'], 'JobPerson');
     $this->assertInstanceOf(Person::class, $job->getCachedObj('JobPerson', '#11'));
     $this->assertInstanceOf(Department::class, $job->getCachedObj('JobPerson', '#11')->getCachedObj('Department', '#31'));
     $this->assertInstanceOf(Person::class, $job->getCachedObj('JobPerson', '#11')->getCachedObj('Department', '#31')->getCachedObj('DepartmentChief', '#12'));
 }
Esempio n. 3
0
 public function genericFinderGetAll()
 {
     $this->getConnection()->setResultSet(new MockResultSet([0 => ['job_id' => 1, 'title' => $this->getName(), 'valid_from' => \util\Date::now(), 'expire_at' => null], 1 => ['job_id' => 2, 'title' => $this->getName() . ' #2', 'valid_from' => \util\Date::now(), 'expire_at' => null]]));
     $all = (new GenericFinder(Job::getPeer()))->getAll(new \rdbms\Criteria());
     $this->assertEquals(2, sizeof($all));
     $this->assertInstanceOf(Job::class, $all[0]);
     $this->assertInstanceOf(Job::class, $all[1]);
 }
Esempio n. 4
0
 public function executeWithRestriction()
 {
     $this->assertInstanceOf(SelectQuery::class, (new SelectQuery())->withRestriction(Job::column('job_id')->equal(5)));
 }
 function restrictionTest()
 {
     $this->assertSQL('where job_id = ceil(asin(sin(0.125)))', 'where job_id = ceiling(asin(sin(0.125)))', 'where job_id = ceil(asin(sin(0.125)))', 'where job_id = php(\'ceil\', php(\'asin\', php(\'sin\', 0.125)))', (new Criteria())->add(Restrictions::equal('job_id', SQLFunctions::ceil(SQLFunctions::asin(SQLFunctions::sin(0.125))))));
     $this->assertSQL('where job_id = ceil(asin(sin(0.125)))', 'where job_id = ceiling(asin(sin(0.125)))', 'where job_id = ceil(asin(sin(0.125)))', 'where job_id = php(\'ceil\', php(\'asin\', php(\'sin\', 0.125)))', (new Criteria())->add(Restrictions::equal(Job::column('job_id'), SQLFunctions::ceil(SQLFunctions::asin(SQLFunctions::sin(0.125))))));
 }
Esempio n. 6
0
 /**
  * Setup method
  */
 public function setUp()
 {
     $this->conn = DriverManager::getConnection('mock://mock/JOBS?autoconnect=1');
     $this->peer = Job::getPeer();
     $this->peer->setConnection(DriverManager::getConnection('mock://mock/JOBS?autoconnect=1'));
 }
 public function noSuchRoleTest()
 {
     $jp = new JoinProcessor(Job::getPeer());
     $jp->setFetchModes(['UnknownRole' => 'join']);
 }
Esempio n. 8
0
 /**
  * Returns the Peer object for this finder
  *
  * @return  rdbms.Peer
  */
 public function getPeer()
 {
     return Job::getPeer();
 }
Esempio n. 9
0
 public function testDoSelectMax()
 {
     for ($i = 0; $i < 4; $i++) {
         $this->setResults(new MockResultSet([0 => ['job_id' => 654, 'title' => 'Java Unit tester', 'valid_from' => Date::now(), 'expire_at' => null], 1 => ['job_id' => 655, 'title' => 'Java Unit tester 1', 'valid_from' => Date::now(), 'expire_at' => null], 2 => ['job_id' => 656, 'title' => 'Java Unit tester 2', 'valid_from' => Date::now(), 'expire_at' => null], 3 => ['job_id' => 657, 'title' => 'Java Unit tester 3', 'valid_from' => Date::now(), 'expire_at' => null]]));
         $this->assertEquals($i ? $i : 4, count(Job::getPeer()->doSelect(new \rdbms\Criteria(), $i)));
     }
 }
Esempio n. 10
0
 public function testJoinWithProjection()
 {
     $jp = new \rdbms\join\JoinProcessor(Job::getPeer());
     $jp->setFetchModes(['PersonJob->Department' => 'join']);
     $jp->enterJoinContext();
     try {
         $this->assertEquals('select  PersonJob.job_id, PersonJob_Department.department_id from JOBS.job as start, JOBS.Person as PersonJob, JOBS.Department as PersonJob_Department where start.job_id *= PersonJob.job_id and PersonJob.department_id *= PersonJob_Department.department_id and  1 = 1', (new Criteria())->setFetchmode(\rdbms\join\Fetchmode::join('PersonJob'))->setProjection(\rdbms\criterion\Projections::projectionList()->add(Job::column('PersonJob->job_id'))->add(Job::column('PersonJob->Department->department_id')))->getSelectQueryString($this->conn, $this->peer, $jp));
     } finally {
         $jp->leaveJoinContext();
     }
 }
Esempio n. 11
0
 function withProjectionTest()
 {
     $crit = new Criteria();
     $this->assertInstanceOf('rdbms.Criteria', $crit->withProjection(Projections::property(Job::column('job_id'))));
     $this->assertFalse($crit->isProjection());
     $this->assertTrue($crit->withProjection(Projections::property(Job::column('job_id')))->isProjection());
 }
 public function ambiguous()
 {
     Job::getPeer()->getConnection()->setResultSet(new MockResultSet([['job_id' => 1549, 'title' => 'Developer'], ['job_id' => 1549, 'title' => 'Doppelgänger']]));
     $in = $this->newReader("job_id;title\n1549;10248")->withProcessors([new GetDataSet(create(new JobFinder())->method('byPrimary')), null]);
     $in->getHeaders();
     try {
         $in->read();
         $this->fail('Lookup succeeded', null, 'lang.FormatException');
     } catch (\lang\FormatException $expected) {
     }
 }