Skip to content

Commit

Permalink
Merge pull request #1 from asgoodasnu/develop
Browse files Browse the repository at this point in the history
add ci
  • Loading branch information
aganhubert authored Sep 24, 2020
2 parents 14ab43f + 9173866 commit 2dd1fc9
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 23 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/PHPStan.yaml
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions .github/workflows/PHPUnit.yaml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions .github/workflows/php-cs-fixer.yaml
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
$finder = PhpCsFixer\Finder::create()
->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)
;
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
vendor: composer.json
@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

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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
```
Expand All @@ -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)%'
Expand All @@ -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:
```
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
5 changes: 5 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
bootstrapFiles:
- vendor/bin/.phpunit/phpunit/vendor/autoload.php
excludes_analyse:
- src/DependencyInjection/Configuration.php
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
<directory>./src</directory>
</whitelist>
</filter>
</phpunit>
</phpunit>
1 change: 0 additions & 1 deletion src/AsgoodasnewAkeneoApiBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@

class AsgoodasnewAkeneoApiBundle extends Bundle
{

}
22 changes: 16 additions & 6 deletions src/DependencyInjection/AsgoodasnewAkeneoApiExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,8 +14,10 @@

class AsgoodasnewAkeneoApiExtension extends Extension
{

public function load(array $configs, ContainerBuilder $container)
/**
* @param array<string, mixed> $configs
*/
public function load(array $configs, ContainerBuilder $container): void
{
$config = $this->handleConfigs($container, $configs);

Expand All @@ -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<string, mixed> $configs
*
* @return array<string, mixed>
*/
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<string, mixed> $config
*/
private function addArgumentsToAuthenticator(ContainerBuilder $container, array $config): void
{
$container
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/AkeneoApiAuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AkeneoApiAuthenticatorTest extends TestCase
protected $authToken;

/**
* @var HttpClientInterface|MockObject
* @var MockObject
*/
protected $client;

Expand Down
4 changes: 2 additions & 2 deletions tests/CachedSymfonyHttpClientAkeneoApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
21 changes: 15 additions & 6 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class FunctionalTest extends TestCase
{
public function testServiceWiring()
public function testServiceWiring(): void
{
$kernel = new AkeneoApiTestingKernel([
'url' => 'url',
Expand All @@ -33,23 +33,32 @@ public function testServiceWiring()

class AkeneoApiTestingKernel extends Kernel
{
/**
* @var array<string, mixed>
*/
private array $akeneoApiConfig;

/**
* @param array<string, mixed> $akeneoApiConfig
*/
public function __construct(array $akeneoApiConfig)
{
parent::__construct('test', true);

$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(
Expand All @@ -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);
}
}
}
4 changes: 2 additions & 2 deletions tests/SymfonyHttpClientAkeneoApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 2dd1fc9

Please sign in to comment.