コード例 #1
0
 public function testField()
 {
     $where = Where::field('foo');
     $exp = $where->equals(10);
     $this->assertInstanceOf(Where\FieldExpressionBuilder::class, $where);
     $this->assertEquals(Expr::eq(Expr::field('foo'), Expr::value(10)), $exp);
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function __invoke(SQLTransformer $transformer, Expression $expression, Configuration $config)
 {
     $left = $expression->getArg(0);
     $right = $expression->getArg(1);
     if (!$right->isValue()) {
         throw new \InvalidArgumentException('Only constant values allowed as right operands of contains expression');
     }
     return Clause::join($transformer->transform($left, $config), ' LIKE ', $transformer->transform(Expression\Expr::value('%' . $right->getValue() . '%'), $config));
 }
コード例 #3
0
 public function provideExpressionTestCases()
 {
     return ['value' => [Expression::value('foo'), function () {
         return Expression\Expr::value('foo');
     }], 'values' => [Expression::exp('array', [Expression::value('foo'), Expression::value('bar'), Expression::value('baz')]), function () {
         return Expression\Expr::values(['foo', 'bar', 'baz']);
     }], 'field' => [Expression::exp('field', [Expression::value('foo')]), function () {
         return Expression\Expr::field('foo');
     }], 'all' => [Expression::exp('all', [Expression::exp('foo'), Expression::exp('bar')]), function () {
         return Expression\Expr::all([Expression::exp('foo'), Expression::exp('bar')]);
     }], 'any' => [Expression::exp('any', [Expression::exp('foo'), Expression::exp('bar')]), function () {
         return Expression\Expr::any([Expression::exp('foo'), Expression::exp('bar')]);
     }], 'all with single expression' => [Expression::exp('foo'), function () {
         return Expression\Expr::all([Expression::exp('foo')]);
     }], 'any with single expression' => [Expression::exp('foo'), function () {
         return Expression\Expr::any([Expression::exp('foo')]);
     }], 'not' => [Expression::exp('not', [Expression::exp('foo')]), function () {
         return Expression\Expr::not(Expression::exp('foo'));
     }], 'eq' => [Expression::exp('eq', [Expression::exp('foo'), Expression::value('bar')]), function () {
         return Expression\Expr::eq(Expression::exp('foo'), Expression::value('bar'));
     }], 'neq' => [Expression::exp('neq', [Expression::exp('foo'), Expression::value('bar')]), function () {
         return Expression\Expr::neq(Expression::exp('foo'), Expression::value('bar'));
     }], 'gt' => [Expression::exp('gt', [Expression::exp('foo'), Expression::value('bar')]), function () {
         return Expression\Expr::gt(Expression::exp('foo'), Expression::value('bar'));
     }], 'ge' => [Expression::exp('ge', [Expression::exp('foo'), Expression::value('bar')]), function () {
         return Expression\Expr::ge(Expression::exp('foo'), Expression::value('bar'));
     }], 'lt' => [Expression::exp('lt', [Expression::exp('foo'), Expression::value('bar')]), function () {
         return Expression\Expr::lt(Expression::exp('foo'), Expression::value('bar'));
     }], 'le' => [Expression::exp('le', [Expression::exp('foo'), Expression::value('bar')]), function () {
         return Expression\Expr::le(Expression::exp('foo'), Expression::value('bar'));
     }], 'in' => [Expression::exp('in', [Expression::exp('foo'), Expression::value('bar')]), function () {
         return Expression\Expr::in(Expression::exp('foo'), Expression::value('bar'));
     }], 'not_in' => [Expression::exp('not_in', [Expression::exp('foo'), Expression::value('bar')]), function () {
         return Expression\Expr::notIn(Expression::exp('foo'), Expression::value('bar'));
     }], 'is_null' => [Expression::exp('is_null', [Expression::exp('foo')]), function () {
         return Expression\Expr::isNull(Expression::exp('foo'));
     }], 'is_not_null' => [Expression::exp('is_not_null', [Expression::exp('foo')]), function () {
         return Expression\Expr::isNotNull(Expression::exp('foo'));
     }], 'is_empty' => [Expression::exp('is_empty', [Expression::exp('foo')]), function () {
         return Expression\Expr::isEmpty(Expression::exp('foo'));
     }], 'is_not_empty' => [Expression::exp('is_not_empty', [Expression::exp('foo')]), function () {
         return Expression\Expr::isNotEmpty(Expression::exp('foo'));
     }]];
 }
コード例 #4
0
 /**
  * Builds "Not" expression.
  *
  * @param Expression $expression
  *
  * @return Expression
  */
 public static function not(Expression $expression)
 {
     return Expr::not($expression);
 }
コード例 #5
0
 public function testFindConstructor()
 {
     $query = Query::criteria($exp = Expr::value(51));
     $this->assertSame($exp, $query->getCriteria());
 }
コード例 #6
0
 /**
  * {@inheritdoc}
  */
 public function __invoke(SQLTransformer $transformer, Expression $expression, Configuration $config)
 {
     return $transformer->transform(Expression\Expr::all([Expression\Expr::isNotNull($expression->getArg(0)), Expression\Expr::neq($expression->getArg(0), Expression\Expr::value(''))]), $config);
 }
コード例 #7
0
 public function testOperandCriteria()
 {
     $filter = $this->transformer->transform(Expr::field('email'), $this->config);
     $result = array_filter($this->data, $filter);
     $this->assertEquals(['jane'], array_keys($result));
 }
コード例 #8
0
 public function testOperandCriteria()
 {
     $sql = $this->transformer->transform(Expression\Expr::field('email'), $this->config);
     $this->assertEquals('phpunit.email', $sql->getWhere());
 }
コード例 #9
0
 public function testOperandCriteria()
 {
     $this->expectException(QueryException::class);
     $this->find(Expression\Expr::field('email'));
 }
コード例 #10
0
 public function testOperandCriteria()
 {
     $result = $this->find(Expression\Expr::field('email'));
     $this->assertEquals([], $result);
 }
コード例 #11
0
 /**
  * @param mixed $value
  *
  * @return Expression
  */
 private function normalize($value)
 {
     if (!$value instanceof Expression) {
         return Expr::value($value);
     }
     return $value;
 }