expectExceptionMessage("Sorry!"); $this->expectException(\Aws\S3\Exception\S3Exception::class); $parser = function () { throw new ParserException('Sorry!'); }; $instance = new RetryableMalformedResponseParser( $parser, S3Exception::class ); $instance( $this->getMockBuilder(CommandInterface::class)->getMock(), $this->getMockBuilder(ResponseInterface::class)->getMock() ); } }