Exemplo n.º 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);
 }
Exemplo n.º 2
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'));
     }]];
 }
 /**
  * {@inheritdoc}
  */
 public function __invoke(SQLTransformer $transformer, Expression $expression, Configuration $config)
 {
     return $transformer->transform(Expression\Expr::any([Expression\Expr::isNull($expression->getArg(0)), Expression\Expr::eq($expression->getArg(0), Expression\Expr::value(''))]), $config);
 }
 /**
  * @param Expression|string|float|int|bool $value
  *
  * @return Expression
  */
 public function equals($value)
 {
     return Expr::eq($this->field, $this->normalize($value));
 }