Skip to content

Commit

Permalink
Merge pull request #3 from bedita/feat/unit-tests
Browse files Browse the repository at this point in the history
Add unit tests
  • Loading branch information
stefanorosanelli authored Mar 29, 2022
2 parents db0abbf + e914519 commit 0b5a524
Showing 21 changed files with 2,065 additions and 57 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -12,3 +12,5 @@ trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml,neon,neon.dist}]
indent_size = 2
146 changes: 146 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
name: 'Run tests'

on:
pull_request:
paths:
- '**/*.php'
- '.github/workflows/*'
push:
paths:
- '**/*.php'
- '.github/workflows/*'

jobs:
cs:
name: 'Check coding style'
runs-on: 'ubuntu-20.04'

steps:
- name: 'Checkout current revision'
uses: 'actions/checkout@v2'

- name: 'Setup PHP'
uses: 'shivammathur/setup-php@v2'
with:
php-version: '7.4'
tools: 'composer'
extensions: 'mbstring, intl'
coverage: 'none'

- name: 'Discover Composer cache directory'
id: 'cachedir'
run: 'echo "::set-output name=path::$(composer global config cache-dir)"'

- name: 'Share Composer cache across runs'
uses: 'actions/cache@v2'
with:
path: '${{ steps.cachedir.outputs.path }}'
key: "composer-${{ github.job }}-${{ hashFiles('**/composer.json') }}"
restore-keys: |
composer-${{ github.job }}-
composer-
- name: 'Install dependencies with Composer'
run: 'composer install --prefer-dist --no-interaction'

- name: 'Run PHP CodeSniffer'
run: 'vendor/bin/phpcs -n'

stan:
name: 'Static code analyzer'
runs-on: 'ubuntu-20.04'
continue-on-error: true

steps:
- name: 'Checkout current revision'
uses: 'actions/checkout@v2'

- name: 'Setup PHP'
uses: 'shivammathur/setup-php@v2'
with:
php-version: '7.4'
tools: 'composer'
extensions: 'mbstring, intl'
coverage: 'none'

- name: 'Discover Composer cache directory'
id: 'cachedir'
run: 'echo "::set-output name=path::$(composer global config cache-dir)"'

- name: 'Share Composer cache across runs'
uses: 'actions/cache@v2'
with:
path: '${{ steps.cachedir.outputs.path }}'
key: "composer-${{ github.job }}-${{ hashFiles('**/composer.json') }}"
restore-keys: |
composer-${{ github.job }}-
composer-
- name: 'Install dependencies with Composer'
run: 'composer install --prefer-dist --no-interaction'

- name: 'Run PHP STAN'
run: 'vendor/bin/phpstan analyse --no-progress --error-format=github'

unit:
name: 'Run unit tests'
if: "!contains(github.event.commits[0].message, '[skip ci]') && !contains(github.event.commits[0].message, '[ci skip]')"
runs-on: 'ubuntu-20.04'

strategy:
fail-fast: false
matrix:
php:
- '7.2'
- '7.3'
- '7.4'

env:
PHP_VERSION: '${{ matrix.php }}'

steps:
- name: 'Checkout current revision'
uses: 'actions/checkout@v2'

- name: 'Setup PHP'
uses: 'shivammathur/setup-php@v2'
with:
php-version: '${{ matrix.php }}'
tools: 'composer'
extensions: 'mbstring, intl'
coverage: 'none' # Using `phpdbg`

- name: 'Discover Composer cache directory'
id: 'cachedir'
run: 'echo "::set-output name=path::$(composer global config cache-dir)"'

- name: 'Share Composer cache across runs'
uses: 'actions/cache@v2'
with:
path: '${{ steps.cachedir.outputs.path }}'
key: "composer-${{ matrix.php }}-${{ hashFiles('**/composer.json') }}"
restore-keys: |
composer-${{ matrix.php }}-
composer-
- name: 'Install dependencies with Composer'
run: 'composer install --prefer-dist --no-interaction'

- name: 'Dump Composer autoloader'
run: 'composer dump-autoload --classmap-authoritative --no-cache'

- name: 'Run PHPUnit'
run: 'phpdbg -qrr vendor/bin/phpunit --coverage-clover=clover.xml'

- name: 'Export coverage results'
uses: 'codecov/codecov-action@v1'
with:
file: './clover.xml'
env_vars: PHP_VERSION

