forked from featherforums/feather
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtensionTest.php
More file actions
90 lines (76 loc) · 3.38 KB
/
Copy pathExtensionTest.php
File metadata and controls
90 lines (76 loc) · 3.38 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
use Mockery as m;
class ExtensionTest extends PHPUnit_Framework_TestCase {
public function testExtensionsAreBootstrapped()
{
list($app, $dispatcher) = $this->getApplicationAndDispatcher();
$extension = array('location' => 'extension/location', 'identifier' => 'foo', 'auto' => true);
$dispatcher->register($extension);
$this->assertEquals('success', $app['events']->first('start_test'));
}
public function testExtensionsCanListenForEvents()
{
list($app, $dispatcher) = $this->getApplicationAndDispatcher();
$extension = array('location' => 'extension/location', 'identifier' => 'foo', 'auto' => true);
$extension = $dispatcher->register($extension);
$extension['loaded']['Feather\Extensions\extension\location\FooExtension']->listen('foobar', function()
{
return 'barfoo';
});
$extension['loaded']['Feather\Extensions\extension\location\FooExtension']->listen('barfoo', function()
{
return 'foobar';
});
$this->assertEquals('barfoo', $app['events']->first('foobar'));
$this->assertEquals('foobar', $app['events']->first('barfoo'));
}
public function testExtensionsCanOverrideEvents()
{
list($app, $dispatcher) = $this->getApplicationAndDispatcher();
$extension = array('location' => 'extension/location', 'identifier' => 'foo', 'auto' => true);
$extension = $dispatcher->register($extension);
$extension['loaded']['Feather\Extensions\extension\location\FooExtension']->listen('foobar', function()
{
return 'barfoo';
});
$extension['loaded']['Feather\Extensions\extension\location\FooExtension']->override('foobar', function()
{
return 'barbar';
});
$this->assertEquals('barbar', $app['events']->first('foobar'));
}
public function testExtensionsCanUseMethods()
{
list($app, $dispatcher) = $this->getApplicationAndDispatcher();
$extension = array('location' => 'extension/location', 'identifier' => 'foo', 'auto' => true);
$extension = $dispatcher->register($extension);
$extension['loaded']['Feather\Extensions\extension\location\FooExtension']->listen('foobar', 'foo');
$this->assertEquals('foomethod', $app['events']->first('foobar'));
}
protected function getApplicationAndDispatcher()
{
$app = new Illuminate\Container;
$app['events'] = new Illuminate\Events\Dispatcher;
$app['files'] = m::mock('Illuminate\Filesystem');
$app['files']->shouldReceive('exists')->once()->andReturn(true);
$dispatcher = m::mock('Feather\Extensions\Dispatcher[findExtensions,loadExtension]');
$dispatcher->__construct($app['files'], 'path/to');
$dispatcher->setApplication($app);
$file = m::mock('stdClass');
$file->shouldReceive('getBasename')->once()->andReturn('FooExtension');
$file->shouldReceive('getExtension')->once()->andReturn('php');
$instantiatedExtension = m::mock('Feather\Extensions\Extension[start]');
$instantiatedExtension->__construct($app);
$instantiatedExtension->shouldReceive('foo')->andReturn('foomethod');
$instantiatedExtension->shouldReceive('start')->once()->andReturnUsing(function() use ($instantiatedExtension)
{
$instantiatedExtension->listen('start_test', function()
{
return 'success';
});
});
$dispatcher->shouldReceive('findExtensions')->once()->with('path/to/extension/location')->andReturn(array($file));
$dispatcher->shouldReceive('loadExtension')->with('Feather\Extensions\extension\location\FooExtension')->andReturn($instantiatedExtension);
return array($app, $dispatcher);
}
}