Skip to content

Commit

Permalink
Feature/add testing (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdambacher authored Oct 20, 2022
1 parent 83be010 commit 0052cb4
Show file tree
Hide file tree
Showing 22 changed files with 4,110 additions and 28 deletions.
6 changes: 6 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# define your env variables for the test env here
KERNEL_CLASS='App\Kernel'
APP_SECRET='$ecretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_APP_ENV=panther
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots
9 changes: 9 additions & 0 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Build Docker Image
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build the Docker image
run: docker build . --file Dockerfile --tag ${{ github.repository }}:$(date +%s)
68 changes: 68 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Linting
on: [push]
jobs:
php-cs-fixer:
runs-on: ubuntu-latest
steps:
- uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
- uses: actions/checkout@v2
- name: Copy .env.test.local
run: php -r "file_exists('.env.test.local') || copy('.env.test', '.env.test.local');"
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Run PHP CS Fixer
run: vendor/bin/php-cs-fixer fix --dry-run

phpstan:
runs-on: ubuntu-latest
steps:
- uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
- uses: actions/checkout@v2
- name: Copy .env.test.local
run: php -r "file_exists('.env.test.local') || copy('.env.test', '.env.test.local');"
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Run phpstan
run: vendor/bin/phpstan analyse

psalm:
runs-on: ubuntu-latest
steps:
- uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
- uses: actions/checkout@v2
- name: Copy .env.test.local
run: php -r "file_exists('.env.test.local') || copy('.env.test', '.env.test.local');"
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Run Psalm
run: vendor/bin/psalm --show-info=false
42 changes: 42 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Tests
on: [push]
jobs:
phpunit:
runs-on: ubuntu-latest
steps:
- uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
- uses: actions/checkout@v2
- name: Copy .env.test.local
run: php -r "file_exists('.env.test.local') || copy('.env.test', '.env.test.local');"
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Execute tests (Unit and Feature tests) via PHPUnit
run: php -dpcov.enabled=1 -dpcov.directory=. ./vendor/bin/phpunit -c phpunit.xml.dist --coverage-html coverage --coverage-text --colors=always --coverage-cobertura=./cobertura-coverage.xml
- name: Code Coverage Report
uses: irongut/CodeCoverageSummary@v1.3.0
with:
filename: ./cobertura-coverage.xml
badge: true
fail_below_min: true
format: markdown
hide_branch_rate: false
hide_complexity: true
indicators: true
output: both
thresholds: '75 90'
- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
recreate: true
path: code-coverage-results.md
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,21 @@
###< symfony/framework-bundle ###

/.idea/

# Coverage
/coverage/

###> phpunit/phpunit ###
/phpunit.xml
.phpunit.result.cache
###< phpunit/phpunit ###

###> friendsofphp/php-cs-fixer ###
/.php-cs-fixer.php
/.php-cs-fixer.cache
###< friendsofphp/php-cs-fixer ###

###> symfony/phpunit-bridge ###
.phpunit.result.cache
/phpunit.xml
###< symfony/phpunit-bridge ###
46 changes: 46 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

use PhpCsFixer\Config;

$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/src');

return (new Config())
->setFinder($finder)
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'@PHP70Migration' => true,
'@PHP70Migration:risky' => true,
'@PHP71Migration' => true,
'@PHP71Migration:risky' => true,
'@PhpCsFixer' => true,
'@PhpCsFixer:risky' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'@DoctrineAnnotation' => true,
'list_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => [
'operators' => [
'=' => 'align',
'=>' => 'align',
'+=' => 'align',
'-=' => 'align',
'*=' => 'align',
'%=' => 'align',
'.=' => 'align',
'^=' => 'align',
],
],
'yoda_style' => false,
'class_definition' => [
'single_line' => false,
],
'native_function_invocation' => true,
'native_function_casing' => true,
'native_constant_invocation' => true,
'object_operator_without_whitespace' => false,
'multiline_whitespace_before_semicolons' => [
'strategy' => 'no_multi_line',
]
]);
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.1] - 2022-10-20
### Added
- Added PHPUnit tests

### Fixed
- Fixed a bug where a zero patch version would deliver the latest patch version

## [1.1.0] - 2022-10-20
### Added
- Get the latest version of a partial version string (e.g. get version `6.4.15.2` if you request version `6.4.15`)
Expand All @@ -15,5 +22,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Controller for getting install urls for specific Shopware 6 versions or the latest version

[1.1.1]: https://github.com/jdambacher/shopware-versions/compare/1.1.0...1.1.1
[1.1.0]: https://github.com/jdambacher/shopware-versions/compare/1.0.0...1.1.0
[1.0.0]: https://github.com/jdambacher/shopware-versions/releases/tag/1.0.0
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local
COPY ./apache.conf /etc/apache2/sites-enabled/000-default.conf
COPY ./ /var/www/html

RUN composer install --no-scripts --optimize-autoloader
RUN composer install --no-scripts --optimize-autoloader --no-dev

###> recipes ###
### recipes ###

WORKDIR /var/www/html
CMD ["apache2-foreground"]

CMD ["apache2-foreground"]
19 changes: 19 additions & 0 deletions bin/phpunit
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env php
<?php

if (!ini_get('date.timezone')) {
ini_set('date.timezone', 'UTC');
}

if (is_file(dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit')) {
define('PHPUNIT_COMPOSER_INSTALL', dirname(__DIR__).'/vendor/autoload.php');
require PHPUNIT_COMPOSER_INSTALL;
PHPUnit\TextUI\Command::main();
} else {
if (!is_file(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php')) {
echo "Unable to find the `simple-phpunit.php` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
exit(1);
}

require dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php';
}
9 changes: 9 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,14 @@
"allow-contrib": false,
"require": "6.1.*"
}
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.12",
"phpstan/phpstan": "^1.8",
"phpunit/phpunit": "^9.5",
"symfony/browser-kit": "6.1.*",
"symfony/maker-bundle": "^1.47",
"symfony/phpunit-bridge": "^6.1",
"vimeo/psalm": "^4.29"
}
}
Loading

0 comments on commit 0052cb4

Please sign in to comment.