Skip to content

Commit

Permalink
Merge pull request #1 from graze/v1-alpha
Browse files Browse the repository at this point in the history
V1 alpha
  • Loading branch information
Harry Bragg committed Feb 23, 2016
2 parents c498906 + d736d51 commit 76bd48f
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 31 deletions.
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 5 additions & 11 deletions src/NodeCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class NodeCollection extends Collection implements NodeCollectionInterface
{
/**
* {@inheritdoc}
* @inheritdoc
*/
public function add($value)
{
Expand All @@ -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);
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down
10 changes: 5 additions & 5 deletions src/NodeCollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
45 changes: 35 additions & 10 deletions tests/unit/NodeCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -45,7 +43,7 @@ public function testCallingApplyWillModifyTheContentsUsingReference()
$collection = new NodeCollection();
$collection->add($node);

$collection->apply(function (&$item) {
$collection->apply(function ($item) {
$item->someMethod();
});

Expand Down Expand Up @@ -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();
Expand All @@ -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();
}));
}
Expand All @@ -147,7 +151,7 @@ public function testFirstWithCallbackWillReturnDefaultIfNoMatchesAreFound()
}));
}

public function tesLastWithCallbackWillReturnDefaultIfNoMatchesAreFound()
public function testLastWithCallbackWillReturnDefaultIfNoMatchesAreFound()
{
$first = m::mock(NodeInterface::class);
$second = m::mock(NodeInterface::class);
Expand All @@ -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");
}
}

0 comments on commit 76bd48f

Please sign in to comment.