Skip to content

Commit

Permalink
Add PHP 8.4 (alpha build) tests support
Browse files Browse the repository at this point in the history
  • Loading branch information
SerafimArts committed Jul 28, 2024
1 parent ac3cbc3 commit 50778dc
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 10 deletions.
7 changes: 4 additions & 3 deletions src/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ private function each(iterable $nodes): iterable
* Recursively traverse array (usually of nodes).
*
* @param array<array-key, object> $nodes Array to traverse
*
* @return array<array-key, object> Result of traversal. May be original
* array or changed one.
*/
Expand Down Expand Up @@ -230,6 +229,7 @@ protected function traverseArray(array $nodes): array
$error = \sprintf($error, \get_class($visitor), \gettype($visitor));

throw new BadMethodException($error, static::ERROR_CODE_ARRAY_ENTERING);

default:
$error = self::ERROR_ENTER_RETURN_TYPE;
$error = \sprintf($error, \get_class($visitor), \gettype($visitor));
Expand Down Expand Up @@ -297,8 +297,7 @@ protected function traverseArray(array $nodes): array
/**
* Recursively traverse a node.
*
* @param NodeInterface $node nodeInterface to traverse
*
* @param NodeInterface $node NodeInterface to traverse.
* @return NodeInterface Result of traversal (may be original node or new one)
*/
protected function traverseNode(NodeInterface $node): NodeInterface
Expand Down Expand Up @@ -376,6 +375,7 @@ protected function traverseNode(NodeInterface $node): NodeInterface
$error = \sprintf($error, \get_class($visitor));

throw new BadReturnTypeException($error, static::ERROR_CODE_NODE_LEAVING);

default:
$error = self::ERROR_LEAVE_RETURN_TYPE;
$error = \sprintf($error, \get_class($visitor), \gettype($return));
Expand All @@ -396,6 +396,7 @@ protected function traverseNode(NodeInterface $node): NodeInterface

/**
* @param string|int $key
* @param mixed $value
*/
private function updateNodeValue(NodeInterface $node, $key, $value): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/ExecutorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface ExecutorInterface
/**
* Traverses an array of nodes using the registered visitors.
*
* @param iterable<array-key, object> $nodes list of nodes
* @param iterable<array-key, object> $nodes List of nodes.
*
* @return iterable<array-key, object> Traversed list of nodes
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Traverser.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@

namespace Phplrt\Visitor;

use Phplrt\Contracts\Ast\NodeInterface;

class Traverser implements TraverserInterface
{
/**
Expand Down
3 changes: 2 additions & 1 deletion src/TraverserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Phplrt\Visitor;

use Phplrt\Contracts\Ast\NodeInterface;

/**
* The TraverserInterface allows to traverse groups of
* nodes using visitor sets.
Expand Down Expand Up @@ -73,7 +75,6 @@ public function without(VisitorInterface $visitor): self;
* registered visitors.
*
* @param iterable<array-key, object> $nodes
*
* @return iterable<array-key, object>
*/
public function traverse(iterable $nodes): iterable;
Expand Down
6 changes: 4 additions & 2 deletions src/VisitorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,28 @@ interface VisitorInterface
* Called once before traversal.
*
* @param iterable|NodeInterface[]|NodeInterface $nodes
*
* @return iterable|NodeInterface[]|NodeInterface|null
*/
public function before(iterable $nodes): ?iterable;

/**
* Called when entering a node.
*
* @return mixed
*/
public function enter(NodeInterface $node);

/**
* Called when leaving a node.
*
* @return mixed
*/
public function leave(NodeInterface $node);

/**
* Called once after traversal.
*
* @param iterable|NodeInterface[]|NodeInterface $nodes
*
* @return iterable|NodeInterface[]|NodeInterface|null
*/
public function after(iterable $nodes): ?iterable;
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Mutations/BeforeTraversingMutationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Phplrt\Visitor\Tests\Unit\Stub\Node;
use Phplrt\Visitor\Tests\Unit\TestCase;
use Phplrt\Visitor\Visitor;
use PHPUnit\Framework\ExpectationFailedException;

/**
* @testdox A set of tests that verify an AST modification using the Visitor::before() method.
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Mutations/EnteringMutationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Phplrt\Visitor\Tests\Unit\Stub\Node;
use Phplrt\Visitor\Tests\Unit\TestCase;
use Phplrt\Visitor\Visitor;
use PHPUnit\Framework\ExpectationFailedException;

/**
* @testdox A set of tests that verify an AST modification using the Visitor::enter() method.
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Mutations/LeavingMutationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Phplrt\Visitor\Tests\Unit\Stub\Node;
use Phplrt\Visitor\Tests\Unit\TestCase;
use Phplrt\Visitor\Visitor;
use PHPUnit\Framework\ExpectationFailedException;

/**
* @testdox A set of tests that verify an AST modification using the Visitor::leave() method.
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Stub/Counter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
class Counter implements VisitorInterface
{
public $before = 0;
public $after = 0;
public $enter = 0;
public $leave = 0;
public $after = 0;
public $enter = 0;
public $leave = 0;

public function before(iterable $nodes): ?iterable
{
Expand Down
13 changes: 13 additions & 0 deletions tests/Unit/Stub/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,24 @@ class Node implements NodeInterface
*/
public array $children;

/**
* @var int
*/
private int $id;

/**
* @param int $id
* @param array $children
*/
public function __construct(int $id, array $children = [])
{
$this->id = $id;
$this->children = $children;
}

/**
* @return int
*/
public function getId(): int
{
return $this->id;
Expand All @@ -34,6 +44,9 @@ public function getIterator(): \Traversable
return new \ArrayIterator(['children' => $this->children]);
}

/**
* @return int
*/
public function getOffset(): int
{
return 0;
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/TraversableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Phplrt\Visitor\Tests\Unit;

use Phplrt\Visitor\Tests\Unit\Stub\Counter;
use PHPUnit\Framework\ExpectationFailedException;

/**
* @testdox A set of tests that count the number of passes by nodes.
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/VisitorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Phplrt\Visitor\Tests\Unit\Stub\Counter;
use Phplrt\Visitor\Traverser;
use PHPUnit\Framework\ExpectationFailedException;

/**
* @testdox A set of tests that check the interaction of Visitor instances with the Traversable container.
Expand Down

0 comments on commit 50778dc

Please sign in to comment.