public function testStaticMethodCalling()
 {
     $this->assertEquals(ClassUtils::callStaticMethod('Singleton::getInstance', 'UrlEncodeFilter'), Singleton::getInstance('UrlEncodeFilter'));
     $this->assertEquals(ClassUtils::callStaticMethod('ImaginaryDialect::me'), ImaginaryDialect::me());
     try {
         ClassUtils::callStaticMethod('InexistantClass::InSaNeMeThOd');
         $this->fail();
     } catch (ClassNotFoundException $e) {
         /* first pass */
     } catch (WrongArgumentException $e) {
         /* and all others */
     }
     try {
         ClassUtils::callStaticMethod('complete nonsense');
         $this->fail();
     } catch (WrongArgumentException $e) {
         /* pass */
     }
     try {
         ClassUtils::callStaticMethod('Identifier::comp::lete::non::sense');
         $this->fail();
     } catch (WrongArgumentException $e) {
         /* pass */
     }
 }
 /**
  * @return ImaginaryDialect
  **/
 public static function me()
 {
     if (!self::$self) {
         self::$self = new self();
     }
     return self::$self;
 }
 public function testToString()
 {
     $range = IpRange::create(IpAddress::create('192.168.1.1'), IpAddress::create('192.168.255.255'));
     $this->assertEquals('192.168.1.1-192.168.255.255', $range->toString());
     $this->assertEquals('\'192.168.1.1-192.168.255.255\'', $range->toDialectString($this->getDbByType('PgSQL')->getDialect()));
     $this->assertEquals('192.168.1.1-192.168.255.255', $range->toDialectString(ImaginaryDialect::me()));
 }
 public function testUpdateQueryByUserWithSameValueObject()
 {
     //if value object same for both main objects - we'll update all fields from value object
     $contactExt = $this->spawnContactValueExt();
     $oldUser = $this->spawnUserWithContactExt(array('contactExt' => $contactExt));
     $user = $this->spawnUserWithContactExt(array('contactExt' => $contactExt));
     $updateUser = $user->proto()->fillQuery(OSQL::update(), $user, $oldUser);
     $this->assertEquals('UPDATE  SET email = foo@bar.com, icq = 12345678, ' . 'phone = 89012345678, city_id = NULL, ' . 'web = https://www.github.com/, skype = github', $updateUser->toDialectString(ImaginaryDialect::me()));
 }
 /**
  * @group ff
  */
 public function testDialect()
 {
     //setup
     $someDate = TimestampTZ::create('2012-02-23 12:12:12 GMT');
     //expectation
     $expectation = $someDate->toTimestamp()->toString();
     //check
     $this->assertEquals($someDate->toDialectString(ImaginaryDialect::me()), $expectation);
 }
 public function testDialectStringObjects()
 {
     $criteria = Criteria::create(TestUser::dao())->setProjection(Projection::property('id'))->add(Expression::gt('registered', Date::create('2011-01-01')));
     $this->assertEquals($criteria->toDialectString(ImaginaryDialect::me()), 'SELECT test_user.id FROM test_user WHERE (test_user.registered > 2011-01-01)');
     $criteria = Criteria::create(TestUserWithContactExtended::dao())->setProjection(Projection::property('contactExt.city.id', 'cityId'))->add(Expression::eq('contactExt.city', TestCity::create()->setId(22)));
     $this->assertEquals($criteria->toDialectString(ImaginaryDialect::me()), 'SELECT test_user_with_contact_extended.city_id AS cityId FROM test_user_with_contact_extended WHERE (test_user_with_contact_extended.city_id = 22)');
     $cityList = array(TestCity::create()->setId(3), TestCity::create()->setId(44));
     $criteria = Criteria::create(TestUser::dao())->setProjection(Projection::property('id'))->add(Expression::in('city', $cityList));
     $this->assertEquals($criteria->toDialectString(ImaginaryDialect::me()), 'SELECT test_user.id FROM test_user WHERE (test_user.city_id IN (3, 44))');
 }
 public function testHasNoReturning()
 {
     $dialect = ImaginaryDialect::me();
     $query = OSQL::update('test_table')->set('field1', 1)->where(Expression::eq('field1', 2))->returning('field1');
     try {
         $query->toDialectString($dialect);
     } catch (UnimplementedFeatureException $e) {
         return $this;
     }
     $this->fail();
 }
 public function testQuery()
 {
     $query = OSQL::delete()->from('pity_table');
     $dialect = ImaginaryDialect::me();
     try {
         $query->toDialectString($dialect);
         $this->fail();
     } catch (WrongArgumentException $e) {
         /* pass */
     }
     $query->where(Expression::eq(1, 2));
     $this->assertEquals($query->toDialectString($dialect), 'DELETE FROM pity_table WHERE (1 = 2)');
     $query->andWhere(Expression::notEq('a', 'b'));
     $this->assertEquals($query->toDialectString($dialect), 'DELETE FROM pity_table WHERE (1 = 2) AND (a != b)');
 }
 public function testQuery()
 {
     $query = OSQL::truncate('single_table');
     try {
         OSQL::truncate()->toDialectString(ImaginaryDialect::me());
         $this->fail();
     } catch (WrongArgumentException $e) {
         /* pass */
     }
     $this->assertEquals($query->toDialectString(ImaginaryDialect::me()), 'DELETE FROM single_table;');
     $this->assertEquals($query->toDialectString(PostgresDialect::me()), 'TRUNCATE TABLE "single_table";');
     $this->assertEquals($query->toDialectString(LiteDialect::me()), 'DELETE FROM "single_table";');
     $this->assertEquals($query->toDialectString(MyDialect::me()), 'TRUNCATE TABLE `single_table`;');
     $query = OSQL::truncate(array('foo', 'bar', 'bleh'));
     $this->assertEquals($query->toDialectString(ImaginaryDialect::me()), 'DELETE FROM foo; DELETE FROM bar; DELETE FROM bleh;');
     $this->assertEquals($query->toDialectString(PostgresDialect::me()), 'TRUNCATE TABLE "foo", "bar", "bleh";');
     $this->assertEquals($query->toDialectString(LiteDialect::me()), 'DELETE FROM "foo"; DELETE FROM "bar"; DELETE FROM "bleh";');
     $this->assertEquals($query->toDialectString(MyDialect::me()), 'TRUNCATE TABLE `foo`; TRUNCATE TABLE `bar`; TRUNCATE TABLE `bleh`;');
 }
 public function testQuery()
 {
     $pgDialect = $this->getDbByType('PgSQL')->getDialect();
     $myDialect = $this->getDbByType('MySQLim')->getDialect();
     $liteDialect = $this->getDbByType('SQLitePDO')->getDialect();
     $query = OSQL::truncate('single_table');
     try {
         OSQL::truncate()->toDialectString(ImaginaryDialect::me());
         $this->fail();
     } catch (WrongArgumentException $e) {
         /* pass */
     }
     $this->assertEquals($query->toDialectString(ImaginaryDialect::me()), 'DELETE FROM single_table;');
     $this->assertEquals($query->toDialectString($pgDialect), 'TRUNCATE TABLE "single_table";');
     $this->assertEquals($query->toDialectString($liteDialect), 'DELETE FROM "single_table";');
     $this->assertEquals($query->toDialectString($myDialect), 'TRUNCATE TABLE `single_table`;');
     $query = OSQL::truncate(array('foo', 'bar', 'bleh'));
     $this->assertEquals($query->toDialectString(ImaginaryDialect::me()), 'DELETE FROM foo; DELETE FROM bar; DELETE FROM bleh;');
     $this->assertEquals($query->toDialectString($pgDialect), 'TRUNCATE TABLE "foo", "bar", "bleh";');
     $this->assertEquals($query->toDialectString($liteDialect), 'DELETE FROM "foo"; DELETE FROM "bar"; DELETE FROM "bleh";');
     $this->assertEquals($query->toDialectString($myDialect), 'TRUNCATE TABLE `foo`; TRUNCATE TABLE `bar`; TRUNCATE TABLE `bleh`;');
 }
 public function testChainSQL()
 {
     $this->assertRegExp('/^\\(\\(a (OR|or) \\(b ((IS NOT NULL)|(is not null)) *\\)\\) (AND|and) \\(c = d\\) (AND|and) \\(e ((IS FALSE)|(is false)) *\\)\\)$/', Expression::chain()->expAnd(Expression::expOr('a', Expression::notNull('b')))->expAnd(Expression::eq('c', 'd'))->expAnd(Expression::isFalse('e'))->toDialectString(ImaginaryDialect::me()));
     $this->assertRegExp('/^\\(\\(a = b\\) (OR|or) \\(d (OR|or) \\(c > e\\)\\) (OR|or) \\(f (in|IN) \\(qwer, asdf, zxcv\\)\\)\\)$/', Expression::chain()->expOr(Expression::eq('a', 'b'))->expOr(Expression::expOr('d', Expression::gt('c', 'e')))->expOr(Expression::in('f', array('qwer', 'asdf', 'zxcv')))->toDialectString(ImaginaryDialect::me()));
 }
 public function testSqlFunction()
 {
     $criteria = Criteria::create(TestCity::dao())->addProjection(Projection::property(SQLFunction::create('count', SQLFunction::create('substring', BinaryExpression::create('name', BinaryExpression::create(DBValue::create('M....w'), DBValue::create('#'), 'for')->noBrackets(), 'from')->noBrackets()))->setAggregateDistinct()->setAlias('my_alias')));
     $this->assertEquals($criteria->toDialectString(ImaginaryDialect::me()), 'SELECT count(DISTINCT substring(custom_table.name from M....w for #)) AS my_alias FROM custom_table');
 }
 public function toString()
 {
     return $this->toDialectString(ImaginaryDialect::me());
 }
 protected function toDialectStringField($field, Dialect $dialect)
 {
     if ($field instanceof SelectQuery) {
         Assert::isTrue(null !== ($alias = $field->getName()), 'can not use SelectQuery to table without name as get field: ' . $field->toDialectString(ImaginaryDialect::me()));
         return "({$field->toDialectString($dialect)}) AS " . $dialect->quoteField($alias);
     } else {
         return $field->toDialectString($dialect);
     }
 }
 public function toString()
 {
     return $this->toDialectString($this->dao ? DBPool::getByDao($this->dao)->getDialect() : ImaginaryDialect::me());
 }