Skip to content

Commit

Permalink
add E2E test
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Feb 9, 2022
1 parent c0678e0 commit 6b8e649
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 9 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/e2e_php74.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This workflow runs system tests: Use the Rector application from the source
# checkout to process "fixture" projects in e2e/ directory
# to see if those can be processed successfully
name: End to End tests on PHP 7.4

on:
pull_request:
branches:
- main
push:
branches:
- main

env:
# see https://github.com/composer/composer/issues/9368#issuecomment-718112361
COMPOSER_ROOT_VERSION: "dev-main"

jobs:
end_to_end:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
directory:
- 'e2e/php74-parse-static'

name: End to end test - ${{ matrix.directory }}

steps:
- uses: actions/checkout@v2

- uses: shivammathur/setup-php@v2
with:
php-version: 7.4
coverage: none

# run in root rector-src
- run: composer install --ansi

# run in e2e subdir
-
run: composer install --ansi
working-directory: ${{ matrix.directory }}

# run e2e test
- run: vendor/bin/rector --ansi
11 changes: 11 additions & 0 deletions e2e/php74-parse-static/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"require": {
"php": "7.4",
"api-platform/core": "^2.6",
"symfony/framework-bundle": "^5.4",
"symfony/http-client": "^5.4"
},
"require-dev": {
"rector/rector": "dev-main"
}
}
19 changes: 19 additions & 0 deletions e2e/php74-parse-static/rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

use Rector\DowngradePhp72\Rector\FuncCall\DowngradeJsonDecodeNullAssociativeArgRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Rector\Core\Configuration\Option;

return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();

$parameters->set(Option::PARALLEL, true);
$parameters->set(Option::PATHS, [
__DIR__ . '/tests',
]);

$services = $containerConfigurator->services();
$services->set(DowngradeJsonDecodeNullAssociativeArgRector::class);
};
15 changes: 15 additions & 0 deletions e2e/php74-parse-static/tests/ApiTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase;
use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\Client;

class ApiTest extends ApiTestCase
{
protected function setUp(): void
{
parent::setUp();
static::createClient();
}
}
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -606,3 +606,8 @@ parameters:

# on purpose to fix tests + old PHP version parsing code and keep compatbility
- '#Extending PHPStan\\Parser\\PathRoutingParser is not covered by backward compatibility promise\. The class might change in a minor PHPStan version#'

# false positive
-
message: '#Dead catch (.*?) ParseError is never thrown in the try block#'
path: src/PhpParser/Parser/RectorPathRoutingParser.php
7 changes: 2 additions & 5 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Rector\Core\Configuration\Option;
use Rector\Nette\Set\NetteSetList;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
use Rector\Php81\Rector\Class_\MyCLabsClassToEnumRector;
use Rector\Php81\Rector\Class_\SpatieEnumClassToEnumRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
Expand Down Expand Up @@ -74,10 +73,8 @@
MyCLabsClassToEnumRector::class,
SpatieEnumClassToEnumRector::class,

// on purpose with private property parent - @todo fix later
ClassPropertyAssignToConstructorPromotionRector::class => [
__DIR__ . '/src/PhpParser/Parser/RectorPathRoutingParser.php',
],
// code for phpstan with named arguments
__DIR__ . '/src/PhpParser/Parser/RectorPathRoutingParser.php',

// test paths
'*/tests/**/Fixture/*',
Expand Down
10 changes: 6 additions & 4 deletions src/PhpParser/Parser/RectorPathRoutingParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\Core\PhpParser\Parser;

use ParseError;
use PhpParser\Node\Stmt;
use PHPStan\Parser\CachedParser;
use PHPStan\Parser\Parser;
Expand Down Expand Up @@ -31,12 +32,13 @@ public function __construct(
*/
public function parseFile(string $file): array
{
// for tests, always parse nodes with directly rich parser to be aware of types
if (defined('PHPUNIT_COMPOSER_INSTALL')) {
try {
// try informative parser to let PHPStan know the types
return $this->currentPhpVersionRichParser->parseFile($file);
} catch (ParseError) {
// fallback to routing parser
return $this->phpstanPathRoutingParser->parseFile($file);
}

return $this->phpstanPathRoutingParser->parseFile($file);
}

/**
Expand Down

0 comments on commit 6b8e649

Please sign in to comment.