Skip to content

Commit

Permalink
Add PHP 8.4 tests support
Browse files Browse the repository at this point in the history
  • Loading branch information
SerafimArts committed Jul 28, 2024
1 parent f15f0c7 commit 8961be8
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ '7.4', '8.0', '8.1', '8.2', '8.3' ]
php: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ]
os: [ ubuntu-latest, macos-latest, windows-latest ]
stability: [ prefer-lowest, prefer-stable ]
steps:
Expand Down
1 change: 1 addition & 0 deletions src/ArrayBuffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function __construct(iterable $stream)

/**
* @param iterable<int<0, max>, TokenInterface> $tokens
*
* @return array<int<0, max>, TokenInterface>
*/
private function iterableToArray(iterable $tokens): array
Expand Down
1 change: 1 addition & 0 deletions src/Buffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function seek($offset): void

/**
* @param array<TokenInterface> $data
*
* @psalm-suppress PossiblyNullArrayOffset
*/
protected function currentFrom(array $data): TokenInterface
Expand Down
6 changes: 6 additions & 0 deletions src/BufferInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface BufferInterface extends \SeekableIterator
* Rewind the BufferInterface to the target token element.
*
* @link https://php.net/manual/en/seekableiterator.seek.php
*
* @see \SeekableIterator::seek()
*
* @param int<0, max> $offset
Expand All @@ -25,6 +26,7 @@ public function seek($offset): void;
* Return the current token.
*
* @link https://php.net/manual/en/iterator.current.php
*
* @see \Iterator::current()
*/
public function current(): TokenInterface;
Expand All @@ -33,6 +35,7 @@ public function current(): TokenInterface;
* Return the ordinal id of the current token element.
*
* @link https://php.net/manual/en/iterator.key.php
*
* @see \Iterator::key()
*
* @return int<0, max>
Expand All @@ -43,6 +46,7 @@ public function key(): int;
* Checks if current position is valid and iterator not completed.
*
* @link https://php.net/manual/en/iterator.valid.php
*
* @see \Iterator::valid()
*/
public function valid(): bool;
Expand All @@ -51,6 +55,7 @@ public function valid(): bool;
* Rewind the BufferInterface to the first token element.
*
* @link https://php.net/manual/en/iterator.rewind.php
*
* @see \Iterator::rewind()
*/
public function rewind(): void;
Expand All @@ -59,6 +64,7 @@ public function rewind(): void;
* Move forward to next token element.
*
* @link https://php.net/manual/en/iterator.next.php
*
* @see \Iterator::next()
*/
public function next(): void;
Expand Down
2 changes: 1 addition & 1 deletion src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

final class Factory implements FactoryInterface
{
public function create(iterable $tokens, int $size = null): BufferInterface
public function create(iterable $tokens, ?int $size = null): BufferInterface
{
if ($size === null) {
return new ArrayBuffer($tokens);
Expand Down
2 changes: 1 addition & 1 deletion src/LazyBuffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function __construct(iterable $stream)

/**
* @param iterable<TokenInterface> $stream
*
* @return \Generator<mixed, TokenInterface, mixed, mixed>
*/
private function toGenerator(iterable $stream): \Generator
Expand Down Expand Up @@ -113,7 +114,6 @@ protected function nextValid(): bool
}

/**
* {@inheritDoc}
* @psalm-suppress MixedReturnTypeCoercion
*/
public function key(): int
Expand Down
14 changes: 8 additions & 6 deletions tests/Unit/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ public static function buffersDataProvider(): array
{
return [
'Generator' => [
static::create(self::createTokens((static::$bufferSize))),
static::create(self::createTokens(static::$bufferSize)),
],
'array' => [
static::create([
...self::createTokens((static::$bufferSize)),
...self::createTokens(static::$bufferSize),
]),
],
'IteratorIterator' => [
static::create(new \IteratorIterator(
self::createTokens((static::$bufferSize)),
self::createTokens(static::$bufferSize),
)),
],
'ArrayIterator' => [
static::create(new \ArrayIterator([
...self::createTokens((static::$bufferSize)),
...self::createTokens(static::$bufferSize),
])),
],
];
Expand Down Expand Up @@ -95,7 +95,8 @@ public function testRewindable(BufferInterface $buffer): void
$needle = $buffer->current();

// Iterate
foreach ($buffer as $token);
foreach ($buffer as $token) {
}

$this->assertNotSame($needle, $buffer->current());
$buffer->rewind();
Expand All @@ -113,7 +114,8 @@ public function testSeekAhead(BufferInterface $buffer): void

$buffer->rewind();

foreach ($buffer as $item);
foreach ($buffer as $item) {
}

$this->assertSame($buffer->current(), $needle);
}
Expand Down

0 comments on commit 8961be8

Please sign in to comment.