Skip to content

Commit

Permalink
[php-symfony] Set required PHP version ^7.1.3 (#6181)
Browse files Browse the repository at this point in the history
* Set PHP 7.1.3 required version

I've tried to specify ^7.0 version at first, but main package which is
symfony/framework-bundle@v4.4.8 requires PHP ^7.1.3.

* Bump Symfony FrameworkBundle to ^4.4.8

Current Symfony Framework stable version is v5.0.8, but I guess it
requires significant codebase upgrade, so I've sticked with 4.4.8 which
shouldn't cause any breaking changes. Old requirement was ^3.3|^4.1
which compatible with 4.4.8.

* Bump PHPUnit version to ^7.0

PHPUnit 8.x version required PHP ^7.2, so I'm setting 7.x version to
support PHP 7.1.
There is new way to specify Kernel class, related PR:
symfony/symfony#22668

* Bump PHP CS Fixer version to ^2.16.3

Configuration and all renamed rules fixed.
Config file renamed to .php_cs.dist as recommended in migration guide.
Migration guide from 1.x to 2.x:
https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/UPGRADE.md#config-file

* Remove PHP_CodeSniffer package

Second linter doesn't make sense. I think Symfony user would prefer
PHP CS Fixer over PHP_CodeSniffer because first one maintained by Symfony
members.

* Remove satooshi/php-coveralls package from Composer

This package is abandoned and Coveralls recommends to install it directly
in Travis-CI task script.

* Update Travic-CI config

I've changed test versions to PHP 7.1.3 and 7.2. PHPUnit generates
coverage report in report/logs/clover.xml file. Then PHP CS Fixer runs
with --dry-run option to not override anything just to show coding style
errors.

* Add basic Coveralls config

This is basic recommended config for a PHP based project.

* Add symfony/yaml package

This package was part of satooshi/php-coveralls, now it should be
defined as dev dependency.

* Do not commit composer.lock

I think committed composer.lock can cause CI errors while tests on fresh
installs are better.

* Remove confusing Ruby comment
  • Loading branch information
ybelenko authored May 29, 2020
1 parent 30caeed commit 83bad10
Show file tree
Hide file tree
Showing 57 changed files with 201 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ public void processOpts() {
additionalProperties.put("escapedInvokerPackage", invokerPackage.replace("\\", "\\\\"));
additionalProperties.put("controllerPackage", controllerPackage);
additionalProperties.put("servicePackage", servicePackage);
additionalProperties.put("testsPackage", testsPackage);
additionalProperties.put("apiTestsPackage", apiTestsPackage);
additionalProperties.put("modelTestsPackage", modelTestsPackage);
additionalProperties.put("controllerTestsPackage", controllerTestsPackage);
Expand Down Expand Up @@ -349,7 +350,7 @@ public void processOpts() {
// Testing components
supportingFiles.add(new SupportingFile("testing/phpunit.xml.mustache", "", "phpunit.xml.dist"));
supportingFiles.add(new SupportingFile("testing/pom.xml", "", "pom.xml"));
supportingFiles.add(new SupportingFile("testing/AppKernel.php", toSrcPath(testsPackage, srcBasePath), "AppKernel.php"));
supportingFiles.add(new SupportingFile("testing/AppKernel.mustache", toSrcPath(testsPackage, srcBasePath), "AppKernel.php"));
supportingFiles.add(new SupportingFile("testing/ControllerTest.mustache", toSrcPath(controllerTestsPackage, srcBasePath), "ControllerTest.php"));
supportingFiles.add(new SupportingFile("testing/test_config.yml", toSrcPath(testsPackage, srcBasePath), "test_config.yml"));

Expand All @@ -360,7 +361,8 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));

supportingFiles.add(new SupportingFile(".travis.yml", "", ".travis.yml"));
supportingFiles.add(new SupportingFile(".php_cs", "", ".php_cs"));
supportingFiles.add(new SupportingFile(".php_cs.dist", "", ".php_cs.dist"));
supportingFiles.add(new SupportingFile(".coveralls.yml", "", ".coveralls.yml"));
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));

// Type-hintable primitive types
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
service_name: travis-ci # travis-ci or travis-pro

# for php-coveralls
coverage_clover: report/logs/clover.xml
json_path: report/logs/coveralls-upload.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
!bin/symfony_requirements
/vendor/

# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
composer.lock

# Assets and user uploads
/web/bundles/
/web/uploads/
Expand All @@ -51,4 +55,14 @@

# From root gitignore
/Tests/cache/
/Tests/logs/
/Tests/logs/

# PHP Coding Standards Fixer
# https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/UPGRADE.md#config-file
# From now you can create new configuration file: .php_cs.dist.
# This file is used if no .php_cs file was found.
# It is recommended to create .php_cs.dist file attached in your repository and add .php_cs file to .gitignore for allowing your contributors to have theirs own configuration file.
/.php_cs

# No reason to commit PHP CS Fixer cache files
/.php_cs.cache
18 changes: 0 additions & 18 deletions modules/openapi-generator/src/main/resources/php-symfony/.php_cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
;

return PhpCsFixer\Config::create()
->setUsingCache(true)
->setRules([
'@PSR2' => true,
'ordered_imports' => [
'sort_algorithm' => 'alpha'
],
'phpdoc_order' => true,
'array_syntax' => ['syntax' => 'short'],
'strict_comparison' => true,
'strict_param' => true
])
->setFinder($finder)
;
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
language: php
sudo: false
dist: trusty
php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm
before_install: "composer install"
script: "vendor/bin/phpunit"
- 7.1.3
- 7.2

