From f18d6efedcf31612c26038fbe361d18ba1b9ecc7 Mon Sep 17 00:00:00 2001 From: Harry Bragg Date: Tue, 23 Feb 2016 08:54:44 +0000 Subject: [PATCH 1/3] test coverage 100% --- Dockerfile | 11 +++++---- README.md | 2 +- tests/unit/NodeCollectionTest.php | 37 ++++++++++++++++++++++++++----- 3 files changed, 40 insertions(+), 10 deletions(-) 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/tests/unit/NodeCollectionTest.php b/tests/unit/NodeCollectionTest.php index b654cdc..c1d709c 100644 --- a/tests/unit/NodeCollectionTest.php +++ b/tests/unit/NodeCollectionTest.php @@ -96,13 +96,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 +116,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 +153,7 @@ public function testFirstWithCallbackWillReturnDefaultIfNoMatchesAreFound() })); } - public function tesLastWithCallbackWillReturnDefaultIfNoMatchesAreFound() + public function testLastWithCallbackWillReturnDefaultIfNoMatchesAreFound() { $first = m::mock(NodeInterface::class); $second = m::mock(NodeInterface::class); @@ -167,4 +173,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"); + } } From 238f86b147dfb5eb5398d276b9bc6429b1786e68 Mon Sep 17 00:00:00 2001 From: Harry Bragg Date: Tue, 23 Feb 2016 09:06:49 +0000 Subject: [PATCH 2/3] update to phpunit 5 --- src/NodeCollection.php | 8 ++++---- tests/unit/NodeCollectionTest.php | 6 ++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/NodeCollection.php b/src/NodeCollection.php index 9377d2c..1ea7b8e 100644 --- a/src/NodeCollection.php +++ b/src/NodeCollection.php @@ -67,8 +67,8 @@ public function getClone() } /** - * @param callable $fn - * @param mixed|null $default + * @param callable|null $fn + * @param mixed|null $default * * @return NodeInterface|null */ @@ -88,8 +88,8 @@ public function first(callable $fn = null, $default = null) } /** - * @param callable $fn - * @param mixed|null $default + * @param callable|null $fn + * @param mixed|null $default * * @return NodeInterface|null */ diff --git a/tests/unit/NodeCollectionTest.php b/tests/unit/NodeCollectionTest.php index c1d709c..be1660f 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); From d736d513f69f6e0337f6b72a101e663aed2405cf Mon Sep 17 00:00:00 2001 From: Harry Bragg Date: Tue, 23 Feb 2016 09:16:02 +0000 Subject: [PATCH 3/3] fix php7/hhvm builds --- src/NodeCollection.php | 16 +++++----------- src/NodeCollectionInterface.php | 10 +++++----- tests/unit/NodeCollectionTest.php | 2 +- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/NodeCollection.php b/src/NodeCollection.php index 1ea7b8e..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|null $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|null $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 be1660f..67831c7 100644 --- a/tests/unit/NodeCollectionTest.php +++ b/tests/unit/NodeCollectionTest.php @@ -43,7 +43,7 @@ public function testCallingApplyWillModifyTheContentsUsingReference() $collection = new NodeCollection(); $collection->add($node); - $collection->apply(function (&$item) { + $collection->apply(function ($item) { $item->someMethod(); });