Skip to content

Commit

Permalink
[TASK] Add failed test for logger usage in directive
Browse files Browse the repository at this point in the history
  • Loading branch information
linawolf committed Dec 12, 2023
1 parent 772dac5 commit ec3ec72
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
use phpDocumentor\Guides\RestructuredText\Directives\SidebarDirective;
use phpDocumentor\Guides\RestructuredText\Directives\SubDirective;
use phpDocumentor\Guides\RestructuredText\Directives\TableDirective;
use phpDocumentor\Guides\RestructuredText\Directives\TestLoggerDirective;
use phpDocumentor\Guides\RestructuredText\Directives\TipDirective;
use phpDocumentor\Guides\RestructuredText\Directives\TitleDirective;
use phpDocumentor\Guides\RestructuredText\Directives\ToctreeDirective;
Expand Down Expand Up @@ -209,6 +210,7 @@
->set(SeeAlsoDirective::class)
->set(SidebarDirective::class)
->set(TableDirective::class)
->set(TestLoggerDirective::class)
->set(TipDirective::class)
->set(TitleDirective::class)
->set(ToctreeDirective::class)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace phpDocumentor\Guides\RestructuredText\Directives;

use phpDocumentor\Guides\Nodes\CollectionNode;
use phpDocumentor\Guides\Nodes\Node;
use phpDocumentor\Guides\RestructuredText\Nodes\ContainerNode;
use phpDocumentor\Guides\RestructuredText\Parser\BlockContext;
use phpDocumentor\Guides\RestructuredText\Parser\Directive;
use phpDocumentor\Guides\RestructuredText\Parser\Productions\Rule;
use Psr\Log\LoggerInterface;

/**
* Divs a sub document in a div with a given class or set of classes.
*
* @link https://docutils.sourceforge.io/docs/ref/rst/directives.html#container
*/
class TestLoggerDirective extends SubDirective
{
public function __construct(
protected Rule $startingRule,
private readonly LoggerInterface $logger,
) {
parent::__construct($startingRule);
}

public function getName(): string
{
return 'testlogger';
}

/** {@inheritDoc}
*
* @param Directive $directive
*/
protected function processSub(
BlockContext $blockContext,
CollectionNode $collectionNode,
Directive $directive,
): Node|null {
$this->logger->warning('Test logging in directives', $blockContext->getLoggerInformation());

return (new ContainerNode($collectionNode->getChildren()))->withOptions(['class' => $directive->getData()]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!-- content start -->
<div class="section" id="directive-tests">
<h1>Directive tests</h1>

<p>This is only displayed in HTML.</p>

<p>This is only displayed in both HTML and Latex.</p>
</div>

<!-- content end -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
\documentclass[11pt]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{cite}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{mathrsfs}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{listings}
\begin{document}
\label{}
\section{Directive tests}


This is only displayed in Latex.
This is only displayed in both HTML and Latex.

\end{document}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<guides xmlns="https://www.phpdoc.org/guides"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.phpdoc.org/guides packages/guides-cli/resources/schema/guides.xsd">
<output-format>tex</output-format>
<output-format>interlink</output-format>
<output-format>html</output-format>
</guides>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Directive tests
===============

.. testlogger::

0 comments on commit ec3ec72

Please sign in to comment.