示例#1
0
    /**
     * @depends testExplode
     * @param $data
     */
    public function testDebug($data)
    {
        $debug = _Array::values()->debug();
        $expected = 'Array
(
    [0] => 4
    [1] => 78
    [2] => 2
    [3] => 7
    [4] => 4
    [5] => 34
    [6] => 43
    [7] => 34
)
';
        ob_start();
        $array = $debug($data);
        $result = ob_get_clean();
        $this->assertEquals($expected, $result);
        $this->assertEquals($array, [4, 78, 2, 7, 4, 34, 43, 34]);
    }
示例#2
0
 public function testContainsStrict()
 {
     $filter = _Array::values()->contains(1, true);
     $this->assertInstanceOf(ContainsFilter::class, $filter);
     $d0 = [1];
     $d1 = ['1'];
     $d2 = [];
     $d3 = [43, 23, 123, 12];
     $d4 = [43, 23, "1", 123, 12];
     $d5 = [43, 23, 1, 123, 12];
     $this->assertTrue($filter($d0));
     $this->assertFalse($filter($d1));
     $this->assertFalse($filter($d2));
     $this->assertFalse($filter($d3));
     $this->assertFalse($filter($d4));
     $this->assertTrue($filter($d5));
 }
示例#3
0
 public function testBooleanInv()
 {
     $cmpNode = _Comparator::boolean()->invert();
     $data = [true, false, true, false, true, false, true];
     $node = _Array::values()->sort($cmpNode);
     $this->assertEquals([true, true, true, true, false, false, false], $node($data));
     $this->assertInstanceOf(AbstractComparator::class, $cmpNode);
 }
示例#4
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;
        };
    }
}