Skip to content

Commit

Permalink
With Container::makeWith() method, we have to pass the parameter name.
Browse files Browse the repository at this point in the history
  • Loading branch information
tortuetorche committed Mar 30, 2017
1 parent 581d411 commit 7b13d7f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/StackMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public function wrap($callable, $params = [])
if (is_callable($callable)) {
$middleware = $callable($kernel);
} else {
// Add kernel as first parameter
array_unshift($params, $kernel);
// Add kernel as 'app' parameter
$params = ['app' => $kernel] + $params;
$makeMethod = method_exists($this->container, 'makeWith') ? 'makeWith' : 'make';
$middleware = $this->container->$makeMethod($callable, $params);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function setUp()
{
$this->app = $this->getMockBuilder('Illuminate\Contracts\Container\Container')
->setMethods([
'bind', 'alias', 'tagged', 'tag', 'bindIf', 'bound', 'singleton', 'extend',
'bind', 'alias', 'factory', 'tagged', 'tag', 'bindIf', 'bound', 'singleton', 'extend',
'instance', 'when', 'make', 'call', 'resolved', 'resolving', 'afterResolving',
])->getMock();
$this->serviceProvider = new ServiceProvider($this->app);
Expand All @@ -46,4 +46,4 @@ public function testRegister()

$this->serviceProvider->register();
}
}
}
14 changes: 9 additions & 5 deletions tests/StackMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ class StackMiddlewareTest extends PHPUnit_Framework_TestCase
*/
public function setUp()
{
$this->container = $this->getMock('Illuminate\Contracts\Container\Container');
$this->container = $this->getMockBuilder('Illuminate\Contracts\Container\Container')
->setMethods([
'bind', 'alias', 'factory', 'tagged', 'tag', 'bindIf', 'bound', 'singleton', 'extend',
'instance', 'when', 'make', 'makeWith', 'call', 'resolved', 'resolving', 'afterResolving',
])->getMock();
$this->stackMiddleware = new StackMiddleware($this->container);
}

Expand All @@ -34,13 +38,13 @@ public function testSimpleWrap()
$arg2 = 'arg2';

$this->container->expects($this->once())
->method('make')
->method('makeWith')
->with(
$this->equalTo($middlewareName),
$this->equalTo([new ClosureHttpKernel(), $arg1, $arg2])
$this->equalTo(['app' => new ClosureHttpKernel(), 'env' => $arg1, 'envVar' => $arg2])
)->will($this->returnValue($kernelStub));

$result = $this->stackMiddleware->wrap($middlewareName, [$arg1, $arg2]);
$result = $this->stackMiddleware->wrap($middlewareName, ['env' => $arg1, 'envVar' => $arg2]);

$this->assertNotInstanceOf('Barryvdh\StackMiddleware\TerminableClosureMiddleware', $result);
$this->assertInstanceOf('Barryvdh\StackMiddleware\ClosureMiddleware', $result);
Expand All @@ -57,4 +61,4 @@ public function testAdvancedWrapWithTerminableInterface()

$this->assertInstanceOf('Barryvdh\StackMiddleware\TerminableClosureMiddleware', $result);
}
}
}

0 comments on commit 7b13d7f

Please sign in to comment.