public function testProperties() { $query = OQL::select('from TestUser'); $criteria = Criteria::create(TestUser::dao()); $this->assertCriteria($query, $criteria); $this->assertCriteria($query->addProperties(OQL::properties('id, count(id) as count')), $criteria->addProjection(Projection::property('id'))->addProjection(Projection::count('id', 'count'))); $this->assertCriteria($query->addProperties(OQL::properties('city.id')), $criteria->addProjection(Projection::property('city.id'))); $properties = OQL::properties('id'); $this->assertFalse($properties->isDistinct()); $this->assertEquals($properties->toProjection(), Projection::chain()->add(Projection::property('id'))); $properties = OQL::properties('id, distinct name'); $this->assertTrue($properties->isDistinct()); $this->assertEquals($properties->toProjection(), Projection::chain()->add(Projection::property('id'))->add(Projection::property('name'))); $properties = OQL::properties('$1')->bind(1, 'foo'); $this->assertEquals($properties->toProjection(), Projection::chain()->add(Projection::property('foo'))); $properties->bind(1, 'bar'); $this->assertEquals($properties->toProjection(), Projection::chain()->add(Projection::property('bar'))); $this->assertCriteria(OQL::select('from TestUser')->addProperties($properties->bind(1, 'foo'))->bind(1, 'bar'), Criteria::create(TestUser::dao())->addProjection(Projection::property('bar'))); $properties = OQL::properties('id, count(distinct city.id + $0), avg(some) as someAverage, ' . 'name not like "%Ы%", foo and (bar or baz), $1 / $2, ' . 'a in ($3, $0)')->bindAll(array(1, 2, 'num', 'test')); $this->assertFalse($properties->isDistinct()); $this->assertEquals($properties->toProjection(), Projection::chain()->add(Projection::property('id'))->add(Projection::distinctCount(Expression::add('city.id', 1)))->add(Projection::avg('some', 'someAverage'))->add(Projection::property(Expression::notLike('name', '%Ы%')))->add(Projection::property(Expression::expAnd('foo', Expression::expOr('bar', 'baz'))))->add(Projection::property(Expression::div(2, 'num')))->add(Projection::property(Expression::in('a', array('test', 1))))); }
public function testProperty() { $this->assertCriteria('from TestUser', Criteria::create(TestUser::dao()))->assertCriteria('id from TestUser', Criteria::create(TestUser::dao())->setProjection(Projection::property('id')))->assertCriteria('avg(id), count(city.id) as count, ' . 'count(distinct city.id) as distinctCount, ' . 'sum(id), min(id), max(id), city.Name as cityName, ' . 'distinct id, city, min from TestUser', Criteria::create(TestUser::dao())->setDistinct(true)->setProjection(Projection::chain()->add(Projection::avg('id'))->add(Projection::count('city.id', 'count'))->add(Projection::distinctCount('city.id', 'distinctCount'))->add(Projection::sum('id'))->add(Projection::min('id'))->add(Projection::max('id'))->add(Projection::property('city.Name', 'cityName'))->add(Projection::property('id'))->add(Projection::property('city'))->add(Projection::property('min'))))->assertCriteria('avg(-id - -1 / -$1), avg((10-id) * -($1+-2.1)), avg(10) as ten ' . 'from TestUser', Criteria::create(TestUser::dao())->setProjection(Projection::chain()->add(Projection::avg(Expression::sub(Expression::minus('id'), Expression::div(-1, -10))))->add(Projection::avg(Expression::mul(Expression::sub(10, 'id'), Expression::minus(Expression::add(10, -2.1)))))->add(Projection::avg(10, 'ten'))), array(1 => 10))->assertCriteria('count(distinct -id * 2 / -3 > 10), count(id in (1, -$1, -3) and Name like `test`)' . 'from TestUser', Criteria::create(TestUser::dao())->setProjection(Projection::chain()->add(Projection::distinctCount(Expression::gt(Expression::div(Expression::mul(Expression::minus('id'), 2), -3), 10)))->add(Projection::count(Expression::expAnd(Expression::in('id', array(1, -2, -3)), Expression::like('Name', 'test'))))), array(1 => 2))->assertCriteria('(id > 10) and (20 > id) as inInterval, ((2*id + 1) / id), -id ' . 'from TestUser', Criteria::create(TestUser::dao())->setProjection(Projection::chain()->add(Projection::property(Expression::expAnd(Expression::gt('id', 10), Expression::gt(20, 'id')), 'inInterval'))->add(Projection::property(Expression::div(Expression::add(Expression::mul(2, 'id'), 1), 'id')))->add(Projection::property(Expression::minus('id'))))); }