Skip to content

Commit dbec208

Browse files
committed
Implemented specific tests for collect
1 parent 0799410 commit dbec208

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

src/AssetManager/Resolver/AggregateResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function collect()
6060
$collection = array();
6161

6262
foreach ($this->queue as $resolver) {
63-
if (!method_exists($resolver, 'collect') {
63+
if (!method_exists($resolver, 'collect')) {
6464
continue;
6565
}
6666

tests/AssetManagerTest/Resolver/AggregateResolverTest.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
class AggregateResolverTest extends PHPUnit_Framework_TestCase
1010
{
11+
public function setUp()
12+
{
13+
require_once __DIR__ . '/../../_files/ResolverWithCollect.php';
14+
}
15+
1116
public function testResolve()
1217
{
1318
$resolver = new AggregateResolver();
@@ -46,9 +51,9 @@ public function testResolve()
4651

4752
public function testCollect()
4853
{
49-
$resolver = new AggregateResolver();
50-
51-
$lowPriority = $this->getMock('AssetManager\Resolver\ResolverInterface');
54+
/* Tests for interfaces that _do_ implement the `collect` method. */
55+
$resolver = new AggregateResolver();
56+
$lowPriority = $this->getMock('ResolverWithCollect');
5257
$lowPriority
5358
->expects($this->exactly(2))
5459
->method('collect')
@@ -57,7 +62,7 @@ public function testCollect()
5762

5863
$this->assertContains('one', $resolver->collect());
5964

60-
$highPriority = $this->getMock('AssetManager\Resolver\ResolverInterface');
65+
$highPriority = $this->getMock('ResolverWithCollect');
6166
$highPriority
6267
->expects($this->once())
6368
->method('collect')
@@ -69,5 +74,21 @@ public function testCollect()
6974
$this->assertContains('three', $collection);
7075

7176
$this->assertCount(3, $collection);
77+
78+
/* Tests for interfaces that _don't_ implement the `collect` method. */
79+
$resolver = new AggregateResolver();
80+
$lowPriority = $this->getMock('AssetManager\Resolver\ResolverInterface');
81+
82+
$resolver->attach($lowPriority);
83+
84+
$this->assertEquals(array(), $resolver->collect());
85+
86+
$highPriority = $this->getMock('AssetManager\Resolver\ResolverInterface');
87+
$resolver->attach($highPriority, 1000);
88+
89+
$collection = $resolver->collect();
90+
$this->assertEquals(array(), $collection);
91+
92+
$this->assertCount(0, $collection);
7293
}
7394
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
use AssetManager\Resolver\ResolverInterface;
4+
5+
class ResolverWithCollect implements ResolverInterface
6+
{
7+
public function resolve($path)
8+
{
9+
}
10+
11+
public function collect()
12+
{
13+
}
14+
}

0 commit comments

Comments
 (0)