createMock(Parser::class); $environment = $this->createMock(Environment::class); $nodeFactory = $this->createMock(NodeFactory::class); $eventManager = $this->createMock(EventManager::class); $codeBlockDirective = $this->createMock(Directive::class); $errorManager = $this->createMock(ErrorManager::class); $docParser = new DocumentParser( $parser, $environment, $nodeFactory, $eventManager, ['code-block' => $codeBlockDirective], true, __DIR__ ); $codeBlockDirective->expects(self::once()) ->method('process') ->willThrowException(new Exception('Invalid something something!')); $codeBlockDirective->expects(self::once()) ->method('getName') ->willReturn('code-block-name'); $environment->expects(self::once()) ->method('getErrorManager') ->willReturn($errorManager); $errorManager->expects(self::once()) ->method('error') ->with('Error while processing "code-block-name" directive: "Invalid something something!"'); $docParser->parse('.. code-block:: php'); } }