install:
- composer install --dev --no-interaction
script:
- mkdir -p report/logs
- php vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover=report/logs/clover.xml
- php vendor/bin/php-cs-fixer fix --config=.php_cs.dist -v --dry-run --stop-on-violation --using-cache=no

before_script:
- composer require --dev php-coveralls/php-coveralls --no-interaction

after_success:
- travis_retry php vendor/bin/php-coveralls
# or enable logging
- travis_retry php vendor/bin/php-coveralls -v
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* {{bundleName}}ApiPass
*
* PHP version 5
* PHP version 7.1.3
*
* @category Class
* @package {{invokerPackage}}\DependencyInjection\Compiler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* ApiServer
*
* PHP version 5
* PHP version 7.1.3
*
* @category Class
* @package {{apiPackage}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* {{bundleClassName}}
*
* PHP version 5
* PHP version 7.1.3
*
* @category Class
* @package {{invokerPackage}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Controller
*
* PHP version 5
* PHP version 7.1.3
*
* @category Class
* @package {{controllerPackage}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* {{bundleExtensionName}}
*
* PHP version 5
* PHP version 7.1.3
*
* @category Class
* @package {{invokerPackage}}\DependencyInjection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})

## Requirements

PHP 5.4.0 and later
PHP 7.1.3 and later

## Installation & Usage

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* {{classname}}
* PHP version 5
* PHP version 7.1.3
*
* @category Class
* @package {{invokerPackage}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{{#operations}}/**
* {{controllerName}}
* PHP version 5
* PHP version 7.1.3
*
* @category Class
* @package {{controllerPackage}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,19 @@
}
],
"require": {
"php": ">=5.4",
"php": "^7.1.3",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"symfony/validator": "*",
"jms/serializer-bundle": "^2.0",
"symfony/framework-bundle": "^3.3|^4.1"
"symfony/framework-bundle": "^4.4.8"
},
"require-dev": {
"phpunit/phpunit": "~4.8",
"satooshi/php-coveralls": "~1.0",
"squizlabs/php_codesniffer": "~2.6",
"friendsofphp/php-cs-fixer": "~1.12",
"phpunit/phpunit": "^7.0",
"friendsofphp/php-cs-fixer": "^2.16.3",
"symfony/browser-kit": "*",
"symfony/yaml": "^4.4.8",
"hoa/regex": "~1.0"
},
"autoload": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/**
* {{classname}}
*
* PHP version 5
* PHP version 7.1.3
*
* @category Class
* @package {{modelPackage}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

namespace {{testsPackage}};

use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

Expand All @@ -8,7 +11,7 @@ class AppKernel extends Kernel
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle()
new FrameworkBundle()
);
return $bundles;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* ControllerTest
* PHP version 5
* PHP version 7.1.3
*
* @category Class
* @package {{controllerTestsPackage}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* {{classname}}Test
* PHP version 5
* PHP version 7.1.3
*
* @category Class
* @package {{apiTestsPackage}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/**
* {{classname}}Test
*
* PHP version 5
* PHP version 7.1.3
*
* @category Class
* @package {{modelTestsPackage}}
Expand All @@ -21,6 +21,8 @@

namespace {{modelPackage}};

use PHPUnit\Framework\TestCase;

/**
* {{classname}}Test Class Doc Comment
*
Expand All @@ -31,7 +33,7 @@ namespace {{modelPackage}};
* @author openapi-generator contributors
* @link https://github.com/openapitools/openapi-generator
*/
class {{classname}}Test extends \PHPUnit_Framework_TestCase
class {{classname}}Test extends TestCase
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
</filter>
<php>
<ini name="error_reporting" value="E_ALL" />
<server name="KERNEL_DIR" value="Tests/" />
<server name="KERNEL_CLASS" value="{{testsPackage}}\AppKernel" />
</php>
</phpunit>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
service_name: travis-ci # travis-ci or travis-pro

# for php-coveralls
coverage_clover: report/logs/clover.xml
json_path: report/logs/coveralls-upload.json
16 changes: 15 additions & 1 deletion samples/server/petstore/php-symfony/SymfonyBundle-php/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
!bin/symfony_requirements
/vendor/

# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
composer.lock

# Assets and user uploads
/web/bundles/
/web/uploads/
Expand All @@ -51,4 +55,14 @@

# From root gitignore
/Tests/cache/
/Tests/logs/
/Tests/logs/

# PHP Coding Standards Fixer
# https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/UPGRADE.md#config-file
# From now you can create new configuration file: .php_cs.dist.
# This file is used if no .php_cs file was found.
# It is recommended to create .php_cs.dist file attached in your repository and add .php_cs file to .gitignore for allowing your contributors to have theirs own configuration file.
/.php_cs

# No reason to commit PHP CS Fixer cache files
/.php_cs.cache
18 changes: 0 additions & 18 deletions samples/server/petstore/php-symfony/SymfonyBundle-php/.php_cs

This file was deleted.

20 changes: 20 additions & 0 deletions samples/server/petstore/php-symfony/SymfonyBundle-php/.php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
;

return PhpCsFixer\Config::create()
->setUsingCache(true)
->setRules([
'@PSR2' => true,
'ordered_imports' => [
'sort_algorithm' => 'alpha'
],
'phpdoc_order' => true,
'array_syntax' => ['syntax' => 'short'],
'strict_comparison' => true,
'strict_param' => true
])
->setFinder($finder)
;
Loading

0 comments on commit 83bad10

Please sign in to comment.