示例#1
0
 public function testCompositeFilter1()
 {
     $filter = new CompositeFilter(CompositeFilter::OP_OR, array(ColumnFilter::fromArray(array('id', '=', 1)), ColumnFilter::fromArray(array('id', '=', 2)), ColumnFilter::fromArray(array('id', '=', 3))));
     $actual = $filter->render();
     $expected = array("(id = ? OR id = ? OR id = ?)", array(1, 2, 3));
     $this->assertSame($expected, $actual);
 }
示例#2
0
 /**
  * @expectedException PHPUnit_Framework_Error
  */
 public function testFilterFromArrayExceptionWrongType()
 {
     $actual = ColumnFilter::fromArray(1);
 }
示例#3
0
 /**
  * Parses method arguments for `->filter()` and returns a corresponding
  * Filter object. Here are the possibilities:
  *
  * 1. One argument is given
  *
  * a) If it's a Filter object, just return it as-is.
  *    e.g. `->filter(new Filter(...))`
  *
  * b) If it's an array, use it to construct a ColumnFilter.
  *    e.g. `->filter(['foo', 'isnull'])
  *
  * c) If it's a string, use it to construct a RawFilter.
  *    e.g. `->filter('foo = lower(bar)')`
  *
  * 2. Two arguments given
  *
  * a) If both are strings, use them to construct a ColumnFilter.
  *    e.g. `->filter('foo', 'isnull')
  *
  * b) If one is string and the other an array, use it to construct a
  *    Raw filter (first is SQL filter, the second is arguments).
  *    e.g. `->filter('foo = concat(?, ?)', ['bar', 'baz'])
  *
  * 3. Three arguments given
  *
  * a) Use them to construct a ColumnFilter.
  *    e.g. `->filter('foo', '=', 'bar')
  *
  * @return Phormium\Filter\Filter.
  */
 private function parseFilterArgs($argv, $argc)
 {
     if ($argc === 1) {
         $arg = $argv[0];
         if ($arg instanceof Filter) {
             return $arg;
         } elseif (is_array($arg)) {
             return ColumnFilter::fromArray($arg);
         } elseif (is_string($arg)) {
             return new RawFilter($arg);
         }
     } elseif ($argc === 2) {
         if (is_string($argv[0])) {
             if (is_string($argv[1])) {
                 return ColumnFilter::fromArray($args);
             } elseif (is_array($argv[1])) {
                 return new RawFilter($argv[0], $argv[1]);
             }
         }
     } elseif ($argc === 3) {
         return ColumnFilter::fromArray($argv);
     }
     throw new \InvalidArgumentException("Invalid filter arguments.");
 }