From 60808a4257a6c285a8aab66ed5e17a54b9f7b82d Mon Sep 17 00:00:00 2001 From: martinmehm Date: Thu, 24 Sep 2020 10:26:50 +0200 Subject: [PATCH 1/4] add ci --- .github/workflows/PHPStan.yaml | 35 +++++++++++++++++++++++++++++ .github/workflows/PHPUnit.yaml | 17 ++++++++++++++ .github/workflows/php-cs-fixer.yaml | 12 ++++++++++ 3 files changed, 64 insertions(+) create mode 100644 .github/workflows/PHPStan.yaml create mode 100644 .github/workflows/PHPUnit.yaml create mode 100644 .github/workflows/php-cs-fixer.yaml diff --git a/.github/workflows/PHPStan.yaml b/.github/workflows/PHPStan.yaml new file mode 100644 index 0000000..107054e --- /dev/null +++ b/.github/workflows/PHPStan.yaml @@ -0,0 +1,35 @@ +on: [push] +name: PHPStan +jobs: + phpstan: + name: PHPStan + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + tools: pecl + extensions: gd + coverage: xdebug + + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache dependencies + uses: actions/cache@v1 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install dependencies + run: composer install --prefer-dist + + - name: Install PHPUnit dependencies + run: vendor/bin/simple-phpunit --help + + - name: PHPStan + run: | + vendor/bin/phpstan analyse src/ tests/ --level 7 diff --git a/.github/workflows/PHPUnit.yaml b/.github/workflows/PHPUnit.yaml new file mode 100644 index 0000000..06a59e4 --- /dev/null +++ b/.github/workflows/PHPUnit.yaml @@ -0,0 +1,17 @@ +on: [push] +name: PHPUnit +jobs: + PHPUnit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + tools: pecl + extensions: amqp + coverage: xdebug + - uses: php-actions/composer@v1 + - name: PHPUnit + run: | + make test-coverage diff --git a/.github/workflows/php-cs-fixer.yaml b/.github/workflows/php-cs-fixer.yaml new file mode 100644 index 0000000..d16885d --- /dev/null +++ b/.github/workflows/php-cs-fixer.yaml @@ -0,0 +1,12 @@ +on: [push] +name: PHP-CS-Fixer +jobs: + php-cs-fixer: + name: PHP-CS-Fixer + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: PHP-CS-Fixer + uses: docker://oskarstark/php-cs-fixer-ga + with: + args: --config=.php_cs.dist --diff --dry-run From 9b8512e6f065ceaa46824f1a1ad2da43e0e810dc Mon Sep 17 00:00:00 2001 From: martinmehm Date: Thu, 24 Sep 2020 10:30:49 +0200 Subject: [PATCH 2/4] add ci --- .php_cs.dist | 25 +++++++++++++++++++++++++ Makefile | 27 +++++++++++++++++++++++++++ phpstan.neon.dist | 9 +++++++++ phpunit.xml.dist | 2 +- 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 .php_cs.dist create mode 100644 Makefile create mode 100644 phpstan.neon.dist diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 0000000..9a32943 --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,25 @@ +in('src') + ->in('tests') + ->notPath('src/Migrations/migration.tpl') +; +return PhpCsFixer\Config::create() + ->setRiskyAllowed(true) + ->setRules([ + '@Symfony' => true, + 'ordered_imports' => true, + 'no_unused_imports' => true, + 'psr4' => true, + 'psr0' => true, + 'array_syntax' => ['syntax' => 'short'], + 'no_superfluous_phpdoc_tags' => true, + 'linebreak_after_opening_tag' => true, + 'logical_operators' => true, + 'native_function_invocation' => [ + 'include' => ['@compiler_optimized'], + 'scope' => 'namespaced' + ] + ]) + ->setFinder($finder) +; diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3a1faa6 --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +# vim: set tabstop=8 softtabstop=8 noexpandtab: + +DATE := $(shell date +%Y-%m-%d_%H-%M-%S) + +vendor: composer.json composer.lock + @composer install --no-interaction + +cs: + # Running PHP-CS-Fixer + @php vendor/bin/php-cs-fixer fix + +analyse: + # Running PHPStan static code analyse + @php vendor/bin/phpstan analyse src/ tests/ --level 7 + +lint-twig: + # Linting Twig files + @symfony php bin/console lint:twig templates/ + +lint-yaml: + # Linting YAML files + @symfony php bin/console lint:yaml config/ src/ translations/ --parse-tags + +test-coverage: + @php vendor/bin/simple-phpunit -v --coverage-clover clover-coverage.xml --coverage-html coverage_html --log-junit coverage_html/junit.xml + +all: cs analyse test-coverage diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..184c999 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,9 @@ +parameters: + bootstrapFiles: + - vendor/bin/.phpunit/phpunit-8.3-0/vendor/autoload.php + excludes_analyse: + - tests/bootstrap.php + - src/Migrations + - src/Tests/Behat + - tests/Tests/Behat + - src/Configuration/AppConfiguration.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index ebcfcbf..3aecab9 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -21,4 +21,4 @@ ./src - \ No newline at end of file + From d51865b26a8a6488e86c2983652604b44dc7e493 Mon Sep 17 00:00:00 2001 From: martinmehm Date: Thu, 24 Sep 2020 10:37:17 +0200 Subject: [PATCH 3/4] change name --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4cc973d..d1b842c 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Add this to composer.json "repositories": [ { "type": "vcs", - "url": "git@github.com:asgoodasnu/akene-api-bundle.git" + "url": "git@github.com:asgoodasnu/akeneo-api-bundle.git" } ] ``` @@ -16,7 +16,7 @@ composer require asgoodasnu/akeneo-api-bundle:*@dev ``` (maybe you get an exception, because the configuration is missing.) -Now add a configuration file in config/packages&/akeneo_api.yaml +Now add a configuration file in config/packages/akeneo_api.yaml ``` asgoodasnew_akeneo_api: url: '%env(AKENEO_API_URL)%' @@ -25,7 +25,7 @@ asgoodasnew_akeneo_api: token: '%env(AKENEO_AUTH_TOKEN)%' cached: false ``` -If cached is set to true, +If cached is set to true, results will be cached for 60 minutes Add environment variables or add the values to the .env file: ``` From 91738666511c303f5a39ef2a9279ea7ea85f086a Mon Sep 17 00:00:00 2001 From: martinmehm Date: Thu, 24 Sep 2020 10:59:20 +0200 Subject: [PATCH 4/4] add ci and fix tests & code --- Makefile | 16 ++------------ composer.json | 4 +++- phpstan.neon.dist | 8 ++----- src/AsgoodasnewAkeneoApiBundle.php | 1 - .../AsgoodasnewAkeneoApiExtension.php | 22 ++++++++++++++----- tests/AkeneoApiAuthenticatorTest.php | 2 +- .../CachedSymfonyHttpClientAkeneoApiTest.php | 4 ++-- tests/FunctionalTest.php | 21 +++++++++++++----- tests/SymfonyHttpClientAkeneoApiTest.php | 4 ++-- 9 files changed, 43 insertions(+), 39 deletions(-) diff --git a/Makefile b/Makefile index 3a1faa6..4692826 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,4 @@ -# vim: set tabstop=8 softtabstop=8 noexpandtab: - -DATE := $(shell date +%Y-%m-%d_%H-%M-%S) - -vendor: composer.json composer.lock +vendor: composer.json @composer install --no-interaction cs: @@ -12,15 +8,7 @@ cs: analyse: # Running PHPStan static code analyse @php vendor/bin/phpstan analyse src/ tests/ --level 7 - -lint-twig: - # Linting Twig files - @symfony php bin/console lint:twig templates/ - -lint-yaml: - # Linting YAML files - @symfony php bin/console lint:yaml config/ src/ translations/ --parse-tags - + test-coverage: @php vendor/bin/simple-phpunit -v --coverage-clover clover-coverage.xml --coverage-html coverage_html --log-junit coverage_html/junit.xml diff --git a/composer.json b/composer.json index 9d838eb..f1ccf78 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,8 @@ } }, "require-dev": { - "symfony/phpunit-bridge": "^5.1" + "symfony/phpunit-bridge": "^5.1", + "phpstan/phpstan": "^0.12.42", + "friendsofphp/php-cs-fixer": "^2.16" } } diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 184c999..fed3239 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,9 +1,5 @@ parameters: bootstrapFiles: - - vendor/bin/.phpunit/phpunit-8.3-0/vendor/autoload.php + - vendor/bin/.phpunit/phpunit/vendor/autoload.php excludes_analyse: - - tests/bootstrap.php - - src/Migrations - - src/Tests/Behat - - tests/Tests/Behat - - src/Configuration/AppConfiguration.php + - src/DependencyInjection/Configuration.php diff --git a/src/AsgoodasnewAkeneoApiBundle.php b/src/AsgoodasnewAkeneoApiBundle.php index 2ed4be9..07ab9ee 100644 --- a/src/AsgoodasnewAkeneoApiBundle.php +++ b/src/AsgoodasnewAkeneoApiBundle.php @@ -8,5 +8,4 @@ class AsgoodasnewAkeneoApiBundle extends Bundle { - } diff --git a/src/DependencyInjection/AsgoodasnewAkeneoApiExtension.php b/src/DependencyInjection/AsgoodasnewAkeneoApiExtension.php index 26d7e53..22b1306 100644 --- a/src/DependencyInjection/AsgoodasnewAkeneoApiExtension.php +++ b/src/DependencyInjection/AsgoodasnewAkeneoApiExtension.php @@ -6,7 +6,6 @@ use Asgoodasnew\AkeneoApiBundle\CachedSymfonyHttpClientAkeneoApi; use Symfony\Component\Config\FileLocator; -use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Extension\Extension; @@ -15,8 +14,10 @@ class AsgoodasnewAkeneoApiExtension extends Extension { - - public function load(array $configs, ContainerBuilder $container) + /** + * @param array $configs + */ + public function load(array $configs, ContainerBuilder $container): void { $config = $this->handleConfigs($container, $configs); @@ -40,20 +41,29 @@ private function addDecorator(ContainerBuilder $container): void $decorated->setArgument(1, new Reference('Psr\Cache\CacheItemPoolInterface')); $container->addDefinitions([ - 'asgoodasnew_akeneo_api.cached_symfony_http_client_akeneo_api' => $decorated + 'asgoodasnew_akeneo_api.cached_symfony_http_client_akeneo_api' => $decorated, ]); } + /** + * @param array $configs + * + * @return array + */ private function handleConfigs(ContainerBuilder $container, array $configs): array { - $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); + $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.xml'); $configuration = $this->getConfiguration($configs, $container); $config = $this->processConfiguration($configuration, $configs); + return $config; } + /** + * @param array $config + */ private function addArgumentsToAuthenticator(ContainerBuilder $container, array $config): void { $container @@ -64,7 +74,7 @@ private function addArgumentsToAuthenticator(ContainerBuilder $container, array ->setArgument(3, $config['token']); } - private function addArgumentsToSymfonyHttpClient(ContainerBuilder $container, $url): void + private function addArgumentsToSymfonyHttpClient(ContainerBuilder $container, string $url): void { $container->getDefinition('asgoodasnew_akeneo_api.symfony_http_client_akeneo_api') ->setArgument(0, $url); diff --git a/tests/AkeneoApiAuthenticatorTest.php b/tests/AkeneoApiAuthenticatorTest.php index 75af1f9..c150390 100644 --- a/tests/AkeneoApiAuthenticatorTest.php +++ b/tests/AkeneoApiAuthenticatorTest.php @@ -38,7 +38,7 @@ class AkeneoApiAuthenticatorTest extends TestCase protected $authToken; /** - * @var HttpClientInterface|MockObject + * @var MockObject */ protected $client; diff --git a/tests/CachedSymfonyHttpClientAkeneoApiTest.php b/tests/CachedSymfonyHttpClientAkeneoApiTest.php index 45ceaa8..0faa93a 100644 --- a/tests/CachedSymfonyHttpClientAkeneoApiTest.php +++ b/tests/CachedSymfonyHttpClientAkeneoApiTest.php @@ -22,12 +22,12 @@ class CachedSymfonyHttpClientAkeneoApiTest extends TestCase protected CachedSymfonyHttpClientAkeneoApi $cachedSymfonyHttpClientAkeneoApi; /** - * @var AkeneoApi|MockObject + * @var MockObject */ protected $decorated; /** - * @var CacheItemPoolInterface|MockObject + * @var MockObject */ protected $cache; diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index 6f1243b..d29a184 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -11,7 +11,7 @@ class FunctionalTest extends TestCase { - public function testServiceWiring() + public function testServiceWiring(): void { $kernel = new AkeneoApiTestingKernel([ 'url' => 'url', @@ -33,8 +33,14 @@ public function testServiceWiring() class AkeneoApiTestingKernel extends Kernel { + /** + * @var array + */ private array $akeneoApiConfig; + /** + * @param array $akeneoApiConfig + */ public function __construct(array $akeneoApiConfig) { parent::__construct('test', true); @@ -42,14 +48,17 @@ public function __construct(array $akeneoApiConfig) $this->akeneoApiConfig = $akeneoApiConfig; } - public function registerBundles() + /** + * @return AsgoodasnewAkeneoApiBundle[] + */ + public function registerBundles(): array { return [ new AsgoodasnewAkeneoApiBundle(), ]; } - public function registerContainerConfiguration(LoaderInterface $loader) + public function registerContainerConfiguration(LoaderInterface $loader): void { $loader->load(function (ContainerBuilder $containerBuilder) { $containerBuilder->register( @@ -61,8 +70,8 @@ public function registerContainerConfiguration(LoaderInterface $loader) }); } - public function getCacheDir() + public function getCacheDir(): string { - return __DIR__ . '/../var/' . spl_object_hash($this); + return __DIR__.'/../var/'.spl_object_hash($this); } -} \ No newline at end of file +} diff --git a/tests/SymfonyHttpClientAkeneoApiTest.php b/tests/SymfonyHttpClientAkeneoApiTest.php index e3c5f3a..99a9521 100644 --- a/tests/SymfonyHttpClientAkeneoApiTest.php +++ b/tests/SymfonyHttpClientAkeneoApiTest.php @@ -18,12 +18,12 @@ class SymfonyHttpClientAkeneoApiTest extends TestCase protected string $baseUrl; /** - * @var HttpClientInterface|MockObject + * @var MockObject */ protected $client; /** - * @var AkeneoApiAuthenticator|MockObject + * @var MockObject */ protected $akeneoApiAuthenticator;