diff --git a/Dockerfile b/Dockerfile index 8a54b42..917e826 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,13 @@ FROM php:5.6-cli -RUN docker-php-ext-install mbstring && \ - curl -s https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer +RUN apt-get update && apt-get install -y zip unzip gzip libc6 php5-xdebug --no-install-recommends && rm -r /var/lib/apt/lists/* -ADD . /opt/graze/dataFlow +RUN docker-php-ext-install mbstring \ + && curl -s https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \ + && echo "zend_extension=$(find / -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini -WORKDIR /opt/graze/dataFlow +ADD . /opt/graze/dataNode + +WORKDIR /opt/graze/dataNode CMD /bin/bash diff --git a/README.md b/README.md index 145b4ef..3b54940 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details. ## Security -If you discover any security related issues, please email harry.bragg@graze.com instead of using the issue tracker. +If you discover any security related issues, please email security@graze.com instead of using the issue tracker. ## Credits diff --git a/src/NodeCollection.php b/src/NodeCollection.php index 9377d2c..6029e6d 100644 --- a/src/NodeCollection.php +++ b/src/NodeCollection.php @@ -15,7 +15,7 @@ class NodeCollection extends Collection implements NodeCollectionInterface { /** - * {@inheritdoc} + * @inheritdoc */ public function add($value) { @@ -26,9 +26,9 @@ public function add($value) } /** - * {@inheritdoc} + * @inheritdoc */ - public function apply($fn) + public function apply(callable $fn) { foreach ($this->items as &$item) { $out = call_user_func($fn, $item); @@ -67,10 +67,7 @@ public function getClone() } /** - * @param callable $fn - * @param mixed|null $default - * - * @return NodeInterface|null + * @inheritdoc */ public function first(callable $fn = null, $default = null) { @@ -88,10 +85,7 @@ public function first(callable $fn = null, $default = null) } /** - * @param callable $fn - * @param mixed|null $default - * - * @return NodeInterface|null + * @inheritdoc */ public function last(callable $fn = null, $default = null) { diff --git a/src/NodeCollectionInterface.php b/src/NodeCollectionInterface.php index 6b46fce..d55a2ca 100644 --- a/src/NodeCollectionInterface.php +++ b/src/NodeCollectionInterface.php @@ -11,19 +11,19 @@ interface NodeCollectionInterface extends CollectionInterface, NodeInterface * * @return NodeCollectionInterface */ - public function apply($fn); + public function apply(callable $fn); /** - * @param callable $fn - * @param NodeInterface $default + * @param callable|null $fn + * @param NodeInterface|null $default * * @return NodeInterface|null */ public function first(callable $fn = null, $default = null); /** - * @param callable $fn - * @param NodeInterface $default + * @param callable|null $fn + * @param NodeInterface|null $default * * @return NodeInterface|null */ diff --git a/tests/unit/NodeCollectionTest.php b/tests/unit/NodeCollectionTest.php index b654cdc..67831c7 100644 --- a/tests/unit/NodeCollectionTest.php +++ b/tests/unit/NodeCollectionTest.php @@ -6,6 +6,7 @@ use Graze\DataNode\NodeInterface; use Graze\DataNode\Test\TestCase; use Graze\DataStructure\Collection\Collection; +use InvalidArgumentException; use Mockery as m; class NodeCollectionTest extends TestCase @@ -26,10 +27,7 @@ public function testAddingANonDataNodeWillThrowAnException() { $node = m::mock('Graze\Extensible\ExtensibleInterface'); - static::setExpectedException( - 'InvalidArgumentException', - "The specified value does not implement NodeInterface" - ); + $this->expectException(InvalidArgumentException::class); $collection = new NodeCollection(); $collection->add($node); @@ -45,7 +43,7 @@ public function testCallingApplyWillModifyTheContentsUsingReference() $collection = new NodeCollection(); $collection->add($node); - $collection->apply(function (&$item) { + $collection->apply(function ($item) { $item->someMethod(); }); @@ -96,13 +94,16 @@ public function testFirstWithCallbackWillReturnTheFirstThatMatches() { $first = m::mock(NodeInterface::class); $second = m::mock(NodeInterface::class); + $third = m::mock(NodeInterface::class); $first->shouldReceive('thisOne') ->andReturn(false); $second->shouldReceive('thisOne') ->andReturn(true); + $third->shouldReceive('thosOne') + ->andReturn(true); - $collection = new NodeCollection([$first, $second]); + $collection = new NodeCollection([$first, $second, $third]); static::assertSame($second, $collection->first(function ($item) { return $item->thisOne(); @@ -113,15 +114,18 @@ public function testLastWithCallbackWillReturnTheFirstThatMatches() { $first = m::mock(NodeInterface::class); $second = m::mock(NodeInterface::class); + $third = m::mock(NodeInterface::class); $first->shouldReceive('thisOne') ->andReturn(true); $second->shouldReceive('thisOne') - ->andReturn(false); + ->andReturn(true); + $third->shouldReceive('thisOne') + ->andReturn(false); - $collection = new NodeCollection([$first, $second]); + $collection = new NodeCollection([$first, $second, $third]); - static::assertSame($first, $collection->last(function ($item) { + static::assertSame($second, $collection->last(function ($item) { return $item->thisOne(); })); } @@ -147,7 +151,7 @@ public function testFirstWithCallbackWillReturnDefaultIfNoMatchesAreFound() })); } - public function tesLastWithCallbackWillReturnDefaultIfNoMatchesAreFound() + public function testLastWithCallbackWillReturnDefaultIfNoMatchesAreFound() { $first = m::mock(NodeInterface::class); $second = m::mock(NodeInterface::class); @@ -167,4 +171,25 @@ public function tesLastWithCallbackWillReturnDefaultIfNoMatchesAreFound() return $item->thisOne(); })); } + + public function testCloneWillCloneTheChildObjects() + { + $first = m::mock(NodeInterface::class); + $second = m::mock(NodeInterface::class); + + $collection = new NodeCollection([$first, $second]); + $collection2 = $collection->getClone(); + + static::assertNotSame($collection, $collection2); + static::assertEquals($collection->count(), $collection2->count()); + for ($i = 0; $i < $collection->count(); $i++) { + static::assertNotSame($collection->getAll()[$i], $collection2->getAll()[$i]); + } + } + + public function testToString() + { + $collection = new NodeCollection(); + static::assertEquals("NodeCollection", "$collection"); + } }