Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazzap committed Sep 15, 2016
2 parents 780f72c + 18e4c73 commit 78e6ca8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
39 changes: 36 additions & 3 deletions tests/src/ArrayMergeRecursiveContextCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

use Brain\Context\ArrayMergeRecursiveContextCollector;
use Brain\Context\ContextProviderInterface;
use Brain\Context\ArrayMergeContextCollector;
use Brain\Context\UpdatableContextProviderInterface;
use Brain\Monkey\WP\Actions;

/**
Expand All @@ -23,6 +23,33 @@
class ArrayMergeRecursiveContextCollectorTest extends TestCase
{

public function testProvideDoNothingWithNoQuery()
{
$collector = new ArrayMergeRecursiveContextCollector();

$query = \Mockery::mock('WP_Query');

$context = \Mockery::mock(ContextProviderInterface::class);
$context->shouldReceive('accept')
->zeroOrMoreTimes()
->with($query)
->andReturn(true);
$context->shouldReceive('provide')
->zeroOrMoreTimes()
->andReturn([
'message' => 'Hello!',
'letters' => ['a']
]);

Actions::expectFired('brain.context.added')
->once()
->with($context, \Mockery::type('SplQueue'));

$collector->addProvider($context);

assertSame([], $collector->provide());
}

public function testProvide()
{
$collector = new ArrayMergeRecursiveContextCollector();
Expand All @@ -31,7 +58,7 @@ public function testProvide()

$context_a = \Mockery::mock(ContextProviderInterface::class);
$context_b = clone $context_a;
$context_c = clone $context_b;
$context_c = \Mockery::mock(UpdatableContextProviderInterface::class);

$context_a->shouldReceive('accept')->once()->with($query)->andReturn(true);
$context_b->shouldReceive('accept')->once()->with($query)->andReturn(false);
Expand All @@ -53,6 +80,12 @@ public function testProvide()
'color' => 'yellow'
]);

$context_c->shouldReceive('update')->once()->andReturnUsing(function(array $context) {
$context['message'] = implode(', ', (array) $context['message']);

return $context;
});

Actions::expectFired('brain.context.added')
->times(3)
->with(\Mockery::type(ContextProviderInterface::class), \Mockery::type('SplQueue'));
Expand All @@ -65,7 +98,7 @@ public function testProvide()
$collector->accept($query);

$expected = [
'message' => ['Hello from A!', 'Hello from C!'],
'message' => 'Hello from A!, Hello from C!',
'letters' => ['a', 'b', 'c', 'd'],
'color' => 'yellow'
];
Expand Down
12 changes: 12 additions & 0 deletions tests/src/WpContextLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Brain\Context\Tests;

use Brain\Context\ContextCollectorInterface;
use Brain\Context\ContextProviderInterface;
use Brain\Context\UpdatableContextProviderInterface;
use Brain\Context\WpContextLoader;
Expand All @@ -25,6 +26,17 @@
class WpContextLoaderTest extends TestCase
{

public function testLoadNothingIfCollectorNotAcceptQuery()
{
$query = \Mockery::mock('WP_Query');

$collector = \Mockery::mock(ContextCollectorInterface::class);
$collector->shouldReceive('accept')->once()->with($query)->andReturn(false);
$collector->shouldReceive('provide')->never();

assertSame([], WpContextLoader::load($query, $collector));
}

public function testLoad()
{
$query = \Mockery::mock('WP_Query');
Expand Down

0 comments on commit 78e6ca8

Please sign in to comment.