Skip to content

Commit

Permalink
refactor: use test setup from 'Leitfaden' (#12)
Browse files Browse the repository at this point in the history
* refactor: use test setup from 'Leitfaden'

* ci: fix php code style

* ci: fix tests in GitHub actions

* ci: fix tests in GitHub actions 02

* ci: fix tests in GitHub actions 03

* clean: small typo and missing directory in .gitattributes
  • Loading branch information
lukadschaak committed Jul 20, 2023
1 parent 2e62425 commit dc585b6
Show file tree
Hide file tree
Showing 33 changed files with 152 additions and 746 deletions.
8 changes: 4 additions & 4 deletions .editorconfig
Expand Up @@ -8,11 +8,11 @@ indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.yaml]
[*.{json,yaml,yml}]
indent_size = 2

[*.neon]
indent_style = tab

[*.md]
trim_trailing_whitespace = false

[*.neon]
indent_style = tab
13 changes: 6 additions & 7 deletions .gitattributes
@@ -1,12 +1,11 @@
/docs/* export-ignore
/.github export-ignore
/.gitattributes export-ignore
/.github/ export-ignore
/.gitignore export-ignore
/.php-cs-fixer.php export-ignore
/docker-compose.yaml export-ignore
/phpstan.neon export-ignore
/bin/ export-ignore
/compose.yaml export-ignore
/docs/ export-ignore
/phpstan-baseline.neon export-ignore
/phpstan.neon export-ignore
/phpunit.xml.dist export-ignore
/run-tests.sh export-ignore
/tests export-ignore
/wait-for-it.sh export-ignore
/tests/ export-ignore
7 changes: 4 additions & 3 deletions .github/workflows/test-and-qa.yaml
Expand Up @@ -44,8 +44,8 @@ jobs:
db:
image: mariadb:10.10.2
env:
MYSQL_ROOT_PASSWORD: 'pimcore'
MYSQL_DATABASE: 'pimcore_test'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_DATABASE: 'pimcore'
MYSQL_USER: 'pimcore'
MYSQL_PASSWORD: 'pimcore'
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
Expand All @@ -71,5 +71,6 @@ jobs:
- name: Execute tests (Unit and Feature tests) via PHPUnit
run: composer tests
env:
DB_URL: 'mysql://pimcore:pimcore@127.0.0.1:3306/pimcore_test?serverVersion=mariadb-10.10.2'
MYSQL_HOST: '127.0.0.1'
MYSQL_SERVER_VERSION: 'mariadb-10.11.4'

2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -7,3 +7,5 @@

# PHPUnit
.phpunit.result.cache
/reports/
/.phpunit.cache/
12 changes: 10 additions & 2 deletions .php-cs-fixer.php
Expand Up @@ -12,20 +12,28 @@
__DIR__ . '/src',
__DIR__ . '/tests',
])
->notPath('DependencyInjection/Configuration.php')
->notPath(['DependencyInjection/Configuration.php', 'app/var'])
)
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,

// declare strict types must be on first line after opening tag
'blank_line_after_opening_tag' => false, // overwrite @Symfony
'linebreak_after_opening_tag' => false, // overwrite @Symfony
'declare_strict_types' => true, // custom

// allow throw's in multiple lines, so message can be a long string
'single_line_throw' => false, // overwrite @Symfony

// we want spaces
'concat_space' => ['spacing' => 'one'],

// allow both styles
// we want to leave the choice to the developer,
// because some people have their own style of naming test methods
'php_unit_method_casing' => false,

// we want to leave the choice to the developer
'php_unit_test_annotation' => false,
]);
45 changes: 21 additions & 24 deletions README.md
Expand Up @@ -10,21 +10,19 @@ This bundle reads standard symfony translation files and migrates them to Pimcor

## Installation

Require via Composer
1. **Require the bundle**

```shell
composer require teamneusta/pimcore-translation-migration-bundle
```
```shell script
composer require teamneusta/pimcore-translation-migration-bundle
```

Enable the bundle via the [Symfony Bundle System](https://symfony.com/doc/current/bundles.html).
2. **Enable the bundle**

```php
// config/bundles.php
return [
...
Neusta\Pimcore\TranslationMigrationBundle\NeustaPimcoreTranslationMigrationBundle::class => ['all' => true],
];
```
Add the Translation Migration Bundle to your `config/bundles.php`:

```php
Neusta\Pimcore\TranslationMigrationBundle\NeustaPimcoreTranslationMigrationBundle::class => ['all' => true],
```

## Usage

Expand All @@ -46,24 +44,23 @@ Feel free to open issues for any bug, feature request, or other ideas.

Please remember to create an issue before creating large pull requests.

### Running tests for development
### Local Development

To develop on local machine, the vendor dependencies are required.

```shell
./run-tests.sh
bin/composer install
```

Only supported on Linux.
We use composer scripts for our main quality tools. They can be executed via the `bin/composer` file as well.

### Further development

Pipelines will tell you, when code does not meet our standards. To use the same tools in local development, take the Docker command from above with other scripts from the `composer.json`. For example:
```shell
bin/composer cs:fix
bin/composer phpstan
```

* cs:check
* phpstan
For the tests there is a different script, that includes a database setup.

```shell
docker run -it --rm -v $(pwd):/app -w /app pimcore/pimcore:PHP8.1-cli composer install --ignore-platform-reqs
docker run -it --rm -v $(pwd):/app -w /app pimcore/pimcore:PHP8.1-cli composer <composer-script>
bin/run-tests
```

Only supported on Linux.
3 changes: 3 additions & 0 deletions bin/composer
@@ -0,0 +1,3 @@
#!/bin/sh

exec docker compose run --rm --user "$(id -u):$(id -g)" --no-deps php composer "$@"
4 changes: 4 additions & 0 deletions bin/run-tests
@@ -0,0 +1,4 @@
#!/bin/sh

docker compose run --rm --user "$(id -u):$(id -g)" php composer tests
docker compose down
26 changes: 26 additions & 0 deletions compose.yaml
@@ -0,0 +1,26 @@
services:
database:
image: mariadb:10.11.4
command: ["mysqld", "--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci"]
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: pimcore
MYSQL_PASSWORD: pimcore
MYSQL_USER: pimcore
tmpfs:
- /tmp/
- /var/lib/mysql/
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
interval: 5s
timeout: 10s

php:
image: pimcore/pimcore:php8.1-v1.3
volumes:
- ./:/var/www/html/
environment:
MYSQL_SERVER_VERSION: mariadb-10.11.4
depends_on:
database:
condition: service_healthy
40 changes: 24 additions & 16 deletions composer.json
Expand Up @@ -11,23 +11,31 @@
"role": "Developer"
}
],
"config": {
"sort-packages": true,
"allow-plugins": {
"phpstan/extension-installer": true
}
},
"require": {
"php": "^8.0",
"pimcore/pimcore": "^10.0",
"symfony/console": "^5.4",
"symfony/finder": "^5.4",
"symfony/framework-bundle": "^5.0|^6.0",
"symfony/yaml": "^5.0|^6.0"
"symfony/console": "^5.4 || ^6.0",
"symfony/finder": "^5.4 || ^6.0",
"symfony/framework-bundle": "^5.0 || ^6.0",
"symfony/yaml": "^5.0 || ^6.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.11",
"phpspec/prophecy": "^1.11",
"phpspec/prophecy-phpunit": "^2.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.9",
"phpstan/phpstan-symfony": "^1.2",
"phpunit/phpunit": "^9.5",
"spatie/phpunit-snapshot-assertions": "^4.2",
"symfony/filesystem": "^5.4",
"friendsofphp/php-cs-fixer": "^3.11",
"phpstan/phpstan": "^1.8",
"phpstan/phpstan-phpunit": "^1.1",
"phpstan/phpstan-symfony": "^1.2"
"teamneusta/pimcore-testing-framework": "^0.11.0"
},
"autoload": {
"psr-4": {
Expand All @@ -36,24 +44,24 @@
},
"autoload-dev": {
"psr-4": {
"Neusta\\Pimcore\\TranslationMigrationBundle\\Tests\\Functional\\": "tests/functional/",
"Neusta\\Pimcore\\TranslationMigrationBundle\\Tests\\Unit\\": "tests/unit/"
"Neusta\\Pimcore\\TranslationMigrationBundle\\Tests\\": "tests/"
},
"classmap": [
"tests/app/TestKernel.php"
]
},
"scripts": {
"cs:check": "php-cs-fixer fix -v --diff --dry-run",
"cs:fix": "php-cs-fixer fix -v --diff",
"phpstan": "phpstan analyse --level=${PHPSTAN_LEVEL:-8} -c phpstan.neon",
"phpstan:baseline": "phpstan analyse --level=${PHPSTAN_LEVEL:-8} -c phpstan.neon --generate-baseline",
"cs:check": "@cs:fix --dry-run",
"cs:fix": "php-cs-fixer fix --ansi --verbose --diff",
"phpstan": "phpstan analyse --ansi --no-interaction",
"phpstan:baseline": "phpstan analyse --generate-baseline",
"tests": "phpunit"
},
"scripts-descriptions": {
"cs:check": "Checks code style (but doesn't fix anything)",
"cs:fix": "Checks and fixes code style",
"phpstan": "Checks code against phpstan rules",
"tests": "runs all the phpunit tests"
"phpstan": "Checks for code smells",
"phpstan:baseline": "Creates a baseline for phpstan",
"tests": "Run all phpunit tests"
}
}
19 changes: 0 additions & 19 deletions docker-compose.yaml

This file was deleted.

6 changes: 3 additions & 3 deletions phpstan-baseline.neon
@@ -1,17 +1,17 @@
parameters:
ignoreErrors:
-
message: "#^Argument of an invalid type array\\|bool\\|float\\|int\\|string\\|UnitEnum\\|null supplied for foreach, only iterables are supported\\.$#"
message: "#^Argument of an invalid type array\\|bool\\|float\\|int\\|string\\|null supplied for foreach, only iterables are supported\\.$#"
count: 1
path: src/DependencyInjection/NeustaPimcoreTranslationMigrationExtension.php

-
message: "#^Binary operation \"\\.\" between array\\|bool\\|float\\|int\\|string\\|UnitEnum\\|null and '/Resources…' results in an error\\.$#"
message: "#^Binary operation \"\\.\" between array\\|bool\\|float\\|int\\|string\\|null and '/Resources…' results in an error\\.$#"
count: 1
path: src/DependencyInjection/NeustaPimcoreTranslationMigrationExtension.php

-
message: "#^Binary operation \"\\.\" between array\\|bool\\|float\\|int\\|string\\|UnitEnum\\|null and '/translations' results in an error\\.$#"
message: "#^Binary operation \"\\.\" between array\\|bool\\|float\\|int\\|string\\|null and '/translations' results in an error\\.$#"
count: 1
path: src/DependencyInjection/NeustaPimcoreTranslationMigrationExtension.php

Expand Down
15 changes: 9 additions & 6 deletions phpstan.neon
@@ -1,11 +1,14 @@
includes:
- phpstan-baseline.neon
- phpstan-baseline.neon

parameters:
paths:
- src

bootstrapFiles:
- vendor/pimcore/pimcore/stubs/dynamic-constants.php
level: 8

checkGenericClassInNonGenericObjectType: false
paths:
- src

bootstrapFiles:
- vendor/pimcore/pimcore/stubs/dynamic-constants.php

checkGenericClassInNonGenericObjectType: false
34 changes: 18 additions & 16 deletions phpunit.xml.dist
@@ -1,27 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="tests/bootstrap.php"
failOnRisky="true"
failOnWarning="true">

<coverage>
<include>
<directory>./src</directory>
</include>
</coverage>

<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="tests/bootstrap.php"
cacheResultFile=".phpunit.cache/test-results"
colors="true"
failOnRisky="true"
failOnWarning="true"
>
<php>
<ini name="display_startup_errors" value="On"/>
<ini name="display_errors" value="On"/>
<ini name="error_reporting" value="-1"/>
<ini name="memory_limit" value="-1" />
</php>

<testsuites>
<testsuite name="tests">
<testsuite name="All tests">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<coverage cacheDirectory=".phpunit.cache/code-coverage" processUncoveredFiles="true">
<include>
<directory>./src</directory>
</include>
</coverage>
</phpunit>
7 changes: 0 additions & 7 deletions run-tests.sh

This file was deleted.

0 comments on commit dc585b6

Please sign in to comment.