From e4c4b9f3d337c74b6a91b17ff62ba0133725a97b Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Tue, 14 Dec 2021 08:04:38 +0100 Subject: [PATCH] Fix tests and CS. --- .github/workflows/ci.yml | 4 +++- src/Tokenizer/Tokens.php | 6 ++++-- src/Tokenizer/Transformer/ReturnRefTransformer.php | 2 +- tests/Fixer/ClassNotation/VisibilityRequiredFixerTest.php | 1 - tests/Tokenizer/TokensTest.php | 4 ++-- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ac4642ad666..84faf63f0cc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -124,7 +124,9 @@ jobs: env: PHP_CS_FIXER_IGNORE_ENV: ${{ matrix.PHP_CS_FIXER_IGNORE_ENV }} FAST_LINT_TEST_CASES: ${{ matrix.FAST_LINT_TEST_CASES }} - run: vendor/bin/phpunit ${{ matrix.phpunit-flags }} + run: | + php -v + vendor/bin/phpunit ${{ matrix.phpunit-flags }} - name: Upload coverage results to Coveralls if: matrix.calculate-code-coverage == 'yes' diff --git a/src/Tokenizer/Tokens.php b/src/Tokenizer/Tokens.php index 7987598b1b1..56ccb8348bd 100644 --- a/src/Tokenizer/Tokens.php +++ b/src/Tokenizer/Tokens.php @@ -859,8 +859,10 @@ public function insertSlices(array $slices): void krsort($slices); - if (array_key_first($slices) > $oldSize) { - throw new \OutOfBoundsException('Cannot insert outside of collection.'); + $firstIndex = key($slices); + + if (!\is_int($firstIndex) || $firstIndex > $oldSize) { + throw new \OutOfBoundsException(sprintf('Invalid index "%s".', $firstIndex)); } $insertBound = $oldSize - 1; diff --git a/src/Tokenizer/Transformer/ReturnRefTransformer.php b/src/Tokenizer/Transformer/ReturnRefTransformer.php index 19a8030442f..06d7c9dd54f 100644 --- a/src/Tokenizer/Transformer/ReturnRefTransformer.php +++ b/src/Tokenizer/Transformer/ReturnRefTransformer.php @@ -46,7 +46,7 @@ public function process(Tokens $tokens, Token $token, int $index): void $prevKinds[] = T_FN; } - if (($token->equals('&')) && $tokens[$tokens->getPrevMeaningfulToken($index)]->isGivenKind($prevKinds)) { + if ($token->equals('&') && $tokens[$tokens->getPrevMeaningfulToken($index)]->isGivenKind($prevKinds)) { $tokens[$index] = new Token([CT::T_RETURN_REF, '&']); } } diff --git a/tests/Fixer/ClassNotation/VisibilityRequiredFixerTest.php b/tests/Fixer/ClassNotation/VisibilityRequiredFixerTest.php index 1e673487379..1ec1ebeb9de 100644 --- a/tests/Fixer/ClassNotation/VisibilityRequiredFixerTest.php +++ b/tests/Fixer/ClassNotation/VisibilityRequiredFixerTest.php @@ -518,7 +518,6 @@ public function testInvalidConfigurationValue(): void } /** - * @requires PHP 7.1 * @dataProvider provideFixClassConstCases */ public function testFixClassConst(string $expected, string $input): void diff --git a/tests/Tokenizer/TokensTest.php b/tests/Tokenizer/TokensTest.php index 281132a7a8c..38c1242488b 100644 --- a/tests/Tokenizer/TokensTest.php +++ b/tests/Tokenizer/TokensTest.php @@ -1485,8 +1485,8 @@ public function provideInsertSlicesCases(): iterable $slices = [ [0 => $openTagToken], - [0 => [$openTagToken]], - [0 => Tokens::fromArray([$openTagToken])], + [0 => [clone $openTagToken]], + [0 => clone Tokens::fromArray([$openTagToken])], ]; foreach ($slices as $i => $slice) {