-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathExtensionDispatcherTest.php
More file actions
66 lines (53 loc) · 2.52 KB
/
Copy pathExtensionDispatcherTest.php
File metadata and controls
66 lines (53 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
use Mockery as m;
use Feather\Models\Extension;
class ExtensionDispatcherTest extends TestCase {
public function testDispatcherRegisterExtension()
{
$dispatcher = $this->getDispatcher();
$extension = array('location' => 'extension/location', 'identifier' => 'foo', 'auto' => false);
$dispatcher->register($extension);
$this->assertEquals('foo', $dispatcher['extension.foo']['identifier']);
$this->assertEquals('extension/location', $dispatcher['extension.foo']['location']);
$this->assertTrue($dispatcher->isRegistered('foo'));
}
public function testDispatcherRegistersExtensionsFromArray()
{
$dispatcher = $this->getDispatcher();
$extension = array('location' => 'extension/location', 'identifier' => 'foo', 'auto' => false);
$dispatcher->registerExtensions(array($extension));
$this->assertEquals('foo', $dispatcher['extension.foo']['identifier']);
$this->assertEquals('extension/location', $dispatcher['extension.foo']['location']);
}
public function testDispatcherAutoStartExtension()
{
$app = new Illuminate\Container;
$app['events'] = new Illuminate\Events\Dispatcher;
$files = m::mock('Illuminate\Filesystem');
$files->shouldReceive('exists')->once()->andReturn(true);
$dispatcher = m::mock('Feather\Extensions\Dispatcher[findExtensions,loadExtension]');
$dispatcher->__construct($files, 'path/to');
$dispatcher->setApplication($app);
$extension = array('location' => 'extension/location', 'identifier' => 'foo', 'auto' => true);
$file = m::mock('stdClass');
$file->shouldReceive('getBasename')->once()->andReturn('FooExtension');
$file->shouldReceive('getExtension')->once()->andReturn('php');
$instantiatedExtension = m::mock('Feather\Extensions\Extension');
$instantiatedExtension->shouldReceive('start')->once();
$dispatcher->shouldReceive('findExtensions')->once()->with('path/to/extension/location')->andReturn(array($file));
$dispatcher->shouldReceive('loadExtension')->with('Feather\Extensions\extension\location\FooExtension')->andReturn($instantiatedExtension);
$dispatcher->register($extension);
$this->assertContains('foo', $dispatcher->getStarted());
$this->assertTrue($dispatcher->isStarted('foo'));
}
protected function getDispatcher()
{
$app = new Illuminate\Container;
$app['events'] = new Illuminate\Events\Dispatcher;
$files = m::mock('Illuminate\Filesystem');
$files->shouldReceive('exists')->once()->andReturn(true);
$dispatcher = m::mock(new Feather\Extensions\Dispatcher($files, 'path/to'));
$dispatcher->setApplication($app);
return $dispatcher;
}
}