예제 #1
0
파일: FilterTest.php 프로젝트: sysvyz/hurl
 /**
  * @depends testIsInt
  * @depends testIsEven
  * @depends testIsArray
  * @depends testIsEmpty
  * @depends testIsString
  * @depends testIsNumeric
  * @depends testIsOdd
  * @param $isInt
  * @param $isEven
  * @param $isArray
  * @param $isEmpty
  * @param $isString
  * @param $isNumeric
  * @param $isOdd
  * @return AbstractNode
  */
 public function testAndOr_Not_Not($isInt, $isEven, $isArray, $isEmpty, $isString, $isNumeric, $isOdd)
 {
     $filter = _Filter::or(_Filter::and($isInt, $isEven), _Filter::and($isArray, $isEmpty), _Filter::and($isString, $isNumeric, $isOdd))->not()->not();
     $this->assertInstanceOf(OrFilter::class, $filter);
     $this->assertFalse($filter([04]));
     $this->assertTrue($filter([]));
     $this->assertTrue($filter(2));
     $this->assertFalse($filter("2"));
     $this->assertFalse($filter(""));
     $this->assertFalse($filter(1));
     $this->assertTrue($filter("1"));
     $this->assertTrue($filter("14353"));
     $this->assertTrue($filter("1.4"));
     $this->assertFalse($filter("2.4"));
     $this->assertFalse($filter("sdasd"));
     $this->assertFalse($filter(""));
     return $filter;
 }
예제 #2
0
 public function testSortMapMap()
 {
     $data = [['4354', '54', '52'], ['45675', '435', '234223'], ['4354', '54']];
     $node = _Array::sort(_Comparator::boolean()->map(MathNode::sum())->map(_Filter::isEven()));
     $this->assertEquals([['45675', '435', '234223'], ['4354', '54', '52'], ['4354', '54']], $node($data));
 }
예제 #3
0
abstract class AbstractArray extends AbstractNode implements CollectionNodeInterface
{
    /**
     * @param callable $do
     * @return AbstractNode
     */
    public function then(callable $do)
    {
        return new class($this, $do) extends AbstractArray implements ContainerTraitInterface
        {
            use ContainerTrait;
        };
    }
    /**
     * @param callable $do
     * @return ArrayEach
     */
    public function each(callable $do)
    {
        return new class($this, _Array::each($do)) extends ArrayEach implements ContainerTraitInterface
        {
            use ContainerTrait;
        };
    }
    /**
     * @param callable $callable
     * @return ArrayMap
     */
    public function map(callable $callable)
    {
        return new class($this, _Array::map($callable)) extends ArrayMap implements ContainerTraitInterface
        {
            use ContainerTrait;
        };
    }
    /**
     * @param callable $callable
     * @return ArrayMap
     */
    public function fold(callable $callable)
    {
        return new class($this, _Array::map($callable)) extends ArrayMap implements ContainerTraitInterface
        {
            use ContainerTrait;
        };
    }
    /**
     * @param \callable[] ...$callable
     * @return ArraySort
     */
    public function sort(callable ...$callable)
    {
        return new class($this, _Array::sort(...$callable)) extends ArraySort implements ContainerTraitInterface
        {
            use ContainerTrait;
        };
    }
    /**
     * @return ArraySort
     */
    public function merge()
    {
        return new class($this, _Array::merge()) extends ArrayMerge implements ContainerTraitInterface
        {
            use ContainerTrait;
        };
    }
    /**
     * @return AbstractNode
     */
    public function sum()
    {
        return new class($this, MathNode::sum()) extends AbstractNode implements ContainerTraitInterface
        {
            use ContainerTrait;
        };
    }
    /**
     * @return ArraySort
     */
    public function values()
    {
        return new class($this, _Array::values()) extends AbstractArray implements ContainerTraitInterface
        {
            use ContainerTrait;
        };
    }
    /**
     * @param string $glue
     * @return AbstractNode
     */
    public function implode(string $glue)
    {
        return $this->then(_Array::implode($glue));
    }
    /**
     * @return IsEmptyFilter
     */
    public function isEmpty()
    {
        return new class($this, _Filter::isEmpty()) extends IsEmptyFilter implements ContainerTraitInterface
        {
            use ContainerTrait;
        };
    }
    /**
     * @return ContainsFilter
     */
    public function contains($needle, $strict = null)
    {
        return new class($this, _Filter::contains($needle, $strict)) extends ContainsFilter implements ContainerTraitInterface
        {
            use ContainerTrait;
        };
    }
}