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 testResolveMiddlewareNotCallable(): void { /** @var Application|MockObject $container */ $container = $this->createMock(Application::class); $middleware = new ResolvesMiddlewareTraitImplementation($container); $this->expectException(InvalidArgumentException::class); $middleware->callResolveMiddleware([new stdClass(), 'test']); } /** * @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'); } }