From 22db58aa9e593b14704c5e723e0430b925b80e8f Mon Sep 17 00:00:00 2001 From: Bastien Miclo Date: Tue, 15 Aug 2023 15:45:08 +0200 Subject: [PATCH 1/4] Add attribute_precedence option --- .../NodeCompiler/AssignmentNodeCompiler.php | 11 +- .../NodeCompiler/AttributeNodeCompiler.php | 2 + .../NodeCompiler/ElementNodeCompiler.php | 6 + .../AssignmentContainerInterface.php | 3 +- .../AbstractAssignmentContainerElement.php | 12 +- .../Formatter/Element/AssignmentElement.php | 12 +- .../Formatter/Element/AttributeElement.php | 5 +- .../Formatter/Element/MarkupElement.php | 15 +- .../Formatter/Formatter/Format/XmlFormat.php | 170 ++++++++++++++++-- .../Parser/Parser/Node/AssignmentNode.php | 5 +- src/Phug/Parser/Parser/Node/AttributeNode.php | 5 +- src/Phug/Parser/Parser/Node/ElementNode.php | 5 +- src/Phug/Parser/Parser/Node/MixinCallNode.php | 5 +- src/Phug/Parser/Parser/Node/MixinNode.php | 5 +- .../TokenHandler/AssignmentTokenHandler.php | 1 + .../TokenHandler/AttributeTokenHandler.php | 11 +- .../Util/Util/AttributesOrderInterface.php | 17 ++ src/Phug/Util/Util/AttributesStorage.php | 45 +++++ src/Phug/Util/Util/OrderableInterface.php | 22 +++ src/Phug/Util/Util/OrderedValue.php | 24 +++ src/Phug/Util/Util/Partial/AttributeTrait.php | 3 +- .../Util/Partial/AttributesOrderTrait.php | 19 ++ src/Phug/Util/Util/Partial/OrderTrait.php | 31 ++++ src/Phug/Util/Util/Partial/ValueTrait.php | 8 +- tests/Phug/AbstractCompilerTest.php | 103 +---------- .../AssignmentNodeCompilerTest.php | 4 + tests/Phug/Format/XmlFormatTest.php | 157 ++++++++++++++++ tests/Phug/Utils/AssertRender.php | 114 ++++++++++++ 28 files changed, 678 insertions(+), 142 deletions(-) create mode 100644 src/Phug/Util/Util/AttributesOrderInterface.php create mode 100644 src/Phug/Util/Util/AttributesStorage.php create mode 100644 src/Phug/Util/Util/OrderableInterface.php create mode 100644 src/Phug/Util/Util/OrderedValue.php create mode 100644 src/Phug/Util/Util/Partial/AttributesOrderTrait.php create mode 100644 src/Phug/Util/Util/Partial/OrderTrait.php create mode 100644 tests/Phug/Utils/AssertRender.php diff --git a/src/Phug/Compiler/Compiler/NodeCompiler/AssignmentNodeCompiler.php b/src/Phug/Compiler/Compiler/NodeCompiler/AssignmentNodeCompiler.php index 4d9e5f66..3048ce6c 100644 --- a/src/Phug/Compiler/Compiler/NodeCompiler/AssignmentNodeCompiler.php +++ b/src/Phug/Compiler/Compiler/NodeCompiler/AssignmentNodeCompiler.php @@ -8,6 +8,8 @@ use Phug\Parser\Node\AssignmentNode; use Phug\Parser\Node\AttributeNode; use Phug\Parser\NodeInterface; +use Phug\Util\AttributesStorage; +use Phug\Util\OrderableInterface; use SplObjectStorage; class AssignmentNodeCompiler extends AbstractNodeCompiler @@ -25,9 +27,16 @@ public function compileNode(NodeInterface $node, ElementInterface $parent = null */ $name = $node->getName(); $attributes = new SplObjectStorage(); + foreach ($node->getAttributes() as $attribute) { /* @var AttributeNode $attribute */ - $attributes->attach($this->getCompiler()->compileNode($attribute, $parent)); + $attributeElement = $this->getCompiler()->compileNode($attribute, $parent); + + if ($attribute instanceof OrderableInterface && $attributeElement instanceof OrderableInterface) { + $attributeElement->setOrder($attribute->getOrder()); + } + + $attributes->attach($attributeElement); } return new AssignmentElement($name, $attributes, null, $node); diff --git a/src/Phug/Compiler/Compiler/NodeCompiler/AttributeNodeCompiler.php b/src/Phug/Compiler/Compiler/NodeCompiler/AttributeNodeCompiler.php index 6601f4a9..76bfb299 100644 --- a/src/Phug/Compiler/Compiler/NodeCompiler/AttributeNodeCompiler.php +++ b/src/Phug/Compiler/Compiler/NodeCompiler/AttributeNodeCompiler.php @@ -9,6 +9,7 @@ use Phug\Formatter\ElementInterface; use Phug\Parser\Node\AttributeNode; use Phug\Parser\NodeInterface; +use Phug\Util\OrderableInterface; class AttributeNodeCompiler extends AbstractNodeCompiler { @@ -71,6 +72,7 @@ public function compileNode(NodeInterface $node, ElementInterface $parent = null $name = $this->compileName($node); $value = $this->compileValue($node); $attribute = new AttributeElement($name, $value, $node); + $attribute->setOrder($node->getOrder()); $attribute->setIsVariadic($node->isVariadic()); return $attribute; diff --git a/src/Phug/Compiler/Compiler/NodeCompiler/ElementNodeCompiler.php b/src/Phug/Compiler/Compiler/NodeCompiler/ElementNodeCompiler.php index b45ce09f..e342b0e8 100644 --- a/src/Phug/Compiler/Compiler/NodeCompiler/ElementNodeCompiler.php +++ b/src/Phug/Compiler/Compiler/NodeCompiler/ElementNodeCompiler.php @@ -9,6 +9,7 @@ use Phug\Parser\Node\ElementNode; use Phug\Parser\Node\ExpressionNode; use Phug\Parser\NodeInterface; +use Phug\Util\OrderableInterface; use SplObjectStorage; class ElementNodeCompiler extends AbstractNodeCompiler @@ -35,6 +36,11 @@ public function compileNode(NodeInterface $node, ElementInterface $parent = null $markup = new MarkupElement($name, $node->isAutoClosed(), $attributes, $node); foreach ($node->getAssignments() as $assignment) { $compiledAssignment = $compiler->compileNode($assignment, $parent); + + if ($compiledAssignment instanceof OrderableInterface && $assignment instanceof OrderableInterface) { + $compiledAssignment->setOrder($assignment->getOrder()); + } + if ($compiledAssignment instanceof AssignmentElement) { $markup->addAssignment($compiledAssignment); } diff --git a/src/Phug/Formatter/Formatter/AssignmentContainerInterface.php b/src/Phug/Formatter/Formatter/AssignmentContainerInterface.php index 90c84d16..04dbd69e 100644 --- a/src/Phug/Formatter/Formatter/AssignmentContainerInterface.php +++ b/src/Phug/Formatter/Formatter/AssignmentContainerInterface.php @@ -3,8 +3,9 @@ namespace Phug\Formatter; use Phug\Formatter\Element\AssignmentElement; +use Phug\Util\AttributesOrderInterface; -interface AssignmentContainerInterface extends ElementInterface +interface AssignmentContainerInterface extends ElementInterface, AttributesOrderInterface { public function getName(); diff --git a/src/Phug/Formatter/Formatter/Element/AbstractAssignmentContainerElement.php b/src/Phug/Formatter/Formatter/Element/AbstractAssignmentContainerElement.php index df206ebe..a46bc3c0 100644 --- a/src/Phug/Formatter/Formatter/Element/AbstractAssignmentContainerElement.php +++ b/src/Phug/Formatter/Formatter/Element/AbstractAssignmentContainerElement.php @@ -4,10 +4,16 @@ use Phug\Formatter\AbstractElement; use Phug\Formatter\AssignmentContainerInterface; +use Phug\Util\Partial\AttributesOrderTrait; use SplObjectStorage; abstract class AbstractAssignmentContainerElement extends AbstractElement implements AssignmentContainerInterface { + use AttributesOrderTrait; + + /** + * @var SplObjectStorage + */ private $assignments; /** @@ -19,6 +25,10 @@ abstract class AbstractAssignmentContainerElement extends AbstractElement implem */ public function addAssignment(AssignmentElement $element) { + if ($element->getOrder() === null) { + $element->setOrder($this->getNextAttributeIndex()); + } + $element->setContainer($this); $this->getAssignments()->attach($element); @@ -42,7 +52,7 @@ public function removedAssignment(AssignmentElement $element) /** * Return markup assignments list. * - * @return SplObjectStorage[AssignmentElement] + * @return SplObjectStorage */ public function getAssignments() { diff --git a/src/Phug/Formatter/Formatter/Element/AssignmentElement.php b/src/Phug/Formatter/Formatter/Element/AssignmentElement.php index f4ed42cf..2bbcd6a9 100644 --- a/src/Phug/Formatter/Formatter/Element/AssignmentElement.php +++ b/src/Phug/Formatter/Formatter/Element/AssignmentElement.php @@ -7,27 +7,31 @@ use Phug\Formatter\AssignmentContainerInterface; use Phug\Parser\NodeInterface as ParserNode; use Phug\Util\AttributesInterface; +use Phug\Util\OrderableInterface; use Phug\Util\Partial\AttributeTrait; use Phug\Util\Partial\NameTrait; +use Phug\Util\Partial\OrderTrait; +use SplObjectStorage; -class AssignmentElement extends AbstractElement implements AttributesInterface +class AssignmentElement extends AbstractElement implements AttributesInterface, OrderableInterface { use AttributeTrait; use NameTrait; + use OrderTrait; /** * AssignmentElement constructor. * * @param string $name - * @param \SplObjectStorage|null $attributes - * @param AssignmentContainerInterface|null $markup + * @param SplObjectStorage|null $attributes + * @param AssignmentContainerInterface|null $container * @param ParserNode|null $originNode * @param NodeInterface|null $parent * @param array|null $children */ public function __construct( $name, - \SplObjectStorage $attributes = null, + SplObjectStorage $attributes = null, AssignmentContainerInterface $container = null, ParserNode $originNode = null, NodeInterface $parent = null, diff --git a/src/Phug/Formatter/Formatter/Element/AttributeElement.php b/src/Phug/Formatter/Formatter/Element/AttributeElement.php index db3caae2..9e929b17 100644 --- a/src/Phug/Formatter/Formatter/Element/AttributeElement.php +++ b/src/Phug/Formatter/Formatter/Element/AttributeElement.php @@ -4,12 +4,15 @@ use Phug\Ast\NodeInterface; use Phug\Parser\NodeInterface as ParserNode; +use Phug\Util\OrderableInterface; use Phug\Util\Partial\NameTrait; +use Phug\Util\Partial\OrderTrait; use Phug\Util\Partial\VariadicTrait; -class AttributeElement extends AbstractValueElement +class AttributeElement extends AbstractValueElement implements OrderableInterface { use NameTrait; + use OrderTrait; use VariadicTrait; /** diff --git a/src/Phug/Formatter/Formatter/Element/MarkupElement.php b/src/Phug/Formatter/Formatter/Element/MarkupElement.php index b8182bd6..a79cc2d4 100644 --- a/src/Phug/Formatter/Formatter/Element/MarkupElement.php +++ b/src/Phug/Formatter/Formatter/Element/MarkupElement.php @@ -7,6 +7,7 @@ use Phug\Util\AttributesInterface; use Phug\Util\Partial\AttributeTrait; use Phug\Util\Partial\NameTrait; +use SplObjectStorage; class MarkupElement extends AbstractMarkupElement implements AttributesInterface { @@ -21,17 +22,17 @@ class MarkupElement extends AbstractMarkupElement implements AttributesInterface /** * MarkupElement constructor. * - * @param string $name - * @param bool $autoClosed - * @param \SplObjectStorage|null $attributes - * @param ParserNode|null $originNode - * @param NodeInterface|null $parent - * @param array|null $children + * @param string $name + * @param bool $autoClosed + * @param SplObjectStorage|null $attributes + * @param ParserNode|null $originNode + * @param NodeInterface|null $parent + * @param array|null $children */ public function __construct( $name, $autoClosed = false, - \SplObjectStorage $attributes = null, + SplObjectStorage $attributes = null, ParserNode $originNode = null, NodeInterface $parent = null, array $children = null diff --git a/src/Phug/Formatter/Formatter/Format/XmlFormat.php b/src/Phug/Formatter/Formatter/Format/XmlFormat.php index a801f939..c4da4062 100644 --- a/src/Phug/Formatter/Formatter/Format/XmlFormat.php +++ b/src/Phug/Formatter/Formatter/Format/XmlFormat.php @@ -2,7 +2,9 @@ namespace Phug\Formatter\Format; +use Closure; use Generator; +use InvalidArgumentException; use Phug\Formatter; use Phug\Formatter\AbstractFormat; use Phug\Formatter\AssignmentContainerInterface; @@ -20,6 +22,7 @@ use Phug\FormatterException; use Phug\Util\AttributesInterface; use Phug\Util\Joiner; +use Phug\Util\OrderedValue; use SplObjectStorage; class XmlFormat extends AbstractFormat @@ -268,17 +271,65 @@ protected function yieldAssignmentElement(AssignmentElement $element) /* @var MarkupElement $markup */ $markup = $element->getContainer(); + $attributeOrder = $this->hasOption('attribute_precedence') + ? $this->getOption('attribute_precedence') + : 'assignment'; + + switch ($attributeOrder) { + case 'assignment': + case 'assignments': + $arguments = array_merge( + $markup instanceof AttributesInterface + ? $this->formatMarkupAttributes($markup) + : [], + $markup instanceof AssignmentContainerInterface + ? $this->formatAttributeAssignments($markup) + : [] + ); + break; - $arguments = $markup instanceof AssignmentContainerInterface - ? $this->formatAttributeAssignments($markup) - : []; + case 'attribute': + case 'attributes': + $arguments = array_merge( + $markup instanceof AssignmentContainerInterface + ? $this->formatAttributeAssignments($markup) + : [], + $markup instanceof AttributesInterface + ? $this->formatMarkupAttributes($markup) + : [] + ); + break; - $arguments = array_merge( - $markup instanceof AttributesInterface - ? $this->formatMarkupAttributes($markup) - : [], - $arguments - ); + case 'left': + $arguments = $this->getSortedAttributes($markup, static function (OrderedValue $a, OrderedValue $b) { + return $b->getOrder() - $a->getOrder(); + }); + break; + + case 'right': + $arguments = $this->getSortedAttributes($markup, static function (OrderedValue $a, OrderedValue $b) { + return $a->getOrder() - $b->getOrder(); + }); + break; + + default: + if (!is_callable($attributeOrder)) { + throw new InvalidArgumentException( + 'Option attribute_precedence must be "assignment" (default), "attribute", "left", "right" or a callable.' + ); + } + + $arguments = array_map(static function ($argument) { + return $argument instanceof OrderedValue ? $argument->getValue() : $argument; + }, $attributeOrder( + $markup instanceof AssignmentContainerInterface + ? $this->formatOrderedAttributeAssignments($markup) + : [], + $markup instanceof AttributesInterface + ? $this->formatOrderedMarkupAttributes($markup) + : [] + )); + } foreach ($markup->getAssignments() as $assignment) { /* @var AssignmentElement $assignment */ @@ -303,22 +354,48 @@ protected function formatAttributeAssignments(AssignmentContainerInterface $mark $arguments = []; foreach ($this->yieldAssignmentAttributes($markup) as $attribute) { - $checked = method_exists($attribute, 'isChecked') && $attribute->isChecked(); + $arguments[] = $this->formatInnerCodeValue($attribute); + } - while (method_exists($attribute, 'getValue')) { - $attribute = $attribute->getValue(); - } + return $arguments; + } - $arguments[] = $this->formatCode($attribute, $checked); + /** + * @param AssignmentContainerInterface $markup + * + * @return list> + */ + protected function formatOrderedAttributeAssignments(AssignmentContainerInterface $markup) + { + $arguments = []; + + foreach ($this->yieldAssignmentOrderedAttributes($markup) as $attribute => $order) { + $arguments[] = new OrderedValue($this->formatInnerCodeValue($attribute), $order); } return $arguments; } + /** + * @param AbstractValueElement|mixed $value + * + * @return string + */ + protected function formatInnerCodeValue($value) + { + $checked = method_exists($value, 'isChecked') && $value->isChecked(); + + while (method_exists($value, 'getValue')) { + $value = $value->getValue(); + } + + return $this->formatCode($value, $checked); + } + /** * @param AssignmentContainerInterface $markup * - * @return Generator|AbstractValueElement[] + * @return Generator */ protected function yieldAssignmentAttributes(AssignmentContainerInterface $markup) { @@ -333,10 +410,28 @@ protected function yieldAssignmentAttributes(AssignmentContainerInterface $marku } } + /** + * @param AssignmentContainerInterface $markup + * + * @return Generator + */ + protected function yieldAssignmentOrderedAttributes(AssignmentContainerInterface $markup) + { + foreach ($markup->getAssignmentsByName('attributes') as $attributesAssignment) { + /* @var AssignmentElement $attributesAssignment */ + foreach ($attributesAssignment->getAttributes() as $attribute) { + /* @var AbstractValueElement $attribute */ + yield $attribute => $attributesAssignment->getOrder(); + } + + $markup->removedAssignment($attributesAssignment); + } + } + /** * @param AttributesInterface $markup * - * @return array + * @return list */ protected function formatMarkupAttributes(AttributesInterface $markup) { @@ -353,6 +448,26 @@ protected function formatMarkupAttributes(AttributesInterface $markup) return $arguments; } + /** + * @param AttributesInterface $markup + * + * @return list> + */ + protected function formatOrderedMarkupAttributes(AttributesInterface $markup) + { + $arguments = []; + $attributes = $markup->getAttributes(); + + foreach ($attributes as $attribute) { + /* @var AttributeElement $attribute */ + $arguments[] = new OrderedValue($this->formatAttributeAsArrayItem($attribute), $attribute->getOrder()); + } + + $attributes->removeAll($attributes); + + return $arguments; + } + /** * @param AssignmentElement $element * @@ -441,4 +556,27 @@ protected function formatMarkupElement(MarkupElement $element) ? $this->getIndent().$tag.$this->getNewLine() : $tag; } + + /** + * @param AssignmentContainerInterface|AttributesInterface|mixed $markup + * @param Closure(OrderedValue, OrderedValue): int $sorter + * + * @return list + */ + private function getSortedAttributes($markup, Closure $sorter) + { + $arguments = array_merge( + $markup instanceof AssignmentContainerInterface + ? $this->formatOrderedAttributeAssignments($markup) + : [], + $markup instanceof AttributesInterface + ? $this->formatOrderedMarkupAttributes($markup) + : [] + ); + usort($arguments, $sorter); + + return array_map(static function (OrderedValue $value) { + return $value->getValue(); + }, $arguments); + } } diff --git a/src/Phug/Parser/Parser/Node/AssignmentNode.php b/src/Phug/Parser/Parser/Node/AssignmentNode.php index 10a383fd..b23f30bc 100644 --- a/src/Phug/Parser/Parser/Node/AssignmentNode.php +++ b/src/Phug/Parser/Parser/Node/AssignmentNode.php @@ -4,11 +4,14 @@ use Phug\Parser\Node; use Phug\Util\AttributesInterface; +use Phug\Util\OrderableInterface; use Phug\Util\Partial\AttributeTrait; use Phug\Util\Partial\NameTrait; +use Phug\Util\Partial\OrderTrait; -class AssignmentNode extends Node implements AttributesInterface +class AssignmentNode extends Node implements AttributesInterface, OrderableInterface { use NameTrait; use AttributeTrait; + use OrderTrait; } diff --git a/src/Phug/Parser/Parser/Node/AttributeNode.php b/src/Phug/Parser/Parser/Node/AttributeNode.php index e1d5b5b3..5475078a 100644 --- a/src/Phug/Parser/Parser/Node/AttributeNode.php +++ b/src/Phug/Parser/Parser/Node/AttributeNode.php @@ -3,17 +3,20 @@ namespace Phug\Parser\Node; use Phug\Parser\Node; +use Phug\Util\OrderableInterface; use Phug\Util\Partial\CheckTrait; use Phug\Util\Partial\EscapeTrait; use Phug\Util\Partial\NameTrait; +use Phug\Util\Partial\OrderTrait; use Phug\Util\Partial\ValueTrait; use Phug\Util\Partial\VariadicTrait; -class AttributeNode extends Node +class AttributeNode extends Node implements OrderableInterface { use NameTrait; use ValueTrait; use EscapeTrait; use CheckTrait; use VariadicTrait; + use OrderTrait; } diff --git a/src/Phug/Parser/Parser/Node/ElementNode.php b/src/Phug/Parser/Parser/Node/ElementNode.php index edf1c8ff..9317ba02 100644 --- a/src/Phug/Parser/Parser/Node/ElementNode.php +++ b/src/Phug/Parser/Parser/Node/ElementNode.php @@ -4,15 +4,18 @@ use Phug\Parser\Node; use Phug\Util\AttributesInterface; +use Phug\Util\AttributesOrderInterface; use Phug\Util\Partial\AssignmentTrait; +use Phug\Util\Partial\AttributesOrderTrait; use Phug\Util\Partial\AttributeTrait; use Phug\Util\Partial\NameTrait; -class ElementNode extends Node implements AttributesInterface +class ElementNode extends Node implements AttributesInterface, AttributesOrderInterface { use NameTrait; use AttributeTrait; use AssignmentTrait; + use AttributesOrderTrait; /** * @var bool diff --git a/src/Phug/Parser/Parser/Node/MixinCallNode.php b/src/Phug/Parser/Parser/Node/MixinCallNode.php index 9e8da4f8..ddaf6cb1 100644 --- a/src/Phug/Parser/Parser/Node/MixinCallNode.php +++ b/src/Phug/Parser/Parser/Node/MixinCallNode.php @@ -4,15 +4,18 @@ use Phug\Parser\Node; use Phug\Util\AttributesInterface; +use Phug\Util\AttributesOrderInterface; use Phug\Util\Partial\AssignmentTrait; +use Phug\Util\Partial\AttributesOrderTrait; use Phug\Util\Partial\AttributeTrait; use Phug\Util\Partial\NameTrait; -class MixinCallNode extends Node implements AttributesInterface +class MixinCallNode extends Node implements AttributesInterface, AttributesOrderInterface { use NameTrait; use AttributeTrait; use AssignmentTrait; + use AttributesOrderTrait; /** * @var bool diff --git a/src/Phug/Parser/Parser/Node/MixinNode.php b/src/Phug/Parser/Parser/Node/MixinNode.php index c4f91027..aca64dc2 100644 --- a/src/Phug/Parser/Parser/Node/MixinNode.php +++ b/src/Phug/Parser/Parser/Node/MixinNode.php @@ -4,13 +4,16 @@ use Phug\Parser\Node; use Phug\Util\AttributesInterface; +use Phug\Util\AttributesOrderInterface; use Phug\Util\Partial\AssignmentTrait; +use Phug\Util\Partial\AttributesOrderTrait; use Phug\Util\Partial\AttributeTrait; use Phug\Util\Partial\NameTrait; -class MixinNode extends Node implements AttributesInterface +class MixinNode extends Node implements AttributesInterface, AttributesOrderInterface { use NameTrait; use AttributeTrait; use AssignmentTrait; + use AttributesOrderTrait; } diff --git a/src/Phug/Parser/Parser/TokenHandler/AssignmentTokenHandler.php b/src/Phug/Parser/Parser/TokenHandler/AssignmentTokenHandler.php index a6e23367..edff3a0a 100644 --- a/src/Phug/Parser/Parser/TokenHandler/AssignmentTokenHandler.php +++ b/src/Phug/Parser/Parser/TokenHandler/AssignmentTokenHandler.php @@ -39,6 +39,7 @@ public function handleToken(TokenInterface $token, State $state) /** @var ElementNode|MixinCallNode $current */ $current = $state->getCurrentNode(); + $node->setOrder($current->getNextAttributeIndex()); $current->getAssignments()->attach($node); if ($state->expectNext([AttributeStartToken::class])) { diff --git a/src/Phug/Parser/Parser/TokenHandler/AttributeTokenHandler.php b/src/Phug/Parser/Parser/TokenHandler/AttributeTokenHandler.php index beec4ef9..6ec3381d 100644 --- a/src/Phug/Parser/Parser/TokenHandler/AttributeTokenHandler.php +++ b/src/Phug/Parser/Parser/TokenHandler/AttributeTokenHandler.php @@ -10,6 +10,8 @@ use Phug\Parser\Node\MixinCallNode; use Phug\Parser\State; use Phug\Parser\TokenHandlerInterface; +use Phug\Util\AttributesOrderInterface; +use Phug\Util\OrderableInterface; class AttributeTokenHandler implements TokenHandlerInterface { @@ -46,8 +48,15 @@ public function handleToken(TokenInterface $token, State $state) } } - /** @var ElementNode|MixinCallNode $current */ + /** @var ElementNode|MixinCallNode|AssignmentNode $current */ $current = $state->getCurrentNode(); + + if ($current instanceof AttributesOrderInterface) { + $node->setOrder($current->getNextAttributeIndex()); + } elseif ($current instanceof OrderableInterface) { + $node->setOrder($current->getOrder()); + } + $current->getAttributes()->attach($node); } } diff --git a/src/Phug/Util/Util/AttributesOrderInterface.php b/src/Phug/Util/Util/AttributesOrderInterface.php new file mode 100644 index 00000000..d1c0fe00 --- /dev/null +++ b/src/Phug/Util/Util/AttributesOrderInterface.php @@ -0,0 +1,17 @@ +holder = $holder; + } + + #[ReturnTypeWillChange] + public function attach($object, $info = null) + { + if ( + $object instanceof OrderableInterface && + $object->getOrder() === null && + $this->holder instanceof AttributesOrderInterface + ) { + $object->setOrder($this->holder->getNextAttributeIndex()); + } + + parent::attach($object, $info); + } + + #[ReturnTypeWillChange] + public function addAll($storage) + { + if ($storage && $this->holder instanceof AttributesOrderInterface) { + foreach ($storage as $element) { + if ($element instanceof OrderableInterface && $element->getOrder() === null) { + $element->setOrder($this->holder->getNextAttributeIndex()); + } + } + } + + parent::addAll($storage); + } +} diff --git a/src/Phug/Util/Util/OrderableInterface.php b/src/Phug/Util/Util/OrderableInterface.php new file mode 100644 index 00000000..ba2b5822 --- /dev/null +++ b/src/Phug/Util/Util/OrderableInterface.php @@ -0,0 +1,22 @@ + + */ +class OrderedValue implements OrderableInterface +{ + use ValueTrait; + use OrderTrait; + + public function __construct($value, $order) + { + $this->value = $value; + $this->order = $order; + } +} diff --git a/src/Phug/Util/Util/Partial/AttributeTrait.php b/src/Phug/Util/Util/Partial/AttributeTrait.php index d83add87..908dbdd0 100644 --- a/src/Phug/Util/Util/Partial/AttributeTrait.php +++ b/src/Phug/Util/Util/Partial/AttributeTrait.php @@ -2,6 +2,7 @@ namespace Phug\Util\Partial; +use Phug\Util\AttributesStorage; use SplObjectStorage; /** @@ -20,7 +21,7 @@ trait AttributeTrait public function getAttributes() { if (!$this->attributes) { - $this->attributes = new SplObjectStorage(); + $this->attributes = new AttributesStorage($this); } return $this->attributes; diff --git a/src/Phug/Util/Util/Partial/AttributesOrderTrait.php b/src/Phug/Util/Util/Partial/AttributesOrderTrait.php new file mode 100644 index 00000000..eb4891e0 --- /dev/null +++ b/src/Phug/Util/Util/Partial/AttributesOrderTrait.php @@ -0,0 +1,19 @@ +attributeIndex++; + } +} diff --git a/src/Phug/Util/Util/Partial/OrderTrait.php b/src/Phug/Util/Util/Partial/OrderTrait.php new file mode 100644 index 00000000..fd30a142 --- /dev/null +++ b/src/Phug/Util/Util/Partial/OrderTrait.php @@ -0,0 +1,31 @@ +order; + } + + /** + * @param int|null $order + */ + public function setOrder($order) + { + $this->order = $order; + } +} diff --git a/src/Phug/Util/Util/Partial/ValueTrait.php b/src/Phug/Util/Util/Partial/ValueTrait.php index 65a509fa..c5ece4b4 100644 --- a/src/Phug/Util/Util/Partial/ValueTrait.php +++ b/src/Phug/Util/Util/Partial/ValueTrait.php @@ -4,18 +4,20 @@ /** * Class ValueTrait. + * + * @template T of mixed */ trait ValueTrait { use StaticMemberTrait; /** - * @var mixed + * @var T */ private $value = null; /** - * @return mixed + * @return T */ public function getValue() { @@ -31,7 +33,7 @@ public function hasStaticValue() } /** - * @param mixed $value + * @param T $value * * @return $this */ diff --git a/tests/Phug/AbstractCompilerTest.php b/tests/Phug/AbstractCompilerTest.php index cf65e624..259d51e2 100644 --- a/tests/Phug/AbstractCompilerTest.php +++ b/tests/Phug/AbstractCompilerTest.php @@ -6,14 +6,12 @@ use JsPhpize\JsPhpize; use Phug\Compiler; use Phug\CompilerEvent; +use Phug\Test\Utils\AssertRender; use Phug\Util\TestCase; abstract class AbstractCompilerTest extends TestCase { - /** - * @var Compiler - */ - protected $compiler; + use AssertRender; protected function expectMessageToBeThrown($message, $type = null) { @@ -27,17 +25,6 @@ protected function expectMessageToBeThrown($message, $type = null) $this->setExpectedException($type ?: Exception::class, $message, null); } - protected function prepareTest() - { - $this->compiler = new Compiler([ - 'paths' => [__DIR__.'/../templates'], - 'patterns' => [ - 'expression_in_text' => '%s', - 'expression_in_bool' => '%s', - ], - ]); - } - protected function enableJsPhpize() { $compiler = $this->compiler; @@ -104,90 +91,4 @@ protected function enableJsPhpize() $this->compiler = $compiler; } - - protected function implodeLines($str) - { - return preg_replace_callback('/(\s+[a-z0-9:_-]+="(?:\\\\[\\S\\s]|[^"\\\\])*")+/', function ($matches) { - $attributes = []; - $input = $matches[0]; - while (mb_strlen($input) && preg_match( - '/^\s+([a-z0-9:_-]+)="((?:\\\\[\\S\\s]|[^"\\\\])*)"/', - $input, - $match - )) { - if ($match[1] === 'class') { - $classes = explode(' ', $match[2]); - sort($classes); - $match[2] = implode(' ', $classes); - } - $attributes[] = trim($match[1]).'="'.$match[2].'"'; - $input = mb_substr($input, mb_strlen($match[0])); - } - sort($attributes); - - return ' '.implode(' ', $attributes); - }, is_string($str) ? $str : implode('', $str)); - } - - protected function assertSameLines($expected, $actual) - { - self::assertSame($this->implodeLines($expected), $this->implodeLines($actual)); - } - - protected function assertCompile($expected, $actual, array $options = []) - { - $compiler = clone $this->compiler; - $compiler->setOptionsRecursive($options); - - return $this->assertSameLines($expected, $compiler->compile($this->implodeLines($actual))); - } - - protected function assertCompileFile($expected, $actual) - { - return $this->assertSameLines($expected, $this->compiler->compileFile($actual)); - } - - protected function getRenderedHtml($php, array $variables = []) - { - if (getenv('LOG_COMPILE')) { - file_put_contents('temp.php', $php); - } - extract($variables); - ob_start(); - eval('?>'.$php); - $actual = ob_get_contents(); - ob_end_clean(); - - return $actual; - } - - protected function render($actual, array $options = [], array $variables = []) - { - $compiler = $this->compiler; - $compiler->setOptionsRecursive($options); - $php = $compiler->compile($this->implodeLines($actual)); - - return $this->getRenderedHtml($php, $variables); - } - - protected function assertRender($expected, $actual, array $options = [], array $variables = []) - { - $actual = $this->render($actual, $options, $variables); - - return $this->assertSameLines($expected, $actual); - } - - protected function assertRenderFile($expected, $actual, array $options = [], array $variables = []) - { - $compiler = $this->compiler; - $compiler->setOptionsRecursive($options); - $php = $compiler->compileFile($actual); - $actual = preg_replace( - '/\s(class|id)=""/', - '', - $this->getRenderedHtml($php, $variables) - ); - - return $this->assertSameLines($expected, $actual); - } } diff --git a/tests/Phug/Compiler/NodeCompiler/AssignmentNodeCompilerTest.php b/tests/Phug/Compiler/NodeCompiler/AssignmentNodeCompilerTest.php index adc08544..aa54dc94 100644 --- a/tests/Phug/Compiler/NodeCompiler/AssignmentNodeCompilerTest.php +++ b/tests/Phug/Compiler/NodeCompiler/AssignmentNodeCompilerTest.php @@ -38,6 +38,10 @@ public function testCompile() '', 'a&attributes(["href" => "/"])(href="#")' ); + $this->assertRender( + '', + 'a(href="#")&attributes(["href" => "/"])&attributes(["id" => "biz"])#boom(id="bam")' + ); } /** diff --git a/tests/Phug/Format/XmlFormatTest.php b/tests/Phug/Format/XmlFormatTest.php index eb5091f0..a4a70cb1 100644 --- a/tests/Phug/Format/XmlFormatTest.php +++ b/tests/Phug/Format/XmlFormatTest.php @@ -2,6 +2,7 @@ namespace Phug\Test\Format; +use InvalidArgumentException; use PHPUnit\Framework\TestCase; use Phug\Formatter; use Phug\Formatter\Element\AssignmentElement; @@ -17,6 +18,8 @@ use Phug\Formatter\Format\BasicFormat; use Phug\Formatter\Format\XmlFormat; use Phug\Parser\Node\TextNode; +use Phug\Test\Utils\AssertRender; +use Phug\Util\OrderedValue; use SplObjectStorage; /** @@ -24,6 +27,8 @@ */ class XmlFormatTest extends TestCase { + use AssertRender; + /** * @covers ::__construct * @covers \Phug\Formatter\AbstractFormat::__construct @@ -636,6 +641,7 @@ public function testNativePhpHelperCall() * @covers ::yieldAssignmentAttributes * @covers ::formatMarkupAttributes * @covers ::formatAttributes + * @covers ::formatInnerCodeValue */ public function testAttributeAssignmentsOption() { @@ -669,6 +675,157 @@ public function testAttributeAssignmentsOption() ); } + /** + * @covers ::yieldAssignmentElement + * @covers ::formatOrderedAttributeAssignments + * @covers ::formatOrderedMarkupAttributes + * @covers ::formatInnerCodeValue + */ + public function testAttributeAttributePrecedence() + { + $this->prepareTest(); + + // Take Attribute over Assignment + $this->assertRender( + '', + 'a&attributes(["href" => "#"])', + ['attribute_precedence' => 'attribute'] + ); + $this->assertRender( + '', + 'a.foo(class=["bar", "biz"])&attributes(["class" => "bar fiz"])', + ['attribute_precedence' => 'attribute'] + ); + $this->assertRender( + '', + 'a.foo(class=["bar", "biz"])&attributes(["class" => "bar fiz"])', + ['attribute_precedence' => 'attribute'] + ); + $this->assertRender( + '', + 'a(href="#")&attributes(["href" => "/"])', + ['attribute_precedence' => 'attribute'] + ); + $this->assertRender( + '', + 'a&attributes(["href" => "/"])(href="#")', + ['attribute_precedence' => 'attribute'] + ); + $this->assertRender( + '', + 'a(href="#")&attributes(["href" => "/"])&attributes(["id" => "biz"])#boom(id="bam")', + ['attribute_precedence' => 'attribute'] + ); + + // Left + $this->assertRender( + '', + 'a&attributes(["href" => "#"])', + ['attribute_precedence' => 'left'] + ); + $this->assertRender( + '', + 'a.foo(class=["bar", "biz"])&attributes(["class" => "bar fiz"])', + ['attribute_precedence' => 'left'] + ); + $this->assertRender( + '', + 'a.foo(class=["bar", "biz"])&attributes(["class" => "bar fiz"])', + ['attribute_precedence' => 'left'] + ); + $this->assertRender( + '', + 'a(href="#")&attributes(["href" => "/"])', + ['attribute_precedence' => 'left'] + ); + $this->assertRender( + '', + 'a&attributes(["href" => "/"])(href="#")', + ['attribute_precedence' => 'left'] + ); + $this->assertRender( + '', + 'a(href="#")&attributes(["href" => "/"])&attributes(["id" => "biz"])#boom(id="bam")', + ['attribute_precedence' => 'left'] + ); + $this->assertRender( + '', + 'a(href="#")&attributes(["href" => "/"])#boom&attributes(["id" => "biz"])(id="bam")', + ['attribute_precedence' => 'left'] + ); + + // Right + $this->assertRender( + '', + 'a&attributes(["href" => "#"])', + ['attribute_precedence' => 'right'] + ); + $this->assertRender( + '', + 'a.foo(class=["bar", "biz"])&attributes(["class" => "bar fiz"])', + ['attribute_precedence' => 'right'] + ); + $this->assertRender( + '', + 'a.foo(class=["bar", "biz"])&attributes(["class" => "bar fiz"])', + ['attribute_precedence' => 'right'] + ); + $this->assertRender( + '', + 'a(href="#")&attributes(["href" => "/"])', + ['attribute_precedence' => 'right'] + ); + $this->assertRender( + '', + 'a&attributes(["href" => "/"])(href="#")', + ['attribute_precedence' => 'right'] + ); + $this->assertRender( + '', + 'a(href="#")&attributes(["href" => "/"])&attributes(["id" => "biz"])#boom(id="bam")', + ['attribute_precedence' => 'right'] + ); + $this->assertRender( + '', + 'a(href="#")&attributes(["href" => "/"])&attributes(["id" => "biz"])(id="bam")#boom', + ['attribute_precedence' => 'right'] + ); + + $this->assertRender( + '', + 'a(href="#stuff")&attributes(["href" => "/"])&attributes(["id" => "biz"])#boom(id="bam")', + ['attribute_precedence' => static function (array $assignments, array $attributes) { + $arguments = array_merge($assignments, $attributes); + + usort($arguments, static function (OrderedValue $a, OrderedValue $b) { + return strlen($a->getValue()) - strlen($b->getValue()); + }); + + return $arguments; + }] + ); + } + + /** + * @covers ::yieldAssignmentElement + * @covers ::formatOrderedAttributeAssignments + * @covers ::formatOrderedMarkupAttributes + * @covers ::formatInnerCodeValue + */ + public function testAttributeAttributePrecedenceFailure() + { + self::expectExceptionObject(new InvalidArgumentException( + 'Option attribute_precedence must be "assignment" (default), "attribute", "left", "right" or a callable.', + )); + + $this->prepareTest(); + + $this->render( + 'a&attributes(["href" => "#"])', + ['attribute_precedence' => 'unknown'] + ); + } + /** * @covers \Phug\Formatter\AbstractFormat::setFormatter */ diff --git a/tests/Phug/Utils/AssertRender.php b/tests/Phug/Utils/AssertRender.php new file mode 100644 index 00000000..77a68d9e --- /dev/null +++ b/tests/Phug/Utils/AssertRender.php @@ -0,0 +1,114 @@ +compiler)) { + return; + } + + $this->compiler = new Compiler([ + 'paths' => [__DIR__.'/../templates'], + 'patterns' => [ + 'expression_in_text' => '%s', + 'expression_in_bool' => '%s', + ], + ]); + } + + protected function implodeLines($str) + { + return preg_replace_callback('/(\s+[a-z0-9:_-]+="(?:\\\\[\\S\\s]|[^"\\\\])*")+/', function ($matches) { + $attributes = []; + $input = $matches[0]; + while (mb_strlen($input) && preg_match( + '/^\s+([a-z0-9:_-]+)="((?:\\\\[\\S\\s]|[^"\\\\])*)"/', + $input, + $match + )) { + if ($match[1] === 'class') { + $classes = explode(' ', $match[2]); + sort($classes); + $match[2] = implode(' ', $classes); + } + $attributes[] = trim($match[1]).'="'.$match[2].'"'; + $input = mb_substr($input, mb_strlen($match[0])); + } + sort($attributes); + + return ' '.implode(' ', $attributes); + }, is_string($str) ? $str : implode('', $str)); + } + + protected function assertSameLines($expected, $actual) + { + self::assertSame($this->implodeLines($expected), $this->implodeLines($actual)); + } + + protected function assertCompile($expected, $actual, array $options = []) + { + $compiler = clone $this->compiler; + $compiler->setOptionsRecursive($options); + + $this->assertSameLines($expected, $compiler->compile($this->implodeLines($actual))); + } + + protected function assertCompileFile($expected, $actual) + { + $this->assertSameLines($expected, $this->compiler->compileFile($actual)); + } + + protected function getRenderedHtml($php, array $variables = []) + { + if (getenv('LOG_COMPILE')) { + file_put_contents('temp.php', $php); + } + extract($variables); + ob_start(); + eval('?>'.$php); + $actual = ob_get_contents(); + ob_end_clean(); + + return $actual; + } + + protected function render($actual, array $options = [], array $variables = []) + { + $compiler = $this->compiler; + $compiler->setOptionsRecursive($options); + $php = $compiler->compile($this->implodeLines($actual)); + + return $this->getRenderedHtml($php, $variables); + } + + protected function assertRender($expected, $actual, array $options = [], array $variables = []) + { + $actual = $this->render($actual, $options, $variables); + + $this->assertSameLines($expected, $actual); + } + + protected function assertRenderFile($expected, $actual, array $options = [], array $variables = []) + { + $compiler = $this->compiler; + $compiler->setOptionsRecursive($options); + $php = $compiler->compileFile($actual); + $actual = preg_replace( + '/\s(class|id)=""/', + '', + $this->getRenderedHtml($php, $variables) + ); + + $this->assertSameLines($expected, $actual); + } +} From af424efdb8489eb5f8650e8a403d61bad9d0e5d6 Mon Sep 17 00:00:00 2001 From: Bastien Miclo Date: Tue, 15 Aug 2023 17:59:54 +0200 Subject: [PATCH 2/4] Fix PHPDoc --- src/Phug/Ast/Ast/Node.php | 1 - .../NodeCompiler/AssignmentNodeCompiler.php | 1 - .../NodeCompiler/AttributeNodeCompiler.php | 1 - .../Compiler/Compiler/NodeCompilerInterface.php | 2 +- src/Phug/Formatter/Formatter/AbstractFormat.php | 13 ++++++++----- .../Formatter/Formatter/Format/XmlFormat.php | 5 +++-- .../Partial/AssignmentHelpersTrait.php | 2 +- src/Phug/Lexer/Lexer/State.php | 9 ++++----- src/Phug/Parser/Parser.php | 2 +- src/Phug/Parser/Parser/Event/NodeEvent.php | 5 +++-- src/Phug/Reader/Reader.php | 6 +++--- src/Phug/Renderer/Renderer/CacheInterface.php | 2 +- .../Renderer/Partial/Debug/DebuggerTrait.php | 3 +++ .../Renderer/Renderer/Profiler/LinkDump.php | 4 ++-- src/Phug/Util/Util/AttributesStorage.php | 3 +-- src/Phug/Util/Util/OrderedValue.php | 1 + src/Phug/Util/Util/Partial/OrderTrait.php | 4 ---- tests/Phug/AbstractCompilerTest.php | 1 - tests/Phug/Adapter/FileAdapterTest.php | 4 ++++ tests/Phug/Ast/NodeTest.php | 8 ++++++++ tests/Phug/CasesTest.php | 2 ++ tests/Phug/CliTest.php | 8 ++++++++ .../AssignmentListNodeCompilerTest.php | 1 + .../NodeCompiler/AssignmentNodeCompilerTest.php | 1 + .../NodeCompiler/AttributeListCompilerTest.php | 1 + .../NodeCompiler/AttributeNodeCompilerTest.php | 2 ++ .../NodeCompiler/BlockNodeCompilerTest.php | 2 ++ .../NodeCompiler/CaseNodeCompilerTest.php | 1 + .../NodeCompiler/CodeNodeCompilerTest.php | 1 + .../NodeCompiler/CommentNodeCompilerTest.php | 1 + .../ConditionalNodeCompilerTest.php | 1 + .../NodeCompiler/DoNodeCompilerTest.php | 1 + .../NodeCompiler/DoctypeNodeCompilerTest.php | 1 + .../NodeCompiler/DocumentNodeCompilerTest.php | 1 + .../NodeCompiler/EachNodeCompilerTest.php | 1 + .../NodeCompiler/ElementNodeCompilerTest.php | 1 + .../NodeCompiler/ExpressionNodeCompilerTest.php | 1 + .../NodeCompiler/FilterNodeCompilerTest.php | 3 +++ .../NodeCompiler/ImportNodeCompilerTest.php | 3 +++ .../NodeCompiler/KeywordNodeCompilerTest.php | 1 + .../NodeCompiler/MixinCallNodeCompilerTest.php | 8 ++++++++ .../NodeCompiler/MixinNodeCompilerTest.php | 5 +++++ .../NodeCompiler/TextNodeCompilerTest.php | 1 + .../NodeCompiler/VariableNodeCompilerTest.php | 2 ++ .../NodeCompiler/WhenNodeCompilerTest.php | 1 + .../NodeCompiler/WhileNodeCompilerTest.php | 2 ++ .../NodeCompiler/YieldNodeCompilerTest.php | 1 + tests/Phug/CompilerModuleTest.php | 4 ++++ tests/Phug/CompilerTest.php | 17 +++++++++++++++++ tests/Phug/Element/AssignmentElementTest.php | 2 ++ tests/Phug/Element/KeywordElementTest.php | 2 ++ tests/Phug/Event/ListenerQueueTest.php | 5 +++++ tests/Phug/Format/HtmlFormatTest.php | 4 ++++ tests/Phug/Format/XmlFormatTest.php | 8 ++++---- tests/Phug/FormatterTest.php | 2 ++ tests/Phug/Invoker/InvokerTest.php | 2 ++ .../Phug/Lexer/Scanner/AttributeScannerTest.php | 1 + tests/Phug/Lexer/Scanner/CaseScannerTest.php | 1 + tests/Phug/Lexer/Scanner/ClassScannerTest.php | 3 --- .../Lexer/Scanner/ConditionalScannerTest.php | 3 +++ tests/Phug/Lexer/Scanner/DoScannerTest.php | 2 -- tests/Phug/Lexer/Scanner/DoctypeScannerTest.php | 1 - tests/Phug/Lexer/Scanner/EachScannerTest.php | 12 ++++++++---- tests/Phug/Lexer/Scanner/ForScannerTest.php | 1 + .../Lexer/Scanner/IndentationScannerTest.php | 2 ++ tests/Phug/Lexer/Scanner/WhenScannerTest.php | 2 +- tests/Phug/Lexer/Scanner/WhileScannerTest.php | 1 + tests/Phug/Lexer/StateTest.php | 16 ++++++++++++++++ tests/Phug/LexerModuleTest.php | 2 ++ tests/Phug/LexerTest.php | 3 +++ tests/Phug/OptimizerTest.php | 2 ++ tests/Phug/Parser/StateTest.php | 8 ++++++++ .../TokenHandler/AssignmentTokenHandlerTest.php | 4 ++++ .../AttributeEndTokenHandlerTest.php | 2 ++ .../AttributeStartTokenHandlerTest.php | 6 ++++++ .../TokenHandler/AttributeTokenHandlerTest.php | 2 ++ .../TokenHandler/AutoCloseTokenHandlerTest.php | 4 ++++ .../TokenHandler/BlockTokenHandlerTest.php | 2 ++ .../TokenHandler/CaseTokenHandlerTest.php | 2 ++ .../TokenHandler/ClassTokenHandlerTest.php | 4 ++++ .../TokenHandler/CodeTokenHandlerTest.php | 4 ++++ .../TokenHandler/CommentTokenHandlerTest.php | 2 ++ .../ConditionalTokenHandlerTest.php | 2 ++ .../Parser/TokenHandler/DoTokenHandlerTest.php | 2 ++ .../TokenHandler/DoctypeTokenHandlerTest.php | 2 ++ .../TokenHandler/EachTokenHandlerTest.php | 2 ++ .../TokenHandler/ExpansionTokenHandlerTest.php | 2 ++ .../TokenHandler/ExpressionTokenHandlerTest.php | 2 ++ .../TokenHandler/FilterTokenHandlerTest.php | 2 ++ .../Parser/TokenHandler/ForTokenHandlerTest.php | 2 ++ .../Parser/TokenHandler/IdTokenHandlerTest.php | 4 ++++ .../TokenHandler/ImportTokenHandlerTest.php | 8 ++++++++ .../TokenHandler/IndentTokenHandlerTest.php | 2 ++ .../InterpolationEndTokenHandlerTest.php | 2 ++ .../InterpolationStartTokenHandlerTest.php | 4 ++++ .../TokenHandler/KeywordTokenHandlerTest.php | 2 ++ .../TokenHandler/MixinCallTokenHandlerTest.php | 2 ++ .../TokenHandler/MixinTokenHandlerTest.php | 2 ++ .../TokenHandler/NewLineTokenHandlerTest.php | 2 ++ .../TokenHandler/OutdentTokenHandlerTest.php | 2 ++ .../TagInterpolationEndTokenHandlerTest.php | 2 ++ .../TagInterpolationStartTokenHandlerTest.php | 2 ++ .../Parser/TokenHandler/TagTokenHandlerTest.php | 6 ++++++ .../TokenHandler/TextTokenHandlerTest.php | 2 ++ .../TokenHandler/VariableTokenHandlerTest.php | 2 ++ .../TokenHandler/WhenTokenHandlerTest.php | 2 ++ .../TokenHandler/WhileTokenHandlerTest.php | 2 ++ .../TokenHandler/YieldTokenHandlerTest.php | 2 ++ tests/Phug/ParserModuleTest.php | 1 + tests/Phug/ParserTest.php | 6 ++++++ tests/Phug/PhugTest.php | 4 ++++ tests/Phug/ProfilerModuleTest.php | 11 +++++++++++ tests/Phug/ReaderTest.php | 11 ++++++++++- tests/Phug/RendererTest.php | 3 +++ tests/Phug/Util/AssociativeStorageTest.php | 4 ++++ tests/Phug/Util/MacroableTraitTest.php | 4 ++++ tests/Phug/Util/ModuleContainerTest.php | 14 ++++++++++++++ tests/Phug/Util/UnorderedArgumentsTest.php | 8 ++++++++ tests/Phug/Utils/AssertRender.php | 10 +++++----- 119 files changed, 357 insertions(+), 54 deletions(-) diff --git a/src/Phug/Ast/Ast/Node.php b/src/Phug/Ast/Ast/Node.php index 8b646c30..5dbdc8e9 100644 --- a/src/Phug/Ast/Ast/Node.php +++ b/src/Phug/Ast/Ast/Node.php @@ -370,7 +370,6 @@ public function findChildren(callable $callback, $depth = null, $level = null) $level = $level ?: 0; foreach ($this->children as $child) { - /** @var NodeInterface $child */ if ($child->is($callback)) { yield $child; diff --git a/src/Phug/Compiler/Compiler/NodeCompiler/AssignmentNodeCompiler.php b/src/Phug/Compiler/Compiler/NodeCompiler/AssignmentNodeCompiler.php index 3048ce6c..74df6392 100644 --- a/src/Phug/Compiler/Compiler/NodeCompiler/AssignmentNodeCompiler.php +++ b/src/Phug/Compiler/Compiler/NodeCompiler/AssignmentNodeCompiler.php @@ -8,7 +8,6 @@ use Phug\Parser\Node\AssignmentNode; use Phug\Parser\Node\AttributeNode; use Phug\Parser\NodeInterface; -use Phug\Util\AttributesStorage; use Phug\Util\OrderableInterface; use SplObjectStorage; diff --git a/src/Phug/Compiler/Compiler/NodeCompiler/AttributeNodeCompiler.php b/src/Phug/Compiler/Compiler/NodeCompiler/AttributeNodeCompiler.php index 76bfb299..896c9145 100644 --- a/src/Phug/Compiler/Compiler/NodeCompiler/AttributeNodeCompiler.php +++ b/src/Phug/Compiler/Compiler/NodeCompiler/AttributeNodeCompiler.php @@ -9,7 +9,6 @@ use Phug\Formatter\ElementInterface; use Phug\Parser\Node\AttributeNode; use Phug\Parser\NodeInterface; -use Phug\Util\OrderableInterface; class AttributeNodeCompiler extends AbstractNodeCompiler { diff --git a/src/Phug/Compiler/Compiler/NodeCompilerInterface.php b/src/Phug/Compiler/Compiler/NodeCompilerInterface.php index ae9a5d6e..1522f816 100644 --- a/src/Phug/Compiler/Compiler/NodeCompilerInterface.php +++ b/src/Phug/Compiler/Compiler/NodeCompilerInterface.php @@ -11,7 +11,7 @@ interface NodeCompilerInterface { /** - * @param $nodeList + * @param $nodeList * @param ElementInterface $parent * * @return array diff --git a/src/Phug/Formatter/Formatter/AbstractFormat.php b/src/Phug/Formatter/Formatter/AbstractFormat.php index 963297f4..10fa316d 100644 --- a/src/Phug/Formatter/Formatter/AbstractFormat.php +++ b/src/Phug/Formatter/Formatter/AbstractFormat.php @@ -233,7 +233,7 @@ protected function getDebugInfo($element) /** * @param string|ElementInterface $element * @param bool $noDebug - * @param $element + * @param $element * * @return string */ @@ -460,13 +460,16 @@ protected function formatDynamicValue($formattedName, $value) return 'null'; } - if ($value instanceof ExpressionElement && - in_array(($code = strtolower($value->getValue())), ['true', 'false', 'null', 'undefined']) - ) { - return $code; + if ($value instanceof ExpressionElement) { + $code = strtolower($value->getValue()); + + if (in_array($code, ['true', 'false', 'null', 'undefined'])) { + return $code; + } } $code = $this->formatAssignmentValue($value); + if ($value instanceof ExpressionElement && $value->isEscaped()) { return $this->exportHelper('array_escape', [$formattedName, $code]); } diff --git a/src/Phug/Formatter/Formatter/Format/XmlFormat.php b/src/Phug/Formatter/Formatter/Format/XmlFormat.php index c4da4062..6928e21d 100644 --- a/src/Phug/Formatter/Formatter/Format/XmlFormat.php +++ b/src/Phug/Formatter/Formatter/Format/XmlFormat.php @@ -315,7 +315,8 @@ protected function yieldAssignmentElement(AssignmentElement $element) default: if (!is_callable($attributeOrder)) { throw new InvalidArgumentException( - 'Option attribute_precedence must be "assignment" (default), "attribute", "left", "right" or a callable.' + 'Option attribute_precedence must be '. + '"assignment" (default), "attribute", "left", "right" or a callable.' ); } @@ -559,7 +560,7 @@ protected function formatMarkupElement(MarkupElement $element) /** * @param AssignmentContainerInterface|AttributesInterface|mixed $markup - * @param Closure(OrderedValue, OrderedValue): int $sorter + * @param Closure(OrderedValue, OrderedValue): int $sorter * * @return list */ diff --git a/src/Phug/Formatter/Formatter/Partial/AssignmentHelpersTrait.php b/src/Phug/Formatter/Formatter/Partial/AssignmentHelpersTrait.php index 93c87071..f5ec8c3b 100644 --- a/src/Phug/Formatter/Formatter/Partial/AssignmentHelpersTrait.php +++ b/src/Phug/Formatter/Formatter/Partial/AssignmentHelpersTrait.php @@ -37,7 +37,7 @@ function ($attributeAssignments) { return function (&$attributes, $name, $value) use ($attributeAssignments) { if (isset($name) && $name !== '') { $result = $attributeAssignments($attributes, $name, $value); - if (($result !== null && $result !== false && ($result !== '' || $name !== 'class'))) { + if ($result !== null && $result !== false && ($result !== '' || $name !== 'class')) { $attributes[$name] = $result; } } diff --git a/src/Phug/Lexer/Lexer/State.php b/src/Phug/Lexer/Lexer/State.php index c7f0d054..a1c7f5a2 100644 --- a/src/Phug/Lexer/Lexer/State.php +++ b/src/Phug/Lexer/Lexer/State.php @@ -241,7 +241,6 @@ public function scan($scanners, array $options = []) $scanners = $this->filterScanners($scanners); foreach ($scanners as $scanner) { - /** @var ScannerInterface $scanner */ $success = false; foreach ($scanner->scan($this, $options) as $token) { @@ -267,7 +266,7 @@ public function scan($scanners, array $options = []) * If the second argument is true, it will throw an exception if none of the scanners * produced any valid tokens. The reading also stops when the end of the input as been reached. * - * @param $scanners + * @param $scanners * @param bool $required * * @throws LexerException @@ -346,9 +345,9 @@ public function createToken($className) * in scanners as you can simply return it's value without having to check for it to be null. * * - * @param $className - * @param $pattern - * @param null $modifiers + * @param class-string $className + * @param string $pattern + * @param string|null $modifiers * * @return iterable */ diff --git a/src/Phug/Parser/Parser.php b/src/Phug/Parser/Parser.php index bca4a48f..1f807255 100644 --- a/src/Phug/Parser/Parser.php +++ b/src/Phug/Parser/Parser.php @@ -330,8 +330,8 @@ public function parse($input, $path = null) foreach ($expandingNodes as $expandingNode) { $current = $expandingNode; - while ($outerNode = $expandingNode->getOuterNode()) { + while ($outerNode = $expandingNode->getOuterNode()) { /** @var NodeInterface $expandedNode */ $expandedNode = $outerNode; $current->setOuterNode(null); diff --git a/src/Phug/Parser/Parser/Event/NodeEvent.php b/src/Phug/Parser/Parser/Event/NodeEvent.php index 9502eb0c..e45ca7ab 100644 --- a/src/Phug/Parser/Parser/Event/NodeEvent.php +++ b/src/Phug/Parser/Parser/Event/NodeEvent.php @@ -4,6 +4,7 @@ use Phug\Event; use Phug\Parser\NodeInterface; +use Phug\ParserEvent; class NodeEvent extends Event { @@ -12,8 +13,8 @@ class NodeEvent extends Event /** * NodeEvent constructor. * - * @param $name - * @param NodeInterface $node + * @param ParserEvent::* $name + * @param NodeInterface $node */ public function __construct($name, NodeInterface $node) { diff --git a/src/Phug/Reader/Reader.php b/src/Phug/Reader/Reader.php index 5cc93461..8b28ba24 100644 --- a/src/Phug/Reader/Reader.php +++ b/src/Phug/Reader/Reader.php @@ -313,9 +313,9 @@ public function peek($length = null, $start = null) * * Notice that ^ is automatically prepended to the pattern. * - * @param string $pattern the regular expression without slashes or modifiers. - * @param string $modifiers the modifiers for the regular expression. - * @param string $ignoredSuffixes characters that are scanned, but don't end up in the consume length. + * @param string $pattern the regular expression without slashes or modifiers. + * @param string|null $modifiers the modifiers for the regular expression. + * @param string|null $ignoredSuffixes characters that are scanned, but don't end up in the consume length. * * @throws ReaderException * diff --git a/src/Phug/Renderer/Renderer/CacheInterface.php b/src/Phug/Renderer/Renderer/CacheInterface.php index c1968eca..d7260197 100644 --- a/src/Phug/Renderer/Renderer/CacheInterface.php +++ b/src/Phug/Renderer/Renderer/CacheInterface.php @@ -11,7 +11,7 @@ interface CacheInterface /** * Return the cached file path after cache optional process. * - * @param $path + * @param string $path * @param string $input pug input * @param callable $rendered method to compile the source into PHP * @param bool $success diff --git a/src/Phug/Renderer/Renderer/Partial/Debug/DebuggerTrait.php b/src/Phug/Renderer/Renderer/Partial/Debug/DebuggerTrait.php index fe5c1aec..42a69d84 100644 --- a/src/Phug/Renderer/Renderer/Partial/Debug/DebuggerTrait.php +++ b/src/Phug/Renderer/Renderer/Partial/Debug/DebuggerTrait.php @@ -180,6 +180,7 @@ private function getRendererException($error, $code, $line, $offset, $source, $s /** * @return bool + * * @codeCoverageIgnore */ private function hasColorSupport() @@ -200,6 +201,7 @@ private function hasColorSupport() /** * @return bool + * * @codeCoverageIgnore */ private function hasStdOutVt100Support() @@ -211,6 +213,7 @@ private function hasStdOutVt100Support() /** * @return bool + * * @codeCoverageIgnore */ private function isStdOutATTY() diff --git a/src/Phug/Renderer/Renderer/Profiler/LinkDump.php b/src/Phug/Renderer/Renderer/Profiler/LinkDump.php index 28388312..65897c34 100644 --- a/src/Phug/Renderer/Renderer/Profiler/LinkDump.php +++ b/src/Phug/Renderer/Renderer/Profiler/LinkDump.php @@ -33,11 +33,11 @@ private function initProperties($name, $events) foreach ([ ['current', EndLexEvent::class, 'lexing', [ 'background' => '#7200c4', - 'color' => 'white', + 'color' => 'white', ]], ['current', HtmlEvent::class, 'rendering', [ 'background' => '#648481', - 'color' => 'white', + 'color' => 'white', ]], ['previous', CompileEvent::class, '%s', [ 'background' => '#ffff78', diff --git a/src/Phug/Util/Util/AttributesStorage.php b/src/Phug/Util/Util/AttributesStorage.php index bb7d2d5e..dc85b43d 100644 --- a/src/Phug/Util/Util/AttributesStorage.php +++ b/src/Phug/Util/Util/AttributesStorage.php @@ -18,8 +18,7 @@ public function __construct($holder) #[ReturnTypeWillChange] public function attach($object, $info = null) { - if ( - $object instanceof OrderableInterface && + if ($object instanceof OrderableInterface && $object->getOrder() === null && $this->holder instanceof AttributesOrderInterface ) { diff --git a/src/Phug/Util/Util/OrderedValue.php b/src/Phug/Util/Util/OrderedValue.php index ef11b69d..897f9c5f 100644 --- a/src/Phug/Util/Util/OrderedValue.php +++ b/src/Phug/Util/Util/OrderedValue.php @@ -9,6 +9,7 @@ * Class OrderedValue. * * @template T + * * @template-implements ValueTrait */ class OrderedValue implements OrderableInterface diff --git a/src/Phug/Util/Util/Partial/OrderTrait.php b/src/Phug/Util/Util/Partial/OrderTrait.php index fd30a142..72a73398 100644 --- a/src/Phug/Util/Util/Partial/OrderTrait.php +++ b/src/Phug/Util/Util/Partial/OrderTrait.php @@ -2,10 +2,6 @@ namespace Phug\Util\Partial; -use ArrayAccess; -use ArrayObject; -use Phug\Util\Collection; - trait OrderTrait { /** diff --git a/tests/Phug/AbstractCompilerTest.php b/tests/Phug/AbstractCompilerTest.php index 259d51e2..2dab4758 100644 --- a/tests/Phug/AbstractCompilerTest.php +++ b/tests/Phug/AbstractCompilerTest.php @@ -78,7 +78,6 @@ protected function enableJsPhpize() }); $compiler->attach(CompilerEvent::OUTPUT, function (Compiler\Event\OutputEvent $event) use ($compiler) { - /** @var JsPhpize $jsPhpize */ $jsPhpize = $compiler->getOption('jsphpize_engine'); $dependencies = $jsPhpize->compileDependencies(); diff --git a/tests/Phug/Adapter/FileAdapterTest.php b/tests/Phug/Adapter/FileAdapterTest.php index a3b81851..e4746127 100644 --- a/tests/Phug/Adapter/FileAdapterTest.php +++ b/tests/Phug/Adapter/FileAdapterTest.php @@ -575,7 +575,9 @@ public function testCacheRenderString() * @covers \Phug\Renderer\Adapter\FileAdapter::cacheDirectory * @covers \Phug\Renderer\Adapter\FileAdapter::getCacheDirectory * @covers \Phug\Renderer\Partial\Debug\DebuggerTrait::getDebuggedException + * * @expectedException \RuntimeException + * * @expectedExceptionCode 5 */ public function testMissingDirectory() @@ -594,7 +596,9 @@ public function testMissingDirectory() * @covers \Phug\Renderer\Adapter\FileAdapter::cacheDirectory * @covers \Phug\Renderer\Adapter\FileAdapter::cache * @covers \Phug\Renderer\Adapter\FileAdapter::displayCached + * * @expectedException \RuntimeException + * * @expectedExceptionCode 6 */ public function testReadOnlyDirectory() diff --git a/tests/Phug/Ast/NodeTest.php b/tests/Phug/Ast/NodeTest.php index 4e2f66b0..ffc8e10b 100644 --- a/tests/Phug/Ast/NodeTest.php +++ b/tests/Phug/Ast/NodeTest.php @@ -282,6 +282,7 @@ public function testGetChildAt() /** * @covers ::getChildAt + * * @expectedException \Phug\AstException */ public function testGetChildAtWithInvalidOffset() @@ -309,6 +310,7 @@ public function testRemoveChildAt() /** * @covers ::removeChildAt + * * @expectedException \Phug\AstException */ public function testRemoveChildAtWithInvalidOffset() @@ -447,7 +449,9 @@ public function testFindChildren() /** * @covers ::insertBefore + * * @expectedException \Phug\AstException + * * @expectedExceptionMessage Failed to insert before: Passed child is not a child of element to insert in */ public function testInsertBeforeWithBadSibling() @@ -481,7 +485,9 @@ public function testInsertBefore() /** * @covers ::insertAfter + * * @expectedException \Phug\AstException + * * @expectedExceptionMessage Failed to insert after: Passed child is not a child of element to insert in */ public function testInsertAfterWithBadSibling() @@ -562,7 +568,9 @@ public function testGetIterator() /** * @covers ::offsetSet + * * @expectedException \InvalidArgumentException + * * @expectedExceptionMessage Argument 2 passed to Node->offsetSet needs to be instance of Phug\Ast\NodeInterface */ public function testOffsetSetInvalidArgument() diff --git a/tests/Phug/CasesTest.php b/tests/Phug/CasesTest.php index c5fa5911..bedb87b6 100644 --- a/tests/Phug/CasesTest.php +++ b/tests/Phug/CasesTest.php @@ -21,7 +21,9 @@ public function caseProvider() /** * @group cases + * * @dataProvider caseProvider + * * @covers ::compileFile * @covers ::render */ diff --git a/tests/Phug/CliTest.php b/tests/Phug/CliTest.php index f372fbb8..fe5d98e7 100644 --- a/tests/Phug/CliTest.php +++ b/tests/Phug/CliTest.php @@ -44,6 +44,7 @@ public function finishTest() /** * @group cli + * * @covers ::getCustomMethods */ public function testGetCustomMethods() @@ -73,6 +74,7 @@ public function testGetCustomMethods() /** * @group cli + * * @covers ::convertToKebabCase * @covers ::convertToCamelCase * @covers ::getNamedArgumentBySpaceDelimiter @@ -104,6 +106,7 @@ public function testRun() /** * @group cli + * * @covers ::convertToKebabCase * @covers ::convertToCamelCase * @covers ::execute @@ -158,6 +161,7 @@ public function testListAvailableMethods() /** * @group cli + * * @covers ::convertToKebabCase * @covers ::convertToCamelCase * @covers ::execute @@ -175,6 +179,7 @@ public function testCallableActions() /** * @group cli + * * @covers ::convertToKebabCase * @covers ::convertToCamelCase * @covers ::getNamedArgumentBySpaceDelimiter @@ -196,6 +201,7 @@ public function testOptions() /** * @group cli + * * @covers ::convertToKebabCase * @covers ::convertToCamelCase * @covers ::getNamedArgumentBySpaceDelimiter @@ -258,6 +264,7 @@ public function testCacheDirectory() /** * @group cli + * * @covers ::convertToKebabCase * @covers ::convertToCamelCase * @covers ::getNamedArgumentBySpaceDelimiter @@ -298,6 +305,7 @@ public function testBootstrap() /** * @group cli + * * @covers ::convertToKebabCase * @covers ::convertToCamelCase * @covers ::getNamedArgumentBySpaceDelimiter diff --git a/tests/Phug/Compiler/NodeCompiler/AssignmentListNodeCompilerTest.php b/tests/Phug/Compiler/NodeCompiler/AssignmentListNodeCompilerTest.php index b12ea5c1..eff2aac7 100644 --- a/tests/Phug/Compiler/NodeCompiler/AssignmentListNodeCompilerTest.php +++ b/tests/Phug/Compiler/NodeCompiler/AssignmentListNodeCompilerTest.php @@ -25,6 +25,7 @@ public function testCompileNode() /** * @covers :: + * * @expectedException \Phug\CompilerException */ public function testException() diff --git a/tests/Phug/Compiler/NodeCompiler/AssignmentNodeCompilerTest.php b/tests/Phug/Compiler/NodeCompiler/AssignmentNodeCompilerTest.php index aa54dc94..3e449fae 100644 --- a/tests/Phug/Compiler/NodeCompiler/AssignmentNodeCompilerTest.php +++ b/tests/Phug/Compiler/NodeCompiler/AssignmentNodeCompilerTest.php @@ -46,6 +46,7 @@ public function testCompile() /** * @covers :: + * * @expectedException \Phug\CompilerException */ public function testException() diff --git a/tests/Phug/Compiler/NodeCompiler/AttributeListCompilerTest.php b/tests/Phug/Compiler/NodeCompiler/AttributeListCompilerTest.php index ea1009dd..fecf17cb 100644 --- a/tests/Phug/Compiler/NodeCompiler/AttributeListCompilerTest.php +++ b/tests/Phug/Compiler/NodeCompiler/AttributeListCompilerTest.php @@ -25,6 +25,7 @@ public function testCompileNode() /** * @covers :: + * * @expectedException \Phug\CompilerException */ public function testException() diff --git a/tests/Phug/Compiler/NodeCompiler/AttributeNodeCompilerTest.php b/tests/Phug/Compiler/NodeCompiler/AttributeNodeCompilerTest.php index 7b792a81..c4b4be1c 100644 --- a/tests/Phug/Compiler/NodeCompiler/AttributeNodeCompilerTest.php +++ b/tests/Phug/Compiler/NodeCompiler/AttributeNodeCompilerTest.php @@ -77,6 +77,7 @@ public function testUnescapedAttributes() /** * @covers :: + * * @expectedException \Phug\CompilerException */ public function testException() @@ -92,6 +93,7 @@ public function testException() /** * @covers ::compileValue + * * @expectedException \Phug\CompilerException */ public function testAttributeException() diff --git a/tests/Phug/Compiler/NodeCompiler/BlockNodeCompilerTest.php b/tests/Phug/Compiler/NodeCompiler/BlockNodeCompilerTest.php index 13079f54..fd8b3fcf 100644 --- a/tests/Phug/Compiler/NodeCompiler/BlockNodeCompilerTest.php +++ b/tests/Phug/Compiler/NodeCompiler/BlockNodeCompilerTest.php @@ -38,6 +38,7 @@ public function testBlock() /** * @covers :: + * * @expectedException \Phug\CompilerException */ public function testException() @@ -53,6 +54,7 @@ public function testException() /** * @covers \Phug\Compiler::compileBlocks + * * @expectedException \Phug\CompilerException */ public function testCompileBlocksException() diff --git a/tests/Phug/Compiler/NodeCompiler/CaseNodeCompilerTest.php b/tests/Phug/Compiler/NodeCompiler/CaseNodeCompilerTest.php index 9b0198e6..093bc3d8 100644 --- a/tests/Phug/Compiler/NodeCompiler/CaseNodeCompilerTest.php +++ b/tests/Phug/Compiler/NodeCompiler/CaseNodeCompilerTest.php @@ -73,6 +73,7 @@ public function testCompile() /** * @covers :: + * * @expectedException \Phug\CompilerException */ public function testException() diff --git a/tests/Phug/Compiler/NodeCompiler/CodeNodeCompilerTest.php b/tests/Phug/Compiler/NodeCompiler/CodeNodeCompilerTest.php index bfab52f4..c81d9184 100644 --- a/tests/Phug/Compiler/NodeCompiler/CodeNodeCompilerTest.php +++ b/tests/Phug/Compiler/NodeCompiler/CodeNodeCompilerTest.php @@ -49,6 +49,7 @@ public function testCompile() /** * @covers :: * @covers ::getCodeElement + * * @expectedException \Phug\CompilerException */ public function testException() diff --git a/tests/Phug/Compiler/NodeCompiler/CommentNodeCompilerTest.php b/tests/Phug/Compiler/NodeCompiler/CommentNodeCompilerTest.php index b7862d1f..88969280 100644 --- a/tests/Phug/Compiler/NodeCompiler/CommentNodeCompilerTest.php +++ b/tests/Phug/Compiler/NodeCompiler/CommentNodeCompilerTest.php @@ -30,6 +30,7 @@ public function testCompile() /** * @covers :: * @covers \Phug\CompilerException:: + * * @expectedException \Phug\CompilerException */ public function testException() diff --git a/tests/Phug/Compiler/NodeCompiler/ConditionalNodeCompilerTest.php b/tests/Phug/Compiler/NodeCompiler/ConditionalNodeCompilerTest.php index 90918140..fc4b717f 100644 --- a/tests/Phug/Compiler/NodeCompiler/ConditionalNodeCompilerTest.php +++ b/tests/Phug/Compiler/NodeCompiler/ConditionalNodeCompilerTest.php @@ -62,6 +62,7 @@ public function testCompile() /** * @covers :: + * * @expectedException \Phug\CompilerException */ public function testException() diff --git a/tests/Phug/Compiler/NodeCompiler/DoNodeCompilerTest.php b/tests/Phug/Compiler/NodeCompiler/DoNodeCompilerTest.php index a30d99ea..82f819fa 100644 --- a/tests/Phug/Compiler/NodeCompiler/DoNodeCompilerTest.php +++ b/tests/Phug/Compiler/NodeCompiler/DoNodeCompilerTest.php @@ -14,6 +14,7 @@ class DoNodeCompilerTest extends AbstractCompilerTest { /** * @covers :: + * * @expectedException \Phug\CompilerException */ public function testException() diff --git a/tests/Phug/Compiler/NodeCompiler/DoctypeNodeCompilerTest.php b/tests/Phug/Compiler/NodeCompiler/DoctypeNodeCompilerTest.php index a4971c8c..b01ffc4f 100644 --- a/tests/Phug/Compiler/NodeCompiler/DoctypeNodeCompilerTest.php +++ b/tests/Phug/Compiler/NodeCompiler/DoctypeNodeCompilerTest.php @@ -29,6 +29,7 @@ public function testCompile() /** * @covers :: + * * @expectedException \Phug\CompilerException */ public function testException() diff --git a/tests/Phug/Compiler/NodeCompiler/DocumentNodeCompilerTest.php b/tests/Phug/Compiler/NodeCompiler/DocumentNodeCompilerTest.php index 6ca2cb58..84679aa7 100644 --- a/tests/Phug/Compiler/NodeCompiler/DocumentNodeCompilerTest.php +++ b/tests/Phug/Compiler/NodeCompiler/DocumentNodeCompilerTest.php @@ -22,6 +22,7 @@ public function testCompile() /** * @covers :: + * * @expectedException \Phug\CompilerException */ public function testException() diff --git a/tests/Phug/Compiler/NodeCompiler/EachNodeCompilerTest.php b/tests/Phug/Compiler/NodeCompiler/EachNodeCompilerTest.php index 54b51035..17760076 100644 --- a/tests/Phug/Compiler/NodeCompiler/EachNodeCompilerTest.php +++ b/tests/Phug/Compiler/NodeCompiler/EachNodeCompilerTest.php @@ -210,6 +210,7 @@ public function testCompileVariablesScope() /** * @covers :: + * * @expectedException \Phug\CompilerException */ public function testException() diff --git a/tests/Phug/Compiler/NodeCompiler/ElementNodeCompilerTest.php b/tests/Phug/Compiler/NodeCompiler/ElementNodeCompilerTest.php index 22157af5..d32731a1 100644 --- a/tests/Phug/Compiler/NodeCompiler/ElementNodeCompilerTest.php +++ b/tests/Phug/Compiler/NodeCompiler/ElementNodeCompilerTest.php @@ -36,6 +36,7 @@ public function testExpansionCompile() /** * @covers :: + * * @expectedException \Phug\CompilerException */ public function testException() diff --git a/tests/Phug/Compiler/NodeCompiler/ExpressionNodeCompilerTest.php b/tests/Phug/Compiler/NodeCompiler/ExpressionNodeCompilerTest.php index 53179fb2..054e2ec6 100644 --- a/tests/Phug/Compiler/NodeCompiler/ExpressionNodeCompilerTest.php +++ b/tests/Phug/Compiler/NodeCompiler/ExpressionNodeCompilerTest.php @@ -29,6 +29,7 @@ public function testCompile() /** * @covers :: + * * @expectedException \Phug\CompilerException */ public function testException() diff --git a/tests/Phug/Compiler/NodeCompiler/FilterNodeCompilerTest.php b/tests/Phug/Compiler/NodeCompiler/FilterNodeCompilerTest.php index 40d4ce22..f3718232 100644 --- a/tests/Phug/Compiler/NodeCompiler/FilterNodeCompilerTest.php +++ b/tests/Phug/Compiler/NodeCompiler/FilterNodeCompilerTest.php @@ -97,6 +97,7 @@ public function testLegacyFilters() /** * @covers :: + * * @expectedException \Phug\CompilerException */ public function testWrongFilterException() @@ -164,6 +165,7 @@ public function testFilterCompilerArgument() /** * @covers ::compileText + * * @expectedException \Phug\CompilerException */ public function testFilterChildrenException() @@ -192,6 +194,7 @@ public function testFilterChildrenException() /** * @covers :: + * * @expectedException \Phug\CompilerException */ public function testException() diff --git a/tests/Phug/Compiler/NodeCompiler/ImportNodeCompilerTest.php b/tests/Phug/Compiler/NodeCompiler/ImportNodeCompilerTest.php index 25282c66..a7ef86b1 100644 --- a/tests/Phug/Compiler/NodeCompiler/ImportNodeCompilerTest.php +++ b/tests/Phug/Compiler/NodeCompiler/ImportNodeCompilerTest.php @@ -15,6 +15,7 @@ class ImportNodeCompilerTest extends AbstractCompilerTest { /** * @covers :: + * * @expectedException \Phug\CompilerException */ public function testException() @@ -294,6 +295,7 @@ public function testNestedIncludedMixins() /** * @covers \Phug\Compiler::compileIntoElement + * * @expectedException \Phug\CompilerException */ public function testCompileIntoElementException() @@ -345,6 +347,7 @@ public function testNotFoundTemplate() /** * @covers \Phug\Compiler::throwException + * * @expectedException \Phug\CompilerException */ public function testFileNotFoundInFileException() diff --git a/tests/Phug/Compiler/NodeCompiler/KeywordNodeCompilerTest.php b/tests/Phug/Compiler/NodeCompiler/KeywordNodeCompilerTest.php index f3db6b64..dd04aacb 100644 --- a/tests/Phug/Compiler/NodeCompiler/KeywordNodeCompilerTest.php +++ b/tests/Phug/Compiler/NodeCompiler/KeywordNodeCompilerTest.php @@ -48,6 +48,7 @@ public function testCompile() /** * @covers :: + * * @expectedException \Phug\CompilerException */ public function testException() diff --git a/tests/Phug/Compiler/NodeCompiler/MixinCallNodeCompilerTest.php b/tests/Phug/Compiler/NodeCompiler/MixinCallNodeCompilerTest.php index 41666d56..9045de1b 100644 --- a/tests/Phug/Compiler/NodeCompiler/MixinCallNodeCompilerTest.php +++ b/tests/Phug/Compiler/NodeCompiler/MixinCallNodeCompilerTest.php @@ -16,6 +16,7 @@ class MixinCallNodeCompilerTest extends AbstractCompilerTest { /** * @group mixins + * * @covers :: * @covers \Phug\Compiler\NodeCompiler\BlockNodeCompiler:: * @covers \Phug\Compiler\NodeCompiler\BlockNodeCompiler::compileAnonymousBlock @@ -54,6 +55,7 @@ public function testCompile() /** * @group mixins + * * @covers :: */ public function testCompileNestedMixins() @@ -82,6 +84,7 @@ public function testCompileNestedMixins() /** * @group mixins + * * @covers :: */ public function testCompileVariadicMixin() @@ -104,6 +107,7 @@ public function testCompileVariadicMixin() /** * @group mixins + * * @covers :: * @covers \Phug\Compiler\NodeCompiler\BlockNodeCompiler:: * @covers \Phug\Compiler\NodeCompiler\BlockNodeCompiler::compileAnonymousBlock @@ -124,6 +128,7 @@ public function testDoubleBlock() /** * @group mixins + * * @covers :: * @covers \Phug\Compiler::compileDocument * @covers \Phug\Compiler\NodeCompiler\BlockNodeCompiler::compileAnonymousBlock @@ -177,6 +182,7 @@ public function testDynamicMixins() /** * @group mixins + * * @covers :: * @covers \Phug\Compiler\NodeCompiler\MixinNodeCompiler:: */ @@ -274,6 +280,7 @@ public function testMissingMixin() /** * @group mixins + * * @covers :: * @covers \Phug\Compiler\NodeCompiler\BlockNodeCompiler:: * @covers \Phug\Compiler\NodeCompiler\BlockNodeCompiler::compileAnonymousBlock @@ -299,6 +306,7 @@ public function testMixinAttributes() /** * @group mixins + * * @covers :: * @covers \Phug\Compiler\NodeCompiler\BlockNodeCompiler:: * @covers \Phug\Compiler\NodeCompiler\BlockNodeCompiler::compileAnonymousBlock diff --git a/tests/Phug/Compiler/NodeCompiler/MixinNodeCompilerTest.php b/tests/Phug/Compiler/NodeCompiler/MixinNodeCompilerTest.php index be53dbc5..7245afd5 100644 --- a/tests/Phug/Compiler/NodeCompiler/MixinNodeCompilerTest.php +++ b/tests/Phug/Compiler/NodeCompiler/MixinNodeCompilerTest.php @@ -14,6 +14,7 @@ class MixinNodeCompilerTest extends AbstractCompilerTest { /** * @covers :: + * * @expectedException \Phug\CompilerException */ public function testException() @@ -29,6 +30,7 @@ public function testException() /** * @group mixins + * * @covers :: */ public function testRecursion() @@ -60,6 +62,7 @@ public function testRecursion() /** * @group mixins + * * @covers :: */ public function testRecursionWithBlock() @@ -94,7 +97,9 @@ public function testRecursionWithBlock() /** * @group mixins + * * @covers \Phug\Compiler\NodeCompiler\BlockNodeCompiler ::compileAnonymousBlock + * * @expectedException \Phug\CompilerException */ public function testAnonymousBlocksOutsideMixin() diff --git a/tests/Phug/Compiler/NodeCompiler/TextNodeCompilerTest.php b/tests/Phug/Compiler/NodeCompiler/TextNodeCompilerTest.php index 18856bd6..4dbe79ee 100644 --- a/tests/Phug/Compiler/NodeCompiler/TextNodeCompilerTest.php +++ b/tests/Phug/Compiler/NodeCompiler/TextNodeCompilerTest.php @@ -62,6 +62,7 @@ public function testText() /** * @covers :: + * * @expectedException \Phug\CompilerException */ public function testException() diff --git a/tests/Phug/Compiler/NodeCompiler/VariableNodeCompilerTest.php b/tests/Phug/Compiler/NodeCompiler/VariableNodeCompilerTest.php index b1659663..514be7f1 100644 --- a/tests/Phug/Compiler/NodeCompiler/VariableNodeCompilerTest.php +++ b/tests/Phug/Compiler/NodeCompiler/VariableNodeCompilerTest.php @@ -26,6 +26,7 @@ public function testCompile() /** * @covers :: + * * @expectedException \Phug\CompilerException */ public function testExpressionException() @@ -39,6 +40,7 @@ public function testExpressionException() /** * @covers :: + * * @expectedException \Phug\CompilerException */ public function testException() diff --git a/tests/Phug/Compiler/NodeCompiler/WhenNodeCompilerTest.php b/tests/Phug/Compiler/NodeCompiler/WhenNodeCompilerTest.php index b27dd572..18c1488c 100644 --- a/tests/Phug/Compiler/NodeCompiler/WhenNodeCompilerTest.php +++ b/tests/Phug/Compiler/NodeCompiler/WhenNodeCompilerTest.php @@ -14,6 +14,7 @@ class WhenNodeCompilerTest extends AbstractCompilerTest { /** * @covers :: + * * @expectedException \Phug\CompilerException */ public function testException() diff --git a/tests/Phug/Compiler/NodeCompiler/WhileNodeCompilerTest.php b/tests/Phug/Compiler/NodeCompiler/WhileNodeCompilerTest.php index d841989b..873f3052 100644 --- a/tests/Phug/Compiler/NodeCompiler/WhileNodeCompilerTest.php +++ b/tests/Phug/Compiler/NodeCompiler/WhileNodeCompilerTest.php @@ -64,6 +64,7 @@ public function testCompile() /** * @covers :: + * * @expectedException \Phug\CompilerException */ public function testException() @@ -80,6 +81,7 @@ public function testException() /** * @covers :: * @covers \Phug\Compiler\NodeCompiler\DoNodeCompiler:: + * * @expectedException \Phug\CompilerException */ public function testDoAndWhileSeededException() diff --git a/tests/Phug/Compiler/NodeCompiler/YieldNodeCompilerTest.php b/tests/Phug/Compiler/NodeCompiler/YieldNodeCompilerTest.php index 7d95587c..8c08e83a 100644 --- a/tests/Phug/Compiler/NodeCompiler/YieldNodeCompilerTest.php +++ b/tests/Phug/Compiler/NodeCompiler/YieldNodeCompilerTest.php @@ -14,6 +14,7 @@ class YieldNodeCompilerTest extends AbstractCompilerTest { /** * @covers :: + * * @expectedException \Phug\CompilerException */ public function testException() diff --git a/tests/Phug/CompilerModuleTest.php b/tests/Phug/CompilerModuleTest.php index 1d2e2de2..8a1d395f 100644 --- a/tests/Phug/CompilerModuleTest.php +++ b/tests/Phug/CompilerModuleTest.php @@ -21,6 +21,7 @@ class CompilerModuleTest extends TestCase { /** * @group modules + * * @covers :: * @covers \Phug\Compiler\Event\CompileEvent:: */ @@ -53,6 +54,7 @@ public function testCompileEvent() /** * @group modules + * * @covers :: * @covers \Phug\Compiler\Event\OutputEvent:: */ @@ -174,6 +176,7 @@ public function testPrependOutput() /** * @group modules + * * @covers :: * @covers \Phug\Compiler\Event\NodeEvent:: */ @@ -245,6 +248,7 @@ public function testUntransformableNode() /** * @group modules + * * @covers :: * @covers \Phug\Compiler\Event\ElementEvent:: */ diff --git a/tests/Phug/CompilerTest.php b/tests/Phug/CompilerTest.php index a96f18ad..24d7a56e 100644 --- a/tests/Phug/CompilerTest.php +++ b/tests/Phug/CompilerTest.php @@ -162,6 +162,7 @@ public function testGetCompiledChildren() /** * @covers ::__construct + * * @expectedException \InvalidArgumentException */ public function testParserClassException() @@ -180,6 +181,7 @@ public function testParserClassException() /** * @covers ::__construct + * * @expectedException \InvalidArgumentException */ public function testFormatterClassException() @@ -198,6 +200,7 @@ public function testFormatterClassException() /** * @covers ::__construct + * * @expectedException \InvalidArgumentException */ public function testLocatorClassException() @@ -213,6 +216,7 @@ public function testLocatorClassException() /** * @covers ::setNodeCompiler + * * @expectedException \InvalidArgumentException */ public function testSetNodeCompilerException() @@ -228,6 +232,7 @@ public function testSetNodeCompilerException() /** * @covers ::compileNode + * * @expectedException \Phug\CompilerException */ public function testCompileNodeException() @@ -246,6 +251,7 @@ public function testCompileNodeException() * @covers ::locate * @covers ::resolve * @covers \Phug\Compiler\NodeCompiler\ImportNodeCompiler::compileNode + * * @expectedException \Phug\CompilerException */ public function testAbsolutePathWithoutPaths() @@ -283,7 +289,9 @@ public function testResolve() /** * @covers ::resolve + * * @expectedException \Phug\CompilerException + * * @expectedExceptionMessage Source file not-existent not found */ public function testResolveNotFoundException() @@ -294,6 +302,7 @@ public function testResolveNotFoundException() /** * @group hooks + * * @covers ::compileNode * @covers ::compile * @covers ::__construct @@ -409,6 +418,7 @@ function ($name) { /** * @covers ::throwException + * * @expectedException \Phug\CompilerException */ public function testThrowException() @@ -419,7 +429,9 @@ public function testThrowException() /** * @covers ::throwException + * * @expectedException \Phug\CompilerException + * * @expectedExceptionMessage foobar.pug */ public function testThrowExceptionFileName() @@ -441,6 +453,7 @@ public function testAssertSuccess() /** * @covers ::assert + * * @expectedException \Phug\CompilerException */ public function testAssertFailure() @@ -451,7 +464,9 @@ public function testAssertFailure() /** * @covers ::initializeFormatter + * * @expectedException \InvalidArgumentException + * * @expectedExceptionMessage Passed formatter class stdClass is not a valid Phug\Formatter */ public function testInitializeFormatterException() @@ -594,7 +609,9 @@ public function testUpperLocator() /** * @covers ::compileNode + * * @expectedException \Phug\CompilerException + * * @expectedExceptionMessage Failed to compile: No compiler found able to compile Phug\Test\Utils\UnknownNode */ public function testUnknownNodeThrowException() diff --git a/tests/Phug/Element/AssignmentElementTest.php b/tests/Phug/Element/AssignmentElementTest.php index e618b078..742469e9 100644 --- a/tests/Phug/Element/AssignmentElementTest.php +++ b/tests/Phug/Element/AssignmentElementTest.php @@ -162,7 +162,9 @@ public function testAttributeElement() * @covers \Phug\Formatter\Format\XmlFormat::formatAttributeAssignments * @covers \Phug\Formatter\Format\XmlFormat::yieldAssignmentAttributes * @covers \Phug\Formatter\Format\XmlFormat::formatMarkupAttributes + * * @expectedException \Phug\FormatterException + * * @expectedExceptionMessage Unable to handle class assignment */ public function testFormatAssignmentElementException() diff --git a/tests/Phug/Element/KeywordElementTest.php b/tests/Phug/Element/KeywordElementTest.php index 69e51ea5..2bedba9b 100644 --- a/tests/Phug/Element/KeywordElementTest.php +++ b/tests/Phug/Element/KeywordElementTest.php @@ -112,7 +112,9 @@ public function testPhpReturn() /** * @covers \Phug\Formatter\AbstractFormat::formatKeywordElement + * * @expectedException \Phug\FormatterException + * * @expectedExceptionMessage The keyword foo returned an invalid value type */ public function testBadReturn() diff --git a/tests/Phug/Event/ListenerQueueTest.php b/tests/Phug/Event/ListenerQueueTest.php index 50f99cfc..695d6f41 100644 --- a/tests/Phug/Event/ListenerQueueTest.php +++ b/tests/Phug/Event/ListenerQueueTest.php @@ -57,7 +57,9 @@ public function testInsert() /** * @covers ::insertMultiple + * * @expectedException \InvalidArgumentException + * * @expectedExceptionMessage insertMultiple only accept array or Traversable as first argument */ public function testInsertMultipleBadType() @@ -70,7 +72,9 @@ public function testInsertMultipleBadType() /** * @covers ::insertMultiple + * * @expectedException \InvalidArgumentException + * * @expectedExceptionMessage Callback inserted into ListenerQueue needs to be callable */ public function testInsertMultipleBadSubInsert() @@ -110,6 +114,7 @@ public function provideParameterValues() /** * @covers ::insert + * * @dataProvider provideParameterValues */ public function testInsertWithNonCallback($parameterValue) diff --git a/tests/Phug/Format/HtmlFormatTest.php b/tests/Phug/Format/HtmlFormatTest.php index f7e22815..a6e78f8b 100644 --- a/tests/Phug/Format/HtmlFormatTest.php +++ b/tests/Phug/Format/HtmlFormatTest.php @@ -209,7 +209,9 @@ public function testFormatVariable() /** * @covers \Phug\Formatter\AbstractFormat::throwException * @covers \Phug\Formatter\Format\XmlFormat::isSelfClosingTag + * * @expectedException \Phug\FormatterException + * * @expectedExceptionMessage input is a self closing element: but contains nested content. */ public function testChildrenInSelfClosingTag() @@ -237,7 +239,9 @@ public function testEmptyTextInSelfClosingTag() /** * @covers \Phug\Formatter\AbstractFormat::throwException * @covers \Phug\Formatter\Format\XmlFormat::isSelfClosingTag + * * @expectedException \Phug\FormatterException + * * @expectedExceptionMessage input is a self closing element: but contains nested content. */ public function testTextInSelfClosingTag() diff --git a/tests/Phug/Format/XmlFormatTest.php b/tests/Phug/Format/XmlFormatTest.php index a4a70cb1..0f68ccab 100644 --- a/tests/Phug/Format/XmlFormatTest.php +++ b/tests/Phug/Format/XmlFormatTest.php @@ -811,13 +811,13 @@ public function testAttributeAttributePrecedence() * @covers ::formatOrderedAttributeAssignments * @covers ::formatOrderedMarkupAttributes * @covers ::formatInnerCodeValue + * + * @expectedException InvalidArgumentException + * + * @expectedExceptionMessage Option attribute_precedence must be "assignment" (default), "attribute", "left", "right" or a callable. */ public function testAttributeAttributePrecedenceFailure() { - self::expectExceptionObject(new InvalidArgumentException( - 'Option attribute_precedence must be "assignment" (default), "attribute", "left", "right" or a callable.', - )); - $this->prepareTest(); $this->render( diff --git a/tests/Phug/FormatterTest.php b/tests/Phug/FormatterTest.php index 0ca905f4..160c4a95 100644 --- a/tests/Phug/FormatterTest.php +++ b/tests/Phug/FormatterTest.php @@ -794,6 +794,7 @@ public function testFormatCode() /** * @group debug + * * @covers \Phug\Formatter\AbstractFormat::format * @covers \Phug\Formatter\AbstractFormat::formatElementChildren * @covers \Phug\Formatter::getSourceLine @@ -914,6 +915,7 @@ public function testFormatCodeWithDebug() /** * @group debug + * * @covers \Phug\Formatter::getSourceLine * @covers \Phug\Formatter::getDebugError */ diff --git a/tests/Phug/Invoker/InvokerTest.php b/tests/Phug/Invoker/InvokerTest.php index cb315597..ae889a30 100644 --- a/tests/Phug/Invoker/InvokerTest.php +++ b/tests/Phug/Invoker/InvokerTest.php @@ -23,6 +23,7 @@ class InvokerTest extends TestCase * @covers ::getCallbackType * * @expectedException RuntimeException + * * @expectedExceptionMessage Passed callback #1 should have at least 1 argument and this first argument must have a typehint. * * @throws ReflectionException @@ -40,6 +41,7 @@ function ($event) { * @covers ::addCallback * * @expectedException RuntimeException + * * @expectedExceptionMessage The #2 value is not callable. * * @throws ReflectionException diff --git a/tests/Phug/Lexer/Scanner/AttributeScannerTest.php b/tests/Phug/Lexer/Scanner/AttributeScannerTest.php index 33186456..c7752f57 100644 --- a/tests/Phug/Lexer/Scanner/AttributeScannerTest.php +++ b/tests/Phug/Lexer/Scanner/AttributeScannerTest.php @@ -197,6 +197,7 @@ public function testScanSpacing() * @covers \Phug\Lexer\Scanner\AttributeScanner::scanParenthesesContent * @covers \Phug\Lexer\Scanner\AttributeScanner::scanParentheses * @covers \Phug\Lexer\Scanner\AttributeScanner::scan + * * @expectedException \Phug\LexerException */ public function testFailsOnUnclosedBracket() diff --git a/tests/Phug/Lexer/Scanner/CaseScannerTest.php b/tests/Phug/Lexer/Scanner/CaseScannerTest.php index f48d0d27..a33e3c34 100644 --- a/tests/Phug/Lexer/Scanner/CaseScannerTest.php +++ b/tests/Phug/Lexer/Scanner/CaseScannerTest.php @@ -23,6 +23,7 @@ protected function getStatementName() * @covers \Phug\Lexer\Scanner\ControlStatementScanner::scan * @covers \Phug\Lexer\Scanner\Partial\NamespaceAndTernaryTrait::checkForTernary * @covers \Phug\Lexer\Scanner\Partial\NamespaceAndTernaryTrait::checkForNamespaceAndTernary + * * @dataProvider provideExpressions */ public function testExpandedExpressions($expr) diff --git a/tests/Phug/Lexer/Scanner/ClassScannerTest.php b/tests/Phug/Lexer/Scanner/ClassScannerTest.php index c0a04926..0f11531c 100644 --- a/tests/Phug/Lexer/Scanner/ClassScannerTest.php +++ b/tests/Phug/Lexer/Scanner/ClassScannerTest.php @@ -13,7 +13,6 @@ class ClassScannerTest extends AbstractLexerTest */ public function testSingleClass() { - /** @var ClassToken $tok */ list($tok) = $this->assertTokens('.some-class', [ ClassToken::class, @@ -28,7 +27,6 @@ public function testSingleClass() */ public function testMultipleClasses() { - /** * @var ClassToken * @var ClassToken $b @@ -50,7 +48,6 @@ public function testMultipleClasses() public function testCommonNamingPatterns() { - /** @var ClassToken $tok */ list($tok) = $this->assertTokens('.--some-class', [ ClassToken::class, diff --git a/tests/Phug/Lexer/Scanner/ConditionalScannerTest.php b/tests/Phug/Lexer/Scanner/ConditionalScannerTest.php index 70e51487..566ae10c 100644 --- a/tests/Phug/Lexer/Scanner/ConditionalScannerTest.php +++ b/tests/Phug/Lexer/Scanner/ConditionalScannerTest.php @@ -28,6 +28,7 @@ protected function getStatementName() * @covers \Phug\Lexer\Scanner\ControlStatementScanner::scan * @covers \Phug\Lexer\Scanner\Partial\NamespaceAndTernaryTrait::checkForTernary * @covers \Phug\Lexer\Scanner\Partial\NamespaceAndTernaryTrait::checkForNamespaceAndTernary + * * @dataProvider provideExpressions */ public function testExpandedExpressions($expr) @@ -119,7 +120,9 @@ public function testElseIfExpandedExpressions($expr, $stmt) /** * @covers Phug\Lexer\Scanner\ConditionalScanner::scan + * * @expectedException Phug\LexerException + * * @expectedExceptionMessage The `else`-conditional statement can't have a subject */ public function testElseWithSubject() diff --git a/tests/Phug/Lexer/Scanner/DoScannerTest.php b/tests/Phug/Lexer/Scanner/DoScannerTest.php index d7807c78..27382481 100644 --- a/tests/Phug/Lexer/Scanner/DoScannerTest.php +++ b/tests/Phug/Lexer/Scanner/DoScannerTest.php @@ -21,7 +21,6 @@ class DoScannerTest extends AbstractLexerTest */ public function testSingleLine() { - /* @var DoToken $tok */ $this->assertTokens("do\n", [DoToken::class, NewLineToken::class]); } @@ -36,7 +35,6 @@ public function testSingleLine() */ public function testExpanded() { - /* @var DoToken $tok */ $this->assertTokens('do: p something', [ DoToken::class, diff --git a/tests/Phug/Lexer/Scanner/DoctypeScannerTest.php b/tests/Phug/Lexer/Scanner/DoctypeScannerTest.php index ed40dbec..0bea6b2f 100644 --- a/tests/Phug/Lexer/Scanner/DoctypeScannerTest.php +++ b/tests/Phug/Lexer/Scanner/DoctypeScannerTest.php @@ -13,7 +13,6 @@ class DoctypeScannerTest extends AbstractLexerTest */ public function testCommonDoctypes() { - /** @var DoctypeToken $tok */ list($tok) = $this->assertTokens( 'doctype 5', diff --git a/tests/Phug/Lexer/Scanner/EachScannerTest.php b/tests/Phug/Lexer/Scanner/EachScannerTest.php index 02e63187..2ea68df1 100644 --- a/tests/Phug/Lexer/Scanner/EachScannerTest.php +++ b/tests/Phug/Lexer/Scanner/EachScannerTest.php @@ -43,11 +43,11 @@ public function provideInvalidSyntaxStyles() * @covers ::scan * @covers \Phug\Lexer\Scanner\Partial\NamespaceAndTernaryTrait::checkForTernary * @covers \Phug\Lexer\Scanner\Partial\NamespaceAndTernaryTrait::checkForNamespaceAndTernary + * * @dataProvider provideExpressions */ public function testWithItemOnly($expr) { - /** @var EachToken $tok */ list($tok) = $this->assertTokens("each \$item in $expr", [EachToken::class]); @@ -59,11 +59,11 @@ public function testWithItemOnly($expr) * @covers ::scan * @covers \Phug\Lexer\Scanner\Partial\NamespaceAndTernaryTrait::checkForTernary * @covers \Phug\Lexer\Scanner\Partial\NamespaceAndTernaryTrait::checkForNamespaceAndTernary + * * @dataProvider provideExpressions */ public function testWithItemAndKey($expr) { - /** @var EachToken $tok */ list($tok) = $this->assertTokens("each \$someItem, \$someKey in $expr", [EachToken::class]); @@ -74,11 +74,11 @@ public function testWithItemAndKey($expr) /** * @covers ::scan + * * @dataProvider provideExpressions */ public function testExpandedWithItemOnly($expr) { - /** @var EachToken $tok */ list($tok) = $this->assertTokens("each \$item in $expr: p Some Text", [ EachToken::class, @@ -93,11 +93,11 @@ public function testExpandedWithItemOnly($expr) /** * @covers ::scan + * * @dataProvider provideExpressions */ public function testExpandedWithItemAndKey($expr) { - /** @var EachToken $tok */ list($tok) = $this->assertTokens("each \$someItem, \$someKey in $expr: p Some Text", [ EachToken::class, @@ -113,7 +113,9 @@ public function testExpandedWithItemAndKey($expr) /** * @dataProvider provideInvalidSyntaxStyles + * * @covers ::scan + * * @expectedException \Phug\LexerException */ public function testThatItFailsWithInvalidSyntax($syntax) @@ -124,7 +126,9 @@ public function testThatItFailsWithInvalidSyntax($syntax) /** * @covers ::scan + * * @expectedException \Phug\LexerException + * * @expectedExceptionMessage `each`-statement has no subject to operate on */ public function testEachWithoutSubject() diff --git a/tests/Phug/Lexer/Scanner/ForScannerTest.php b/tests/Phug/Lexer/Scanner/ForScannerTest.php index 06b2ae2b..572e359b 100644 --- a/tests/Phug/Lexer/Scanner/ForScannerTest.php +++ b/tests/Phug/Lexer/Scanner/ForScannerTest.php @@ -23,6 +23,7 @@ protected function getStatementName() * @covers \Phug\Lexer\Scanner\ControlStatementScanner::scan * @covers \Phug\Lexer\Scanner\Partial\NamespaceAndTernaryTrait::checkForTernary * @covers \Phug\Lexer\Scanner\Partial\NamespaceAndTernaryTrait::checkForNamespaceAndTernary + * * @dataProvider provideExpressions */ public function testExpandedExpressions($expr) diff --git a/tests/Phug/Lexer/Scanner/IndentationScannerTest.php b/tests/Phug/Lexer/Scanner/IndentationScannerTest.php index b80dbca0..ba74b4be 100644 --- a/tests/Phug/Lexer/Scanner/IndentationScannerTest.php +++ b/tests/Phug/Lexer/Scanner/IndentationScannerTest.php @@ -166,6 +166,7 @@ public function testMixedIndentation() * @covers \Phug\Lexer\Scanner\IndentationScanner::formatIndentChar * @covers \Phug\Lexer\Scanner\IndentationScanner::getIndentChar * @covers \Phug\LexerException:: + * * @expectedException \Phug\LexerException */ public function testInconsistentIndent() @@ -186,6 +187,7 @@ public function testInconsistentIndent() /** * @covers \Phug\Lexer\Scanner\IndentationScanner::formatIndentChar * @covers \Phug\Lexer\Scanner\IndentationScanner::getIndentLevel + * * @expectedException \Phug\LexerException */ public function testNotAllowedMixedIndent() diff --git a/tests/Phug/Lexer/Scanner/WhenScannerTest.php b/tests/Phug/Lexer/Scanner/WhenScannerTest.php index 14d46575..d4366389 100644 --- a/tests/Phug/Lexer/Scanner/WhenScannerTest.php +++ b/tests/Phug/Lexer/Scanner/WhenScannerTest.php @@ -26,6 +26,7 @@ protected function getStatementName() * @covers \Phug\Lexer\Scanner\ControlStatementScanner::scan * @covers \Phug\Lexer\Scanner\Partial\NamespaceAndTernaryTrait::checkForTernary * @covers \Phug\Lexer\Scanner\Partial\NamespaceAndTernaryTrait::checkForNamespaceAndTernary + * * @dataProvider provideExpressions */ public function testExpandedExpressions($expr) @@ -35,7 +36,6 @@ public function testExpandedExpressions($expr) public function testDefault() { - /** @var WhenToken $tok */ list($tok) = $this->assertTokens('default: p Do something', [ WhenToken::class, diff --git a/tests/Phug/Lexer/Scanner/WhileScannerTest.php b/tests/Phug/Lexer/Scanner/WhileScannerTest.php index 57d21cce..09a03fae 100644 --- a/tests/Phug/Lexer/Scanner/WhileScannerTest.php +++ b/tests/Phug/Lexer/Scanner/WhileScannerTest.php @@ -23,6 +23,7 @@ protected function getStatementName() * @covers \Phug\Lexer\Scanner\ControlStatementScanner::scan * @covers \Phug\Lexer\Scanner\Partial\NamespaceAndTernaryTrait::checkForTernary * @covers \Phug\Lexer\Scanner\Partial\NamespaceAndTernaryTrait::checkForNamespaceAndTernary + * * @dataProvider provideExpressions */ public function testExpandedExpressions($expr) diff --git a/tests/Phug/Lexer/StateTest.php b/tests/Phug/Lexer/StateTest.php index 28e8711a..66fc9589 100644 --- a/tests/Phug/Lexer/StateTest.php +++ b/tests/Phug/Lexer/StateTest.php @@ -20,7 +20,9 @@ class StateTest extends TestCase { /** * @covers ::__construct + * * @expectedException \InvalidArgumentException + * * @expectedExceptionMessage Configuration option `reader_class_name` * @expectedExceptionMessage needs to be a valid FQCN of a class * @expectedExceptionMessage that extends Phug\Reader @@ -71,7 +73,9 @@ public function testSetIndentStyle() /** * @covers \Phug\Lexer\Partial\IndentStyleTrait::setIndentStyle + * * @expectedException \InvalidArgumentException + * * @expectedExceptionMessage indentStyle needs to be null or one of the INDENT_* constants of the lexer */ public function testSetIndentStyleException() @@ -120,7 +124,9 @@ public function testSetIndentWidth() /** * @covers \Phug\Lexer\Partial\IndentStyleTrait::setIndentWidth + * * @expectedException \InvalidArgumentException + * * @expectedExceptionMessage indentWidth needs to be null or an integer above 0 */ public function testSetIndentWidthException() @@ -143,7 +149,9 @@ public function testCreateToken() /** * @covers ::createToken * @covers ::throwException + * * @expectedException \Phug\LexerException + * * @expectedExceptionMessage Failed to lex: bar * @expectedExceptionMessage Near: p Hello * @expectedExceptionMessage Line: 1 @@ -161,7 +169,9 @@ public function testCreateTokenException() /** * @covers ::__construct + * * @expectedException \Phug\ReaderException + * * @expectedExceptionMessage Path: path.pug */ public function testReaderExceptionWithPath() @@ -203,7 +213,9 @@ public function testScan() * @covers ::scan * @covers ::filterScanners * @covers ::throwException + * * @expectedException \InvalidArgumentException + * * @expectedExceptionMessage The passed scanner with key `tag` * @expectedExceptionMessage doesn't seem to be either a valid * @expectedExceptionMessage Phug\Lexer\ScannerInterface @@ -222,7 +234,9 @@ public function testFilterScanersException() * @covers ::scan * @covers ::filterScanners * @covers ::throwException + * * @expectedException \Phug\LexerException + * * @expectedExceptionMessage Scanner Phug\Test\MockScanner * @expectedExceptionMessage generated a result that is not a * @expectedExceptionMessage Phug\Lexer\TokenInterface @@ -245,7 +259,9 @@ public function testScanException() /** * @covers ::loopScan * @covers ::throwException + * * @expectedException \Phug\LexerException + * * @expectedExceptionMessage Unexpected p Hello */ public function testLoopScanException() diff --git a/tests/Phug/LexerModuleTest.php b/tests/Phug/LexerModuleTest.php index 5493101f..7ebf5a79 100644 --- a/tests/Phug/LexerModuleTest.php +++ b/tests/Phug/LexerModuleTest.php @@ -244,7 +244,9 @@ public function testTokenGeneratorEvent() /** * @covers \Phug\Lexer\Event\TokenEvent::setTokenGenerator + * * @expectedException InvalidArgumentException + * * @expectedExceptionMessage setTokenGenerator(iterable $tokens) expect its argument to be iterable, integer received. */ public function testTokenGeneratorBadInput() diff --git a/tests/Phug/LexerTest.php b/tests/Phug/LexerTest.php index 317ac5e0..f26bb144 100644 --- a/tests/Phug/LexerTest.php +++ b/tests/Phug/LexerTest.php @@ -41,6 +41,7 @@ public function testGetScanners() /** * @covers \Phug\Lexer\Partial\StateTrait::getState + * * @expectedException \RuntimeException */ public function testGetStateException() @@ -148,6 +149,7 @@ public function testAddScanner() /** * @covers ::filterScanner + * * @expectedException \InvalidArgumentException */ public function testFilterScanner() @@ -165,6 +167,7 @@ public function testFilterScanner() /** * @covers ::lex + * * @expectedException \InvalidArgumentException */ public function testBadStateClassName() diff --git a/tests/Phug/OptimizerTest.php b/tests/Phug/OptimizerTest.php index 5f5b974a..1dfa4e01 100644 --- a/tests/Phug/OptimizerTest.php +++ b/tests/Phug/OptimizerTest.php @@ -88,7 +88,9 @@ public function testUpToDateCheck() /** * @covers \Phug\Phug::cacheDirectory + * * @expectedException \InvalidArgumentException + * * @expectedExceptionMessage Expected $options to be an array, got: 'biz' */ public function testCacheDirectoryWithWrongOptions() diff --git a/tests/Phug/Parser/StateTest.php b/tests/Phug/Parser/StateTest.php index fc17dbfd..3de56162 100644 --- a/tests/Phug/Parser/StateTest.php +++ b/tests/Phug/Parser/StateTest.php @@ -142,7 +142,9 @@ public function testHandleTokenTwice() /** * @covers ::handleToken + * * @expectedException \Phug\ParserException + * * @expectedExceptionMessage Failed to parse: Unexpected token * @expectedExceptionMessage `Phug\Lexer\Token\TagToken`, * @expectedExceptionMessage no token handler registered @@ -387,7 +389,9 @@ public function testParentNodeIs() /** * @covers ::createNode + * * @expectedException \InvalidArgumentException + * * @expectedExceptionMessage ErrorException is not a valid token class */ public function testCreateNodeException() @@ -447,7 +451,9 @@ public function testLeave() /** * @covers ::leave + * * @expectedException \Phug\ParserException + * * @expectedExceptionMessage Failed to outdent: No parent to outdent to. * @expectedExceptionMessage Seems the parser moved out too many levels. */ @@ -495,7 +501,9 @@ public function testStore() /** * @covers ::throwException + * * @expectedException \Phug\ParserException + * * @expectedExceptionMessage Failed to parse: Unexpected token * @expectedExceptionMessage `Phug\Lexer\Token\TagToken`, * @expectedExceptionMessage no token handler registered diff --git a/tests/Phug/Parser/TokenHandler/AssignmentTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/AssignmentTokenHandlerTest.php index 6fa2e1e7..890c8012 100644 --- a/tests/Phug/Parser/TokenHandler/AssignmentTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/AssignmentTokenHandlerTest.php @@ -73,7 +73,9 @@ public function testHandleTokenWithNothingNext() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass Assignment tokens to this token handler */ public function testHandleTokenTokenException() @@ -86,7 +88,9 @@ public function testHandleTokenTokenException() /** * @covers :: + * * @expectedException \Phug\ParserException + * * @expectedExceptionMessage Failed to parse: Assignments can only happen on elements and mixinCalls */ public function testHandleTokenElementTagsException() diff --git a/tests/Phug/Parser/TokenHandler/AttributeEndTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/AttributeEndTokenHandlerTest.php index 2d82d039..aa866a86 100644 --- a/tests/Phug/Parser/TokenHandler/AttributeEndTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/AttributeEndTokenHandlerTest.php @@ -30,7 +30,9 @@ public function testHandleToken() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass attribute end tokens to this token handler */ public function testHandleTokenTokenException() diff --git a/tests/Phug/Parser/TokenHandler/AttributeStartTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/AttributeStartTokenHandlerTest.php index 7b4d1ef1..cc4479fb 100644 --- a/tests/Phug/Parser/TokenHandler/AttributeStartTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/AttributeStartTokenHandlerTest.php @@ -64,7 +64,9 @@ public function testHandleTokenFull() /** * @covers :: * @covers Phug\Parser\TokenHandler\AttributeStartTokenHandler:: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass attribute start tokens to this token handler */ public function testHandleTokenTokenException() @@ -78,7 +80,9 @@ public function testHandleTokenTokenException() /** * @covers :: * @covers \Phug\Parser\TokenHandler\AttributeStartTokenHandler:: + * * @expectedException \Phug\ParserException + * * @expectedExceptionMessage Failed to parse: Attributes can only be placed on * @expectedExceptionMessage element, assignment, import, variable, * @expectedExceptionMessage mixin and mixinCall @@ -101,7 +105,9 @@ public function testHandleTokenElementTagsException() /** * @covers :: * @covers \Phug\Parser\TokenHandler\AttributeStartTokenHandler:: + * * @expectedException \Phug\ParserException + * * @expectedExceptionMessage Attribute list not closed */ public function testHandleTokenListNotClosedException() diff --git a/tests/Phug/Parser/TokenHandler/AttributeTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/AttributeTokenHandlerTest.php index b54b44a9..247ad39b 100644 --- a/tests/Phug/Parser/TokenHandler/AttributeTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/AttributeTokenHandlerTest.php @@ -47,7 +47,9 @@ public function testNoCurrentNode() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass attribute tokens to this token handler */ public function testHandleTokenTokenException() diff --git a/tests/Phug/Parser/TokenHandler/AutoCloseTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/AutoCloseTokenHandlerTest.php index f7924d51..9a8f3c87 100644 --- a/tests/Phug/Parser/TokenHandler/AutoCloseTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/AutoCloseTokenHandlerTest.php @@ -89,7 +89,9 @@ public function testHandleToken() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass auto-close tokens to this token handler */ public function testHandleTokenTokenException() @@ -102,7 +104,9 @@ public function testHandleTokenTokenException() /** * @covers :: + * * @expectedException \Phug\ParserException + * * @expectedExceptionMessage Auto-close operators can only be used on elements */ public function testHandleClassOnWrongNode() diff --git a/tests/Phug/Parser/TokenHandler/BlockTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/BlockTokenHandlerTest.php index 9a0b774f..74428564 100644 --- a/tests/Phug/Parser/TokenHandler/BlockTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/BlockTokenHandlerTest.php @@ -27,7 +27,9 @@ public function testHandleToken() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass block tokens to this token handler */ public function testHandleTokenTokenException() diff --git a/tests/Phug/Parser/TokenHandler/CaseTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/CaseTokenHandlerTest.php index 22cbd963..091ff85e 100644 --- a/tests/Phug/Parser/TokenHandler/CaseTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/CaseTokenHandlerTest.php @@ -27,7 +27,9 @@ public function testHandleToken() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass case tokens to this token handler */ public function testHandleTokenTokenException() diff --git a/tests/Phug/Parser/TokenHandler/ClassTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/ClassTokenHandlerTest.php index 76a58bc4..483a10ff 100644 --- a/tests/Phug/Parser/TokenHandler/ClassTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/ClassTokenHandlerTest.php @@ -50,7 +50,9 @@ public function testClassNamePassedToAttribute() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass class tokens to this token handler */ public function testHandleTokenTokenException() @@ -63,7 +65,9 @@ public function testHandleTokenTokenException() /** * @covers :: + * * @expectedException \Phug\ParserException + * * @expectedExceptionMessage Classes can only be used on elements and mixin calls */ public function testHandleClassOnWrongNode() diff --git a/tests/Phug/Parser/TokenHandler/CodeTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/CodeTokenHandlerTest.php index 47d54f1b..f73b2dc4 100644 --- a/tests/Phug/Parser/TokenHandler/CodeTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/CodeTokenHandlerTest.php @@ -98,7 +98,9 @@ public function testHandleCodeValue() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass code tokens to this token handler */ public function testHandleTokenTokenException() @@ -112,7 +114,9 @@ public function testHandleTokenTokenException() /** * @covers :: * @covers \Phug\Parser\State::throwException + * * @expectedException \Phug\ParserException + * * @expectedExceptionMessage Unexpected token `blockcode` expected `text`, `interpolated-code` or `code` */ public function testHandleTokenUnexpectedBlock() diff --git a/tests/Phug/Parser/TokenHandler/CommentTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/CommentTokenHandlerTest.php index c70db216..7c9dc3b3 100644 --- a/tests/Phug/Parser/TokenHandler/CommentTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/CommentTokenHandlerTest.php @@ -40,7 +40,9 @@ public function testHandleToken() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass comment tokens to this token handler */ public function testHandleTokenTokenException() diff --git a/tests/Phug/Parser/TokenHandler/ConditionalTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/ConditionalTokenHandlerTest.php index d6453d83..6877074a 100644 --- a/tests/Phug/Parser/TokenHandler/ConditionalTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/ConditionalTokenHandlerTest.php @@ -28,7 +28,9 @@ public function testHandleToken() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass conditional tokens to this token handler */ public function testHandleTokenTokenException() diff --git a/tests/Phug/Parser/TokenHandler/DoTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/DoTokenHandlerTest.php index b5756ff1..b14aa56f 100644 --- a/tests/Phug/Parser/TokenHandler/DoTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/DoTokenHandlerTest.php @@ -32,7 +32,9 @@ public function testHandleToken() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass do tokens to this token handler */ public function testHandleTokenTokenException() diff --git a/tests/Phug/Parser/TokenHandler/DoctypeTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/DoctypeTokenHandlerTest.php index c46e451c..06d7a7ab 100644 --- a/tests/Phug/Parser/TokenHandler/DoctypeTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/DoctypeTokenHandlerTest.php @@ -27,7 +27,9 @@ public function testHandleToken() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass doctype tokens to this token handler */ public function testHandleTokenTokenException() diff --git a/tests/Phug/Parser/TokenHandler/EachTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/EachTokenHandlerTest.php index 0d633132..00820946 100644 --- a/tests/Phug/Parser/TokenHandler/EachTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/EachTokenHandlerTest.php @@ -29,7 +29,9 @@ public function testHandleToken() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass each tokens to this token handler */ public function testHandleTokenTokenException() diff --git a/tests/Phug/Parser/TokenHandler/ExpansionTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/ExpansionTokenHandlerTest.php index ed976cee..942e3124 100644 --- a/tests/Phug/Parser/TokenHandler/ExpansionTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/ExpansionTokenHandlerTest.php @@ -74,7 +74,9 @@ public function testHandleToken() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass expansion tokens to this token handler */ public function testHandleTokenTokenException() diff --git a/tests/Phug/Parser/TokenHandler/ExpressionTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/ExpressionTokenHandlerTest.php index 49c040a5..d8932186 100644 --- a/tests/Phug/Parser/TokenHandler/ExpressionTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/ExpressionTokenHandlerTest.php @@ -33,7 +33,9 @@ public function testHandleToken() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass expression tokens to this token handler */ public function testHandleTokenTokenException() diff --git a/tests/Phug/Parser/TokenHandler/FilterTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/FilterTokenHandlerTest.php index 78c7122d..053e800b 100644 --- a/tests/Phug/Parser/TokenHandler/FilterTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/FilterTokenHandlerTest.php @@ -89,7 +89,9 @@ public function testHandleToken() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass filter tokens to this token handler */ public function testHandleTokenTokenException() diff --git a/tests/Phug/Parser/TokenHandler/ForTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/ForTokenHandlerTest.php index 70d35541..37b26cfe 100644 --- a/tests/Phug/Parser/TokenHandler/ForTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/ForTokenHandlerTest.php @@ -29,7 +29,9 @@ public function testHandleToken() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass for tokens to this token handler */ public function testHandleTokenTokenException() diff --git a/tests/Phug/Parser/TokenHandler/IdTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/IdTokenHandlerTest.php index 01ef6681..7031a9c7 100644 --- a/tests/Phug/Parser/TokenHandler/IdTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/IdTokenHandlerTest.php @@ -37,7 +37,9 @@ public function testHandleToken() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass id tokens to this token handler */ public function testHandleTokenTokenException() @@ -50,7 +52,9 @@ public function testHandleTokenTokenException() /** * @covers :: + * * @expectedException \Phug\ParserException + * * @expectedExceptionMessage IDs can only be used on elements and mixin calls */ public function testHandleTokenElementException() diff --git a/tests/Phug/Parser/TokenHandler/ImportTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/ImportTokenHandlerTest.php index c407c275..35d013eb 100644 --- a/tests/Phug/Parser/TokenHandler/ImportTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/ImportTokenHandlerTest.php @@ -38,7 +38,9 @@ public function testHandleToken() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass import tokens to this token handler */ public function testHandleTokenTokenException() @@ -52,7 +54,9 @@ public function testHandleTokenTokenException() /** * @covers :: * @covers ::isEmptyDocument + * * @expectedException \Phug\ParserException + * * @expectedExceptionMessage extends should be the very first statement in a document */ public function testDivTagBeforeExtends() @@ -63,7 +67,9 @@ public function testDivTagBeforeExtends() /** * @covers :: * @covers ::isEmptyDocument + * * @expectedException \Phug\ParserException + * * @expectedExceptionMessage extends should be the very first statement in a document */ public function testVisibleCommentBeforeExtends() @@ -74,7 +80,9 @@ public function testVisibleCommentBeforeExtends() /** * @covers :: * @covers ::isEmptyDocument + * * @expectedException \Phug\ParserException + * * @expectedExceptionMessage extends should be the very first statement in a document */ public function testMultipleThingsBeforeExtends() diff --git a/tests/Phug/Parser/TokenHandler/IndentTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/IndentTokenHandlerTest.php index 4aae531d..dfeaed36 100644 --- a/tests/Phug/Parser/TokenHandler/IndentTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/IndentTokenHandlerTest.php @@ -29,7 +29,9 @@ public function testHandleSingleLine() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass indent tokens to this token handler */ public function testHandleTokenTokenException() diff --git a/tests/Phug/Parser/TokenHandler/InterpolationEndTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/InterpolationEndTokenHandlerTest.php index 95b2853f..3851bf75 100644 --- a/tests/Phug/Parser/TokenHandler/InterpolationEndTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/InterpolationEndTokenHandlerTest.php @@ -16,7 +16,9 @@ class InterpolationEndTokenHandlerTest extends TestCase { /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass interpolation end tokens to this token handler */ public function testHandleTokenTokenException() diff --git a/tests/Phug/Parser/TokenHandler/InterpolationStartTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/InterpolationStartTokenHandlerTest.php index 2aad0bc4..ad334cf7 100644 --- a/tests/Phug/Parser/TokenHandler/InterpolationStartTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/InterpolationStartTokenHandlerTest.php @@ -127,7 +127,9 @@ public function testInterpolationInNestedBlock() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass interpolation start tokens to this token handler */ public function testHandleTokenTokenException() @@ -207,7 +209,9 @@ public function testInterpolationsWithOneTagPerLine() /** * @covers :: + * * @expectedException \Phug\ParserException + * * @expectedExceptionMessage Interpolation not properly closed */ public function testBadEndingException() diff --git a/tests/Phug/Parser/TokenHandler/KeywordTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/KeywordTokenHandlerTest.php index ec02d6b7..5855d0e3 100644 --- a/tests/Phug/Parser/TokenHandler/KeywordTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/KeywordTokenHandlerTest.php @@ -43,7 +43,9 @@ public function testHandleToken() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass keyword tokens to this token handler */ public function testHandleTokenTokenException() diff --git a/tests/Phug/Parser/TokenHandler/MixinCallTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/MixinCallTokenHandlerTest.php index a8ca9004..1011d8b5 100644 --- a/tests/Phug/Parser/TokenHandler/MixinCallTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/MixinCallTokenHandlerTest.php @@ -39,7 +39,9 @@ public function testHandleSingleLine() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass mixin call tokens to this token handler */ public function testHandleTokenTokenException() diff --git a/tests/Phug/Parser/TokenHandler/MixinTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/MixinTokenHandlerTest.php index 92b28314..44cfc85f 100644 --- a/tests/Phug/Parser/TokenHandler/MixinTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/MixinTokenHandlerTest.php @@ -29,7 +29,9 @@ public function testHandleSingleLine() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass mixin tokens to this token handler */ public function testHandleTokenTokenException() diff --git a/tests/Phug/Parser/TokenHandler/NewLineTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/NewLineTokenHandlerTest.php index 9cfcfccc..546bcc75 100644 --- a/tests/Phug/Parser/TokenHandler/NewLineTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/NewLineTokenHandlerTest.php @@ -31,7 +31,9 @@ public function testHandleSingleLine() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass newline tokens to this token handler */ public function testHandleTokenTokenException() diff --git a/tests/Phug/Parser/TokenHandler/OutdentTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/OutdentTokenHandlerTest.php index 1498938a..9079c422 100644 --- a/tests/Phug/Parser/TokenHandler/OutdentTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/OutdentTokenHandlerTest.php @@ -31,7 +31,9 @@ public function testHandleSingleLine() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass outdent tokens to this token handler */ public function testHandleTokenTokenException() diff --git a/tests/Phug/Parser/TokenHandler/TagInterpolationEndTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/TagInterpolationEndTokenHandlerTest.php index 2c3832c9..74ce312b 100644 --- a/tests/Phug/Parser/TokenHandler/TagInterpolationEndTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/TagInterpolationEndTokenHandlerTest.php @@ -16,7 +16,9 @@ class TagInterpolationEndTokenHandlerTest extends TestCase { /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass tag interpolation end tokens to this token handler */ public function testHandleTokenTokenException() diff --git a/tests/Phug/Parser/TokenHandler/TagInterpolationStartTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/TagInterpolationStartTokenHandlerTest.php index 18829d2a..9e6322e7 100644 --- a/tests/Phug/Parser/TokenHandler/TagInterpolationStartTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/TagInterpolationStartTokenHandlerTest.php @@ -127,7 +127,9 @@ public function testExpansionWithInterpolations() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass tag interpolation start tokens to this token handler */ public function testHandleTokenTokenException() diff --git a/tests/Phug/Parser/TokenHandler/TagTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/TagTokenHandlerTest.php index a929a94a..e3586e32 100644 --- a/tests/Phug/Parser/TokenHandler/TagTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/TagTokenHandlerTest.php @@ -50,7 +50,9 @@ public function testHandleToken() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass tag tokens to this token handler */ public function testHandleTokenTokenException() @@ -63,7 +65,9 @@ public function testHandleTokenTokenException() /** * @covers :: + * * @expectedException \Phug\ParserException + * * @expectedExceptionMessage Failed to parse: Tags can only be used on elements */ public function testHandleTokenElementTagsException() @@ -83,7 +87,9 @@ public function testHandleTokenElementTagsException() /** * @covers :: + * * @expectedException \Phug\ParserException + * * @expectedExceptionMessage Failed to parse: The element already has a tag name */ public function testHandleTokenTagNameException() diff --git a/tests/Phug/Parser/TokenHandler/TextTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/TextTokenHandlerTest.php index 9ebdad36..087bb4e3 100644 --- a/tests/Phug/Parser/TokenHandler/TextTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/TextTokenHandlerTest.php @@ -60,7 +60,9 @@ public function testHandleMarkup() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass text tokens to this token handler */ public function testHandleTokenTokenException() diff --git a/tests/Phug/Parser/TokenHandler/VariableTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/VariableTokenHandlerTest.php index a460bc86..cccfaf76 100644 --- a/tests/Phug/Parser/TokenHandler/VariableTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/VariableTokenHandlerTest.php @@ -28,7 +28,9 @@ public function testHandleToken() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass variable tokens to this token handler */ public function testHandleTokenTokenException() diff --git a/tests/Phug/Parser/TokenHandler/WhenTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/WhenTokenHandlerTest.php index 00363090..9b72832e 100644 --- a/tests/Phug/Parser/TokenHandler/WhenTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/WhenTokenHandlerTest.php @@ -50,7 +50,9 @@ public function testHandleToken() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass when tokens to this token handler */ public function testHandleTokenTokenException() diff --git a/tests/Phug/Parser/TokenHandler/WhileTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/WhileTokenHandlerTest.php index 550bc6e5..851e2096 100644 --- a/tests/Phug/Parser/TokenHandler/WhileTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/WhileTokenHandlerTest.php @@ -45,7 +45,9 @@ public function testHandleToken() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass while tokens to this token handler */ public function testHandleTokenTokenException() diff --git a/tests/Phug/Parser/TokenHandler/YieldTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/YieldTokenHandlerTest.php index 0513f0ee..0bca7050 100644 --- a/tests/Phug/Parser/TokenHandler/YieldTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/YieldTokenHandlerTest.php @@ -27,7 +27,9 @@ public function testHandleToken() /** * @covers :: + * * @expectedException \RuntimeException + * * @expectedExceptionMessage You can only pass yield tokens to this token handler */ public function testHandleTokenTokenException() diff --git a/tests/Phug/ParserModuleTest.php b/tests/Phug/ParserModuleTest.php index abad96a4..4ecd9af9 100644 --- a/tests/Phug/ParserModuleTest.php +++ b/tests/Phug/ParserModuleTest.php @@ -109,6 +109,7 @@ public function testStateEnterLeaveStoreEvents() /** * @group events + * * @covers \Phug\Parser::__construct * @covers \Phug\Parser\Event\ParseEvent:: * @covers \Phug\Parser\Event\NodeEvent:: diff --git a/tests/Phug/ParserTest.php b/tests/Phug/ParserTest.php index 56099a00..c62a8264 100644 --- a/tests/Phug/ParserTest.php +++ b/tests/Phug/ParserTest.php @@ -22,7 +22,9 @@ public function testParseAssignment() /** * @covers :: + * * @expectedException \InvalidArgumentException + * * @expectedExceptionMessage Passed lexer class ErrorException is not a valid Phug\Lexer */ public function testWrongLexerClassNameOption() @@ -34,7 +36,9 @@ public function testWrongLexerClassNameOption() /** * @covers :: + * * @expectedException \InvalidArgumentException + * * @expectedExceptionMessage Passed token handler needs to implement Phug\Parser\TokenHandlerInterface */ public function testWrongTokenHandler() @@ -45,7 +49,9 @@ public function testWrongTokenHandler() /** * @covers :: * @covers ::dumpNode + * * @expectedException \InvalidArgumentException + * * @expectedExceptionMessage parser_state_class_name needs to be a valid Phug\Parser\State sub class */ public function testWrongStateClassNameOption() diff --git a/tests/Phug/PhugTest.php b/tests/Phug/PhugTest.php index 35c87792..4bc803d0 100644 --- a/tests/Phug/PhugTest.php +++ b/tests/Phug/PhugTest.php @@ -258,7 +258,9 @@ public function testKeywords() /** * @covers ::setFilter + * * @expectedException \Phug\PhugException + * * @expectedExceptionMessage Invalid foo filter given: */ public function testWrongFilter() @@ -297,7 +299,9 @@ public function testGetExtensionsOptions() /** * @covers ::addExtension + * * @expectedException \Phug\PhugException + * * @expectedExceptionMessage Invalid not-an-extension extension given: */ public function testWrongExtension() diff --git a/tests/Phug/ProfilerModuleTest.php b/tests/Phug/ProfilerModuleTest.php index b13bca14..04eac097 100644 --- a/tests/Phug/ProfilerModuleTest.php +++ b/tests/Phug/ProfilerModuleTest.php @@ -19,6 +19,7 @@ class ProfilerModuleTest extends TestCase { /** * @group profiler + * * @covers ::record * @covers ::renderProfile * @covers ::cleanupProfilerNodes @@ -88,6 +89,7 @@ public function testRenderProfiler() /** * @group profiler + * * @covers ::record * @covers ::renderProfile * @covers ::recordDisplayEvent @@ -129,6 +131,7 @@ public function testLogProfiler() /** * @group profiler + * * @covers ::renderProfile * @covers \Phug\Renderer\Partial\Debug\DebuggerTrait::initDebugOptions */ @@ -151,6 +154,7 @@ public function testDebugDefaultOptions() /** * @group profiler + * * @covers ::renderProfile * @covers \Phug\Renderer\Partial\Debug\DebuggerTrait::initDebugOptions */ @@ -178,6 +182,7 @@ public function testMemoryLimitOptions() /** * @group profiler + * * @covers ::record * @covers ::renderProfile * @covers ::recordDisplayEvent @@ -216,6 +221,7 @@ public function testExecutionMaxTime() /** * @group profiler + * * @covers ::record * @covers ::renderProfile * @covers ::recordDisplayEvent @@ -265,6 +271,7 @@ public function testMemoryLimit() /** * @group profiler + * * @covers \Phug\Renderer\Profiler\TokenDump:: */ public function testTokenDump() @@ -294,6 +301,7 @@ public function testTokenDump() /** * @group profiler + * * @covers ::record * @covers ::renderProfile * @covers ::cleanupProfilerNodes @@ -347,6 +355,7 @@ public function testDisplayProfiler() /** * @group profiler + * * @covers ::reset * @covers ::initialize * @covers ::getFunctionDump @@ -396,6 +405,7 @@ public function testCustomDump() /** * @group profiler + * * @covers ::reset * @covers ::initialize * @covers ::getFunctionDump @@ -451,6 +461,7 @@ public function testEventVarDump() /** * @group profiler + * * @covers ::initialize * @covers ::getFunctionDump */ diff --git a/tests/Phug/ReaderTest.php b/tests/Phug/ReaderTest.php index a375fe8c..c1d0f0c9 100644 --- a/tests/Phug/ReaderTest.php +++ b/tests/Phug/ReaderTest.php @@ -198,6 +198,7 @@ public function testPeek() /** * @covers ::peek + * * @expectedException \InvalidArgumentException */ public function testPeekThrowsExceptionOnInvalidArguments() @@ -236,6 +237,7 @@ public function testMatch() * @covers ::getPregErrorText * @covers ::throwException * @covers \Phug\ReaderException + * * @expectedException \Phug\ReaderException */ public function testMatchFailsOnPregError() @@ -246,7 +248,9 @@ public function testMatchFailsOnPregError() /** * @covers ::throwException * @covers \Phug\ReaderException + * * @expectedException \Phug\ReaderException + * * @expectedExceptionMessage Path: path.pug */ public function testPathInErrors() @@ -275,6 +279,7 @@ public function testGetMatch() * @covers ::getMatch * @covers ::throwException * @covers \Phug\ReaderException + * * @expectedException \Phug\ReaderException */ public function testGetMatchCantOperateOnMissingMatchCall() @@ -297,6 +302,7 @@ public function testGetMatchData() * @covers ::getMatchData * @covers ::throwException * @covers \Phug\ReaderException + * * @expectedException \Phug\ReaderException */ public function testGetMatchDataCantOperateOnMissingMatchCall() @@ -336,6 +342,7 @@ public function testConsume() * @covers ::consume * @covers ::throwException * @covers \Phug\ReaderException + * * @expectedException \Phug\ReaderException */ public function testConsumeThrowsExceptionOnInvalidConsumeLength() @@ -361,6 +368,7 @@ public function testReadWhile() /** * @covers ::readWhile + * * @expectedException \InvalidArgumentException */ public function testReadWhileExpectsValidCallback() @@ -659,6 +667,7 @@ public function testReadString() * @covers ::readString * @covers ::throwException * @covers \Phug\ReaderException + * * @expectedException \Phug\ReaderException * * @dataProvider provideNotCorrectlyClosedStrings @@ -692,6 +701,7 @@ public function testReadExpression() * @covers ::readExpression * @covers ::throwException * @covers \Phug\ReaderException + * * @expectedException \Phug\ReaderException * * @dataProvider provideNotCorrectlyClosedBrackets @@ -726,7 +736,6 @@ public function testGetPregErrorText() public function testReadmeFirstLexingExample() { - //Some C-style example code $code = 'someVar = {a, "this is a string (really, it \"is\")", func(b, c), d}'; diff --git a/tests/Phug/RendererTest.php b/tests/Phug/RendererTest.php index a18051f5..9c0333d7 100644 --- a/tests/Phug/RendererTest.php +++ b/tests/Phug/RendererTest.php @@ -822,6 +822,7 @@ public function testHandleHtmlError() /** * @group error + * * @covers ::handleError * @covers \Phug\Renderer\Partial\AdapterTrait::getSandboxCall * @covers \Phug\Renderer\Partial\AdapterTrait::handleHtmlEvent @@ -1099,6 +1100,7 @@ public function testTwigOutput() /** * @expectedException Exception + * * @expectedExceptionMessage p= $undefined() */ public function testExtendsUndefinedCall() @@ -1120,6 +1122,7 @@ public function testExtendsUndefinedCall() /** * @expectedException Exception + * * @expectedExceptionMessage div= $undefined() */ public function testUndefinedCallInBlock() diff --git a/tests/Phug/Util/AssociativeStorageTest.php b/tests/Phug/Util/AssociativeStorageTest.php index a3ca61d4..c672804d 100644 --- a/tests/Phug/Util/AssociativeStorageTest.php +++ b/tests/Phug/Util/AssociativeStorageTest.php @@ -21,7 +21,9 @@ class AssociativeStorageTest extends TestCase /** * @covers :: * @covers ::attachStrictMode + * * @expectedException \InvalidArgumentException + * * @expectedExceptionMessage Duplicate entity for the name foo */ public function testStrictMode() @@ -39,7 +41,9 @@ public function testStrictMode() /** * @covers :: * @covers ::attachStrictMode + * * @expectedException \InvalidArgumentException + * * @expectedExceptionMessage Unknown mode: 99 */ public function testWrongMode() diff --git a/tests/Phug/Util/MacroableTraitTest.php b/tests/Phug/Util/MacroableTraitTest.php index c795f5b4..1bd9b0dc 100644 --- a/tests/Phug/Util/MacroableTraitTest.php +++ b/tests/Phug/Util/MacroableTraitTest.php @@ -130,7 +130,9 @@ public function testMacrosOption() /** * @covers \Phug\Util\Partial\MacroableTrait::__call + * * @expectedException \BadMethodCallException + * * @expectedExceptionMessage Method fooBar does not exist. */ public function testMacroCallBadMethod() @@ -141,7 +143,9 @@ public function testMacroCallBadMethod() /** * @covers \Phug\Util\Partial\MacroableTrait::__callStatic + * * @expectedException \BadMethodCallException + * * @expectedExceptionMessage Method fooBar does not exist. */ public function testMacroCallStaticBadMethod() diff --git a/tests/Phug/Util/ModuleContainerTest.php b/tests/Phug/Util/ModuleContainerTest.php index f15437af..2a4c80c9 100644 --- a/tests/Phug/Util/ModuleContainerTest.php +++ b/tests/Phug/Util/ModuleContainerTest.php @@ -100,7 +100,9 @@ public function testHasGetSetRemoveModule() /** * @covers ::getModuleBaseClassName * @covers ::addModule + * * @expectedException InvalidArgumentException + * * @expectedExceptionMessage Passed module class name stdClass needs to be a class extending Phug\Util\ModuleInterface and/or Phug\Util\ModuleInterface */ public function testInvalidModuleClassName() @@ -115,7 +117,9 @@ public function testInvalidModuleClassName() /** * @covers ::getModuleBaseClassName * @covers ::addModule + * * @expectedException InvalidArgumentException + * * @expectedExceptionMessage Module Phug\Test\Util\FirstTestModule is already registered. */ public function testDoubleRegistration() @@ -131,7 +135,9 @@ public function testDoubleRegistration() /** * @covers ::getModuleBaseClassName * @covers ::addModule + * * @expectedException InvalidArgumentException + * * @expectedExceptionMessage This occurrence of Phug\Test\Util\FirstTestModule is already registered. */ public function testInstanceDoubleRegistration() @@ -148,7 +154,9 @@ public function testInstanceDoubleRegistration() /** * @covers ::getModuleBaseClassName * @covers ::addModule + * * @expectedException InvalidArgumentException + * * @expectedExceptionMessage This occurrence of Phug\Test\Util\FirstTestModule is already registered in another module container. */ public function testInstanceDivergentRegistrations() @@ -164,7 +172,9 @@ public function testInstanceDivergentRegistrations() /** * @covers ::getModuleBaseClassName * @covers ::removeModule + * * @expectedException InvalidArgumentException + * * @expectedExceptionMessage The container doesn't contain a Phug\Test\Util\FirstTestModule module */ public function testRemovalOfNonExistentModule() @@ -180,7 +190,9 @@ public function testRemovalOfNonExistentModule() /** * @covers ::getModuleBaseClassName * @covers ::removeModule + * * @expectedException InvalidArgumentException + * * @expectedExceptionMessage This occurrence of Phug\Test\Util\FirstTestModule is not registered. */ public function testRemovalOfNonExistentModuleInstance() @@ -196,7 +208,9 @@ public function testRemovalOfNonExistentModuleInstance() /** * @covers ::addModule + * * @expectedException \RuntimeException + * * @expectedExceptionMessage Current module container uses the ModuleContainerTrait, but doesn't implement Phug\Util\ModuleContainerInterface, please implement it. */ public function testNonInterfacedContainer() diff --git a/tests/Phug/Util/UnorderedArgumentsTest.php b/tests/Phug/Util/UnorderedArgumentsTest.php index 02c68a30..953edc22 100644 --- a/tests/Phug/Util/UnorderedArgumentsTest.php +++ b/tests/Phug/Util/UnorderedArgumentsTest.php @@ -47,7 +47,9 @@ public function testRequired() /** * @covers ::required + * * @expectedException \InvalidArgumentException + * * @expectedExceptionMessage Arguments miss one of the boolean type */ public function testRequiredException() @@ -72,7 +74,9 @@ public function testNoMoreArguments() /** * @covers ::noMoreArguments * @covers ::noMoreDefinedArguments + * * @expectedException \InvalidArgumentException + * * @expectedExceptionMessage You pass 2 unexpected arguments */ public function testNoMoreArgumentsException() @@ -87,7 +91,9 @@ public function testNoMoreArgumentsException() /** * @covers ::noMoreArguments * @covers ::noMoreDefinedArguments + * * @expectedException \InvalidArgumentException + * * @expectedExceptionMessage You pass 2 unexpected arguments */ public function testNoMoreUndefinedArgumentsException() @@ -103,7 +109,9 @@ public function testNoMoreUndefinedArgumentsException() /** * @covers ::noMoreArguments * @covers ::noMoreDefinedArguments + * * @expectedException \InvalidArgumentException + * * @expectedExceptionMessage You pass 1 unexpected not null arguments */ public function testNoMoreDefinedArgumentsException() diff --git a/tests/Phug/Utils/AssertRender.php b/tests/Phug/Utils/AssertRender.php index 77a68d9e..791ef5a7 100644 --- a/tests/Phug/Utils/AssertRender.php +++ b/tests/Phug/Utils/AssertRender.php @@ -18,7 +18,7 @@ protected function prepareTest() } $this->compiler = new Compiler([ - 'paths' => [__DIR__.'/../templates'], + 'paths' => [__DIR__.'/../../templates'], 'patterns' => [ 'expression_in_text' => '%s', 'expression_in_bool' => '%s', @@ -32,10 +32,10 @@ protected function implodeLines($str) $attributes = []; $input = $matches[0]; while (mb_strlen($input) && preg_match( - '/^\s+([a-z0-9:_-]+)="((?:\\\\[\\S\\s]|[^"\\\\])*)"/', - $input, - $match - )) { + '/^\s+([a-z0-9:_-]+)="((?:\\\\[\\S\\s]|[^"\\\\])*)"/', + $input, + $match + )) { if ($match[1] === 'class') { $classes = explode(' ', $match[2]); sort($classes); From 548627556d021edafd7a9b3be74fafbc1d8e7bac Mon Sep 17 00:00:00 2001 From: Bastien Miclo Date: Tue, 15 Aug 2023 18:28:10 +0200 Subject: [PATCH 3/4] Add tests --- .../Renderer/Adapter/Stream/Template.php | 5 ++ src/Phug/Util/Util/TestCase.php | 2 + tests/Phug/Format/XmlFormatTest.php | 3 + .../AttributeTokenHandlerTest.php | 28 ++++++++ tests/Phug/Util/AttributesStorageTest.php | 69 +++++++++++++++++++ tests/Phug/Util/OrderedValueTest.php | 29 ++++++++ 6 files changed, 136 insertions(+) create mode 100644 tests/Phug/Util/AttributesStorageTest.php create mode 100644 tests/Phug/Util/OrderedValueTest.php diff --git a/src/Phug/Renderer/Renderer/Adapter/Stream/Template.php b/src/Phug/Renderer/Renderer/Adapter/Stream/Template.php index fb405391..cbff93cd 100644 --- a/src/Phug/Renderer/Renderer/Adapter/Stream/Template.php +++ b/src/Phug/Renderer/Renderer/Adapter/Stream/Template.php @@ -19,6 +19,11 @@ class Template */ private $data = ''; + /** + * @var mixed + */ + public $context; + /** * @param $path * diff --git a/src/Phug/Util/Util/TestCase.php b/src/Phug/Util/Util/TestCase.php index 5cbf7faf..2a89f307 100644 --- a/src/Phug/Util/Util/TestCase.php +++ b/src/Phug/Util/Util/TestCase.php @@ -6,6 +6,7 @@ use Phug\CompatibilityUtil\TestCaseTypeBase; use ReflectionMethod; +// @codeCoverageIgnoreStart if (!class_exists(TestCaseTypeBase::class)) { $setUp = @new ReflectionMethod(PHPUnitTestCase::class, 'setUp'); $testCaseInitialization = true; @@ -16,6 +17,7 @@ unset($testCaseInitialization); } +// @codeCoverageIgnoreEnd class TestCase extends TestCaseTypeBase { diff --git a/tests/Phug/Format/XmlFormatTest.php b/tests/Phug/Format/XmlFormatTest.php index 0f68ccab..b68096a0 100644 --- a/tests/Phug/Format/XmlFormatTest.php +++ b/tests/Phug/Format/XmlFormatTest.php @@ -678,8 +678,10 @@ public function testAttributeAssignmentsOption() /** * @covers ::yieldAssignmentElement * @covers ::formatOrderedAttributeAssignments + * @covers ::yieldAssignmentOrderedAttributes * @covers ::formatOrderedMarkupAttributes * @covers ::formatInnerCodeValue + * @covers ::getSortedAttributes */ public function testAttributeAttributePrecedence() { @@ -809,6 +811,7 @@ public function testAttributeAttributePrecedence() /** * @covers ::yieldAssignmentElement * @covers ::formatOrderedAttributeAssignments + * @covers ::yieldAssignmentOrderedAttributes * @covers ::formatOrderedMarkupAttributes * @covers ::formatInnerCodeValue * diff --git a/tests/Phug/Parser/TokenHandler/AttributeTokenHandlerTest.php b/tests/Phug/Parser/TokenHandler/AttributeTokenHandlerTest.php index 247ad39b..9247f082 100644 --- a/tests/Phug/Parser/TokenHandler/AttributeTokenHandlerTest.php +++ b/tests/Phug/Parser/TokenHandler/AttributeTokenHandlerTest.php @@ -8,6 +8,7 @@ use Phug\Lexer\Token\AttributeToken; use Phug\Lexer\Token\TagToken; use Phug\Parser; +use Phug\Parser\Node\AssignmentNode; use Phug\Parser\Node\AttributeNode; use Phug\Parser\Node\ElementNode; use Phug\Parser\State; @@ -60,6 +61,33 @@ public function testHandleTokenTokenException() $handler->handleToken(new TagToken(), $state); } + /** + * @covers :: + */ + public function testHandleTokenKeepOrder() + { + $lexer = new Lexer(); + $state = new State(new Parser(), $lexer->lex('(b="b")(a="a" c="c")')); + $handler = new AttributeTokenHandler(); + $assignmentNode = new AssignmentNode(); + $assignmentNode->setOrder(5); + $state->setCurrentNode($assignmentNode); + $token = new AttributeToken(); + $token->setName('b'); + $token->setValue('b'); + $handler->handleToken(new AttributeToken(), $state); + + /** @var AssignmentNode $currentNode */ + $currentNode = $state->getCurrentNode(); + + self::assertSame($currentNode, $assignmentNode); + + $attribute = iterator_to_array($currentNode->getAttributes())[0]; + + self::assertInstanceOf(AttributeNode::class, $attribute); + self::assertSame(5, $attribute->getOrder()); + } + /** * @covers \Phug\Parser\TokenHandler\AttributeEndTokenHandler:: * @covers \Phug\Parser\TokenHandler\AttributeStartTokenHandler:: diff --git a/tests/Phug/Util/AttributesStorageTest.php b/tests/Phug/Util/AttributesStorageTest.php new file mode 100644 index 00000000..f147d5f8 --- /dev/null +++ b/tests/Phug/Util/AttributesStorageTest.php @@ -0,0 +1,69 @@ +attach(new OrderedValue(42, null)); + $next = new SplObjectStorage(); + $next->attach(new OrderedValue('C', 3)); + $next->attach(new OrderedValue('A', 1)); + $storage->addAll($next); + + $output = []; + + foreach ($storage as $value) { + $output[] = [$value->getOrder(), $value->getValue()]; + } + + self::assertSame([ + [null, 42], + [3, 'C'], + [1, 'A'], + ], $output); + } + + /** + * @covers ::__construct + * @covers ::attach + * @covers ::addAll + */ + public function testMarkupHolder() + { + $storage = new AttributesStorage(new MarkupElement('div')); + $storage->attach(new OrderedValue(42, null)); + $next = new SplObjectStorage(); + $next->attach(new OrderedValue('C', -3)); + $next->attach(new OrderedValue('A', null)); + $storage->addAll($next); + + $output = []; + + foreach ($storage as $value) { + $output[] = [$value->getOrder(), $value->getValue()]; + } + + self::assertSame([ + [0, 42], + [-3, 'C'], + [1, 'A'], + ], $output); + } +} diff --git a/tests/Phug/Util/OrderedValueTest.php b/tests/Phug/Util/OrderedValueTest.php new file mode 100644 index 00000000..4b030047 --- /dev/null +++ b/tests/Phug/Util/OrderedValueTest.php @@ -0,0 +1,29 @@ +getValue()); + self::assertSame(3, $value->getOrder()); + + $value->setOrder(null); + $value->setValue('Hello'); + + self::assertSame('Hello', $value->getValue()); + self::assertSame(null, $value->getOrder()); + } +} From 9b9dcc0381d64d1bcd17597623b31f22f84823b7 Mon Sep 17 00:00:00 2001 From: Bastien Miclo Date: Tue, 15 Aug 2023 20:25:38 +0200 Subject: [PATCH 4/4] Fix PHP 8.2 issues --- .github/workflows/tests.yml | 2 +- src/Phug/Phug/Phug/Cli.php | 8 ++++---- .../Phug/Compiler/NodeCompiler/ImportNodeCompilerTest.php | 4 ++-- tests/Phug/Format/FakeFormat.php | 4 ++++ tests/Phug/FormatterTest.php | 2 +- tests/Phug/ProfilerModuleTest.php | 1 + tests/Phug/RendererTest.php | 4 ---- tests/Phug/Utils/AssertRender.php | 2 +- 8 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2aff22bd..8b865ce8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - php: ['5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] + php: ['5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] setup: ['lowest', 'stable', 'next'] name: PHP ${{ matrix.php }} - ${{ matrix.setup }} diff --git a/src/Phug/Phug/Phug/Cli.php b/src/Phug/Phug/Phug/Cli.php index 3375e37d..782f008e 100644 --- a/src/Phug/Phug/Phug/Cli.php +++ b/src/Phug/Phug/Phug/Cli.php @@ -152,21 +152,21 @@ protected function convertToKebabCase($string) { return preg_replace_callback('/[A-Z]/', function ($match) { return '-'.strtolower($match[0]); - }, $string); + }, (string) $string); } protected function convertToCamelCase($string) { return preg_replace_callback('/-([a-z])/', function ($match) { return strtoupper($match[1]); - }, $string); + }, (string) $string); } protected function execute($facade, $method, $arguments, $outputFile) { $callable = [$facade, $method]; $arguments = array_map(function ($argument) { - return in_array(substr($argument, 0, 1), ['[', '{']) + return in_array(substr((string) $argument, 0, 1), ['[', '{']) ? json_decode($argument, true) : $argument; }, $arguments); @@ -206,7 +206,7 @@ protected function getNamedArgumentBySpaceDelimiter(array &$arguments, $index, $ protected function getNamedArgumentByEqualOperator(array &$arguments, $index, $name) { - if (preg_match('/^'.preg_quote($name).'=(.*)$/', $arguments[$index], $match)) { + if (preg_match('/^'.preg_quote($name).'=(.*)$/', (string) $arguments[$index], $match)) { array_splice($arguments, $index, 1); return $match[1]; diff --git a/tests/Phug/Compiler/NodeCompiler/ImportNodeCompilerTest.php b/tests/Phug/Compiler/NodeCompiler/ImportNodeCompilerTest.php index a7ef86b1..73d8da6d 100644 --- a/tests/Phug/Compiler/NodeCompiler/ImportNodeCompilerTest.php +++ b/tests/Phug/Compiler/NodeCompiler/ImportNodeCompilerTest.php @@ -180,7 +180,7 @@ public function testNestedYield() $expected = file_get_contents(__DIR__.'/../../../templates/yield-in-sub-include.html'); $this->assertCompileFile( - str_replace("\n", '', $expected), + str_replace(["\r", "\n"], '', $expected), __DIR__.'/../../../templates/yield-in-sub-include.pug' ); } @@ -193,7 +193,7 @@ public function testMixinsPropagation() $expected = file_get_contents(__DIR__.'/../../../templates/inheritance.extend.mixins.html'); $this->assertRenderFile( - preg_replace('/\n\s*/', '', $expected), + preg_replace('/\r?\n\s*/', '', $expected), __DIR__.'/../../../templates/inheritance.extend.mixins.pug' ); } diff --git a/tests/Phug/Format/FakeFormat.php b/tests/Phug/Format/FakeFormat.php index 056932f9..c7f642db 100644 --- a/tests/Phug/Format/FakeFormat.php +++ b/tests/Phug/Format/FakeFormat.php @@ -19,20 +19,24 @@ public function __invoke(ElementInterface $element) return $helper($element->getName()); } + #[\ReturnTypeWillChange] public function offsetExists($offset) { return strpos($offset, 'non_existing') === false; } + #[\ReturnTypeWillChange] public function offsetGet($offset) { return $offset; } + #[\ReturnTypeWillChange] public function offsetSet($offset, $value) { } + #[\ReturnTypeWillChange] public function offsetUnset($offset) { } diff --git a/tests/Phug/FormatterTest.php b/tests/Phug/FormatterTest.php index 160c4a95..e1f838e2 100644 --- a/tests/Phug/FormatterTest.php +++ b/tests/Phug/FormatterTest.php @@ -450,7 +450,7 @@ public function testTransformExpression() self::assertSame( 'bar) || is_object($_pug_temp) && '. '!method_exists($_pug_temp, "__toString") ? json_encode($_pug_temp) : strval($_pug_temp)) ?>', - $formatter->format($expression, HtmlFormat::class) + preg_replace('/\s+/', ' ', $formatter->format($expression, HtmlFormat::class)) ); $attribute = new AttributeElement('class', new ExpressionElement('$foo.bar')); diff --git a/tests/Phug/ProfilerModuleTest.php b/tests/Phug/ProfilerModuleTest.php index 04eac097..315ac94f 100644 --- a/tests/Phug/ProfilerModuleTest.php +++ b/tests/Phug/ProfilerModuleTest.php @@ -187,6 +187,7 @@ public function testMemoryLimitOptions() * @covers ::renderProfile * @covers ::recordDisplayEvent * @covers ::getException + * @covers \Phug\Renderer\Partial\Debug\DebuggerTrait::getRendererException */ public function testExecutionMaxTime() { diff --git a/tests/Phug/RendererTest.php b/tests/Phug/RendererTest.php index 9c0333d7..c26be0cf 100644 --- a/tests/Phug/RendererTest.php +++ b/tests/Phug/RendererTest.php @@ -1283,10 +1283,6 @@ public function testConsecutiveStringRenders() */ public function testCacheDirectoryPreserveDependencies() { - if (version_compare(PHP_VERSION, '8.1.0-dev', '>=')) { - $this->markTestSkipped('Not compatible with PHP 8.1'); - } - $cacheDirectory = sys_get_temp_dir().'/pug-test'.mt_rand(0, 999999); $this->createEmptyDirectory($cacheDirectory); diff --git a/tests/Phug/Utils/AssertRender.php b/tests/Phug/Utils/AssertRender.php index 791ef5a7..cb482a5f 100644 --- a/tests/Phug/Utils/AssertRender.php +++ b/tests/Phug/Utils/AssertRender.php @@ -47,7 +47,7 @@ protected function implodeLines($str) sort($attributes); return ' '.implode(' ', $attributes); - }, is_string($str) ? $str : implode('', $str)); + }, str_replace("\r", '', is_string($str) ? $str : implode('', $str))); } protected function assertSameLines($expected, $actual)