- name: 'Archive code coverage results'
uses: 'actions/upload-artifact@v2'
with:
name: 'PHP ${{ matrix.php }}'
path: 'clover.xml'

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/composer.lock
/phpcs.xml
/phpstan.neon
/phpunit.xml
/vendor
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
AWS integrations plugin for BEdita 4
====================================
# AWS integrations plugin for BEdita 4
![GitHub Workflow](https://github.com/bedita/aws/actions/workflows/test.yml/badge.svg)
[![Codecov coverage](https://codecov.io/gh/bedita/aws/branch/master/graph/badge.svg)](https://codecov.io/gh/bedita/aws)

This plugin includes a few useful integrations for BEdita 4, such as:

- S3 (storage)
- SES (mailer)
- SNS (mailer, for SMS)

Installation
------------
## Installation

Run this command to add this package to your application's dependencies:

```console
$ composer require bedita/aws
```

Then, in your `Application::bootstrap()` method, add:

```php
$this->addPlugin('BEdita/AWS');
```
19 changes: 16 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -11,7 +11,10 @@
"bedita/core": "*"
},
"require-dev": {
"phpunit/phpunit": "*"
"cakephp/cakephp-codesniffer": "^3.0",
"cakephp/plugin-installer": "^1.0",
"phpunit/phpunit": "^5.7.14|^6.0",
"phpstan/phpstan": "^1.5"
},
"autoload": {
"psr-4": {
@@ -20,8 +23,18 @@
},
"autoload-dev": {
"psr-4": {
"BEdita\\AWS\\Test\\": "tests",
"Cake\\Test\\": "./vendor/cakephp/cakephp/tests"
"BEdita\\AWS\\Test\\": "tests"
}
},
"scripts": {
"cs-check": "vendor/bin/phpcs",
"cs-fix": "vendor/bin/phpcbf",
"stan": "vendor/bin/phpstan analyse",
"test": "vendor/bin/phpunit --colors=always"
},
"config": {
"allow-plugins": {
"cakephp/plugin-installer": true
}
}
}
12 changes: 12 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<ruleset name="App">
<file>./src</file>
<file>./tests</file>

<arg name="colors"/>
<arg value="p"/>

<config name="installed_paths" value="../../cakephp/cakephp-codesniffer"/>

<rule ref="CakePHP"/>
</ruleset>
8 changes: 8 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
parameters:
bootstrapFiles:
- tests/bootstrap.php
paths:
- src
- tests
level: 8
checkMissingIterableValueType: false
41 changes: 41 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ BEdita, API-first content management framework
~ Copyright 2022 Atlas Srl, Chialab Srl
~
~ This file is part of BEdita: you can redistribute it and/or modify
~ it under the terms of the GNU Lesser General Public License as published
~ by the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details.
-->

<phpunit colors="true" processIsolation="false" stopOnFailure="false" bootstrap="tests/bootstrap.php">
<php>
<ini name="memory_limit" value="-1"/>
<ini name="apc.enable_cli" value="1"/>
</php>

<!-- Add any additional test suites you want to run here -->
<testsuites>
<testsuite name="BEdita/AWS">
<directory>tests/TestCase/</directory>
</testsuite>
</testsuites>

<!-- Setup a listener for fixtures -->
<listeners>
<listener class="Cake\TestSuite\Fixture\FixtureInjector">
<arguments>
<object class="Cake\TestSuite\Fixture\FixtureManager"/>
</arguments>
</listener>
</listeners>

<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</phpunit>
14 changes: 7 additions & 7 deletions src/AwsConfigTrait.php
Original file line number Diff line number Diff line change
@@ -21,18 +21,18 @@
trait AwsConfigTrait
{
/**
* Reformat configuration preparing it for
* Reformat configuration.
*
* @param array $config Configuration.
* @return array
*/
protected function reformatConfig(array $config): array
protected function reformatCredentials(array $config): array
{
if (!empty($config['username']) && !empty($config['password'])) {
$config['credentials'] = [
'key' => $config['username'],
'secret' => $config['password'],
];
if (!empty($config['username'])) {
$config['credentials']['key'] = $config['credentials']['key'] ?? $config['username'];
}
if (!empty($config['password'])) {
$config['credentials']['secret'] = $config['credentials']['secret'] ?? $config['password'];
}

return $config;
Loading

0 comments on commit 0b5a524

Please sign in to comment.