createMock(Application::class); $middlewareInterface = $this->getMockForAbstractClass(MiddlewareInterface::class); $callable = [HasStaticMethod::class, 'foo']; $container->expects($this->exactly(3)) ->method('make') ->withConsecutive( ['FooBarClass'], [CallableHandler::class, ['callable' => $callable]], ['UnresolvableClass'] ) ->willReturnOnConsecutiveCalls( $middlewareInterface, $middlewareInterface, null ); $middleware = new ResolvesMiddlewareTraitImplementation($container); $return = $middleware->callResolveMiddleware('FooBarClass'); $this->assertEquals($middlewareInterface, $return); $return = $middleware->callResolveMiddleware($callable); $this->assertEquals($middlewareInterface, $return); $this->expectException(InvalidArgumentException::class); $middleware->callResolveMiddleware('UnresolvableClass'); } /** * @covers \Engelsystem\Middleware\ResolvesMiddlewareTrait::resolveMiddleware */ public function testResolveMiddlewareNoContainer(): void { $middlewareInterface = $this->getMockForAbstractClass(MiddlewareInterface::class); $middleware = new ResolvesMiddlewareTraitImplementation(); $return = $middleware->callResolveMiddleware($middlewareInterface); $this->assertEquals($middlewareInterface, $return); $this->expectException(InvalidArgumentException::class); $middleware->callResolveMiddleware('FooBarClass'); } }