Example #1
0
 /**
  * @param string $value
  * @param string $type
  *
  * @return Expression
  */
 public static function value($value, $type = null)
 {
     if (!is_scalar($value)) {
         throw new \InvalidArgumentException(sprintf('Value expression can only take scalar values, %s given', gettype($value)));
     }
     return Expression::value($value, $type);
 }
 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'));
     }]];
 }
 public function testContainsWithField()
 {
     $this->expectException(\InvalidArgumentException::class);
     $this->transformer->transform(Expression::exp('contains', [Expression::exp('field', [Expression::value('first')]), Expression::exp('field', [Expression::value('last')])]), $this->config);
 }
 public function provideHydrationTestCases()
 {
     return ['value' => ['exp' => Expression::value(41), 'data' => ['value' => 41, 'type' => null]], 'value with type' => ['exp' => Expression::value(41, 'integer'), 'data' => ['value' => 41, 'type' => 'integer']], 'expression' => ['exp' => Expression::exp('foo'), 'data' => ['exp' => 'foo', 'args' => []]], 'expression with arguments' => ['exp' => Expression::exp('foo', [Expression::exp('bar')]), 'data' => ['exp' => 'foo', 'args' => [['exp' => 'bar', 'args' => []]]]], 'expression with value' => ['exp' => Expression::exp('foo', [Expression::value('bar')]), 'data' => ['exp' => 'foo', 'args' => [['value' => 'bar', 'type' => null]]]]];
 }