public function getConnection() { $q = new SelectQuery(); $this->assertNull($q->getConnection()); $q->setPeer(Job::getPeer()); $this->assertInstanceOf(MockConnection::class, $q->getConnection()); }
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()); }
/** * Sets up a Database Object for the test * */ public function setUp() { $this->syconn = new SybaseConnection(new \rdbms\DSN('sybase://localhost:1999/')); $this->myconn = new MySQLConnection(new \rdbms\DSN('mysql://localhost/')); $this->pgconn = new PostgreSQLConnection(new \rdbms\DSN('pgsql://localhost/')); $this->sqconn = new SQLite3Connection(new \rdbms\DSN('sqlite://tmpdir/tmpdb')); $this->peer = Job::getPeer(); }
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')); }
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]); }
/** * 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']); }
/** * Returns the Peer object for this finder * * @return rdbms.Peer */ public function getPeer() { return Job::getPeer(); }
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))); } }
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(); } }
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) { } }