Skip to content

Commit

Permalink
Php 8 support (#160)
Browse files Browse the repository at this point in the history
* Php 8 support

* Made typehints cross-version compatible

* Fixes

* Remove dep cache in unit tests

* fixes
  • Loading branch information
sspat authored Dec 29, 2020
1 parent 40e0b7a commit 0505f41
Show file tree
Hide file tree
Showing 18 changed files with 119 additions and 221 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
dependencies:
- "locked"
php-version:
- "7.4"
- "8.0"
operating-system:
- "ubuntu-latest"
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
dependencies:
- "locked"
php-version:
- "7.4"
- "8.0"
operating-system:
- "ubuntu-latest"
steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/mutation-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
dependencies:
- "locked"
php-version:
- "7.4"
- "8.0"
operating-system:
- "ubuntu-latest"
steps:
Expand Down Expand Up @@ -43,7 +43,7 @@ jobs:
if: ${{ matrix.dependencies == 'locked' }}
run: "composer install --no-interaction --no-progress --no-suggest"
- name: "Infection"
run: "vendor/bin/infection --only-covered --test-framework-options=\"--testsuite=unit\""
run: "vendor/bin/roave-infection-static-analysis-plugin --only-covered --test-framework-options=\"--testsuite=unit\""
env:
INFECTION_BADGE_API_KEY: ${{ secrets.INFECTION_BADGE_API_KEY }}
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
dependencies:
- "locked"
php-version:
- "7.4"
- "8.0"
operating-system:
- "ubuntu-latest"
steps:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
- "locked"
php-version:
- "7.4"
- "8.0"
operating-system:
- "ubuntu-latest"
- "windows-latest"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
dependencies:
- "locked"
php-version:
- "7.4"
- "8.0"
operating-system:
- "ubuntu-latest"
steps:
Expand Down
55 changes: 28 additions & 27 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,43 @@
}
],
"require": {
"php": ">=7.4.1,<7.5.0",
"php": "^7.4|^8.0",
"ext-json": "*",
"cebe/php-openapi": "^1.4",
"league/openapi-psr7-validator": "^0.9.0",
"lukasoppermann/http-status": "^2.0",
"nikic/php-parser": "^4.5",
"league/openapi-psr7-validator": "^0.14.0",
"lukasoppermann/http-status": "^3.1",
"nikic/php-parser": "^4.10",
"nyholm/psr7": "^1.3",
"phpdocumentor/reflection-docblock": "^5.1",
"sspat/reserved-words": "^1.0",
"symfony/cache": "^5.0",
"symfony/config": "^5.0",
"symfony/console": "^5.0",
"symfony/dependency-injection": "^5.0",
"symfony/event-dispatcher": "^5.0",
"symfony/http-kernel": "^5.0",
"symfony/process": "^5.0",
"phpdocumentor/reflection-docblock": "^5.2",
"sspat/reserved-words": "^2.0",
"symfony/cache": "^5.1",
"symfony/config": "^5.1.4",
"symfony/console": "^5.1",
"symfony/dependency-injection": "^5.1.4",
"symfony/event-dispatcher": "^5.1",
"symfony/http-kernel": "^5.1",
"symfony/process": "^5.1",
"symfony/psr-http-message-bridge": "^2.0",
"symfony/routing": "^5.0",
"symfony/yaml": "^5.0",
"thecodingmachine/safe": "^1.0"
"symfony/routing": "^5.1",
"symfony/yaml": "^5.1",
"thecodingmachine/safe": "^1.3"
},
"require-dev": {
"doctrine/coding-standard": "^8.1.0",
"infection/infection": "^0.16.4",
"doctrine/coding-standard": "^8.2",
"infection/infection": "^0.20.2",
"matthiasnoback/symfony-config-test": "^4.2",
"matthiasnoback/symfony-dependency-injection-test": "^4.1",
"phpstan/phpstan": "^0.12.33",
"phpstan/phpstan-phpunit": "^0.12.13",
"phpstan/phpstan-strict-rules": "^0.12.4",
"phpunit/phpunit": "^9.2.6",
"matthiasnoback/symfony-dependency-injection-test": "^4.2",
"phpstan/phpstan": "^0.12.64",
"phpstan/phpstan-phpunit": "^0.12.17",
"phpstan/phpstan-strict-rules": "^0.12.7",
"phpunit/phpunit": "^9.5",
"roave/infection-static-analysis-plugin": "^1.6",
"sensiolabs/security-checker": "^6.0",
"squizlabs/php_codesniffer": "^3.5.5",
"squizlabs/php_codesniffer": "^3.5",
"symfony/browser-kit": "^5.1",
"symfony/framework-bundle": "^5.1",
"thecodingmachine/phpstan-safe-rule": "^1.0.0",
"vimeo/psalm": "^3.12.2"
"thecodingmachine/phpstan-safe-rule": "^1.0",
"vimeo/psalm": "^4.3"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down Expand Up @@ -86,7 +87,7 @@
"stan": "phpstan analyse --memory-limit=-1",
"sec": "security-checker security:check",
"tests": "phpunit --fail-on-warning",
"mutation": "infection --only-covered --test-framework-options=\"--testsuite=unit\"",
"mutation": "vendor/bin/roave-infection-static-analysis-plugin --only-covered --test-framework-options=\"--testsuite=unit\"",
"all": "composer psalm && composer stan && composer tests && composer mutation && composer cs && composer sec"
}
}
File renamed without changes.
35 changes: 27 additions & 8 deletions test/functional/Command/CommandTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,52 @@

namespace OnMoon\OpenApiServerBundle\Test\Functional\Command;

use OnMoon\OpenApiServerBundle\Test\Functional\TestKernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

use function get_class;

abstract class CommandTestCase extends KernelTestCase
{
/**
* phpcs:disable SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
* @var string $class
*/
protected static $class = CommandTestKernel::class;

protected string $openapiNamespace = 'PetStore';
protected string $openapiOperationId = 'getGood';
protected CommandTester $commandTester;
protected Application $application;

/**
* @param mixed[] $data
*/
public function __construct(?string $name = null, array $data = [], string $dataName = '')
{
parent::__construct($name, $data, $dataName);

$kernelClass = new class ('test', true) extends TestKernel {
protected function configureContainer(ContainerConfigurator $c): void
{
}

protected function configureRoutes(RoutingConfigurator $routes): void
{
}
};

self::$class = get_class($kernelClass);
}

public function setUp(): void
{
$this->application = new Application(static::bootKernel());
$this->application = new Application(self::bootKernel());
}

public function tearDown(): void
{
$filesystem = new Filesystem();
$filesystem->remove([CommandTestKernel::$bundleRootPath]);
$filesystem->remove([TestKernel::$bundleRootPath]);
unset($this->commandTester, $this->application);
parent::tearDown();
}
Expand Down
15 changes: 8 additions & 7 deletions test/functional/Command/DeleteGeneratedCodeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace OnMoon\OpenApiServerBundle\Test\Functional\Command;

use OnMoon\OpenApiServerBundle\Command\DeleteGeneratedCodeCommand;
use OnMoon\OpenApiServerBundle\Test\Functional\TestKernel;
use PHPUnit\Framework\Assert;
use Symfony\Component\Console\Tester\CommandTester;

Expand All @@ -25,8 +26,8 @@ public function setUp(): void
$command = $this->application->find(DeleteGeneratedCodeCommand::COMMAND);
$this->commandTester = new CommandTester($command);

mkdir(CommandTestKernel::$bundleRootPath);
file_put_contents(CommandTestKernel::$bundleRootPath . '/test.txt', '');
mkdir(TestKernel::$bundleRootPath);
file_put_contents(TestKernel::$bundleRootPath . '/test.txt', '');
}

public function testDeletion(): void
Expand All @@ -38,9 +39,9 @@ public function testDeletion(): void
]);

$output = $this->commandTester->getDisplay();
Assert::assertEquals(sprintf('Delete all contents of the directory %1$s? (y/n): All contents of directory were deleted: %1$s', CommandTestKernel::$bundleRootPath), rtrim($output));
Assert::assertEquals(sprintf('Delete all contents of the directory %1$s? (y/n): All contents of directory were deleted: %1$s', TestKernel::$bundleRootPath), rtrim($output));
Assert::assertSame(0, $this->commandTester->getStatusCode());
Assert::assertFileDoesNotExist(CommandTestKernel::$bundleRootPath . '/test.txt');
Assert::assertFileDoesNotExist(TestKernel::$bundleRootPath . '/test.txt');
}

public function testDeletionCancel(): void
Expand All @@ -52,9 +53,9 @@ public function testDeletionCancel(): void
]);

$output = $this->commandTester->getDisplay();
Assert::assertEquals(sprintf('Delete all contents of the directory %1$s? (y/n):', CommandTestKernel::$bundleRootPath), rtrim($output));
Assert::assertEquals(sprintf('Delete all contents of the directory %1$s? (y/n):', TestKernel::$bundleRootPath), rtrim($output));
Assert::assertSame(0, $this->commandTester->getStatusCode());
Assert::assertDirectoryExists(CommandTestKernel::$bundleRootPath);
Assert::assertFileExists(CommandTestKernel::$bundleRootPath . '/test.txt');
Assert::assertDirectoryExists(TestKernel::$bundleRootPath);
Assert::assertFileExists(TestKernel::$bundleRootPath . '/test.txt');
}
}
17 changes: 9 additions & 8 deletions test/functional/Command/GenerateApiCodeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace OnMoon\OpenApiServerBundle\Test\Functional\Command;

use OnMoon\OpenApiServerBundle\Command\GenerateApiCodeCommand;
use OnMoon\OpenApiServerBundle\Test\Functional\TestKernel;
use PHPUnit\Framework\Assert;
use Symfony\Component\Console\Tester\CommandTester;

Expand All @@ -31,14 +32,14 @@ public function testGeneration(): void
]);

$output = $this->commandTester->getDisplay();
Assert::assertEquals(sprintf('API server code generated in: %s', CommandTestKernel::$bundleRootPath), rtrim($output));
Assert::assertEquals(sprintf('API server code generated in: %s', TestKernel::$bundleRootPath), rtrim($output));
Assert::assertSame(0, $this->commandTester->getStatusCode());
Assert::assertDirectoryExists(CommandTestKernel::$bundleRootPath);
Assert::assertDirectoryIsReadable(CommandTestKernel::$bundleRootPath);
Assert::assertFileExists(CommandTestKernel::$bundleRootPath . '/ServiceSubscriber/ApiServiceLoaderServiceSubscriber.php');
Assert::assertFileExists(CommandTestKernel::$bundleRootPath . '/Apis/' . $this->openapiNamespace . '/' . ucfirst($this->openapiOperationId) . '/' . ucfirst($this->openapiOperationId) . '.php');
Assert::assertFileExists(CommandTestKernel::$bundleRootPath . '/Apis/' . $this->openapiNamespace . '/' . ucfirst($this->openapiOperationId) . '/Dto/Request/' . ucfirst($this->openapiOperationId) . 'RequestDto.php');
Assert::assertFileExists(CommandTestKernel::$bundleRootPath . '/Apis/' . $this->openapiNamespace . '/' . ucfirst($this->openapiOperationId) . '/Dto/Request/PathParameters/PathParametersDto.php');
Assert::assertFileExists(CommandTestKernel::$bundleRootPath . '/Apis/' . $this->openapiNamespace . '/' . ucfirst($this->openapiOperationId) . '/Dto/Response/OK/' . ucfirst($this->openapiOperationId) . 'OKDto.php');
Assert::assertDirectoryExists(TestKernel::$bundleRootPath);
Assert::assertDirectoryIsReadable(TestKernel::$bundleRootPath);
Assert::assertFileExists(TestKernel::$bundleRootPath . '/ServiceSubscriber/ApiServiceLoaderServiceSubscriber.php');
Assert::assertFileExists(TestKernel::$bundleRootPath . '/Apis/' . $this->openapiNamespace . '/' . ucfirst($this->openapiOperationId) . '/' . ucfirst($this->openapiOperationId) . '.php');
Assert::assertFileExists(TestKernel::$bundleRootPath . '/Apis/' . $this->openapiNamespace . '/' . ucfirst($this->openapiOperationId) . '/Dto/Request/' . ucfirst($this->openapiOperationId) . 'RequestDto.php');
Assert::assertFileExists(TestKernel::$bundleRootPath . '/Apis/' . $this->openapiNamespace . '/' . ucfirst($this->openapiOperationId) . '/Dto/Request/PathParameters/PathParametersDto.php');
Assert::assertFileExists(TestKernel::$bundleRootPath . '/Apis/' . $this->openapiNamespace . '/' . ucfirst($this->openapiOperationId) . '/Dto/Response/OK/' . ucfirst($this->openapiOperationId) . 'OKDto.php');
}
}
9 changes: 5 additions & 4 deletions test/functional/Command/RefreshApiCodeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use OnMoon\OpenApiServerBundle\Command\ProcessFactory;
use OnMoon\OpenApiServerBundle\Command\RefreshApiCodeCommand;
use OnMoon\OpenApiServerBundle\Test\Functional\TestKernel;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Console\Tester\CommandTester;
Expand Down Expand Up @@ -40,7 +41,7 @@ public function testRefreshingAcceptedByUser(): void
->expects(self::atLeast(2))
->method('getProcess');

$command = new RefreshApiCodeCommand(CommandTestKernel::$bundleRootPath, $this->processFactory, self::COMMAND);
$command = new RefreshApiCodeCommand(TestKernel::$bundleRootPath, $this->processFactory, self::COMMAND);
$this->application->add($command);
$this->commandTester = new CommandTester($command);

Expand All @@ -51,7 +52,7 @@ public function testRefreshingAcceptedByUser(): void
]);

$output = $this->commandTester->getDisplay();
Assert::assertEquals(sprintf('Delete all contents of the directory %s? (y/n):', CommandTestKernel::$bundleRootPath), rtrim($output));
Assert::assertEquals(sprintf('Delete all contents of the directory %s? (y/n):', TestKernel::$bundleRootPath), rtrim($output));
Assert::assertSame(0, $this->commandTester->getStatusCode());
}

Expand All @@ -61,7 +62,7 @@ public function testRefreshingDeclinedByUser(): void
->expects(self::never())
->method('getProcess');

$command = new RefreshApiCodeCommand(CommandTestKernel::$bundleRootPath, $this->processFactory, self::COMMAND);
$command = new RefreshApiCodeCommand(TestKernel::$bundleRootPath, $this->processFactory, self::COMMAND);
$this->application->add($command);
$this->commandTester = new CommandTester($command);

Expand All @@ -72,7 +73,7 @@ public function testRefreshingDeclinedByUser(): void
]);

$output = $this->commandTester->getDisplay();
Assert::assertEquals(sprintf('Delete all contents of the directory %s? (y/n):', CommandTestKernel::$bundleRootPath), rtrim($output));
Assert::assertEquals(sprintf('Delete all contents of the directory %s? (y/n):', TestKernel::$bundleRootPath), rtrim($output));
Assert::assertSame(0, $this->commandTester->getStatusCode());
}
}
Loading

0 comments on commit 0505f41

Please sign in to comment.