Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update bundle structure to latest version #7

Merged
merged 6 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

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

[*.md]
indent_size = 2
trim_trailing_whitespace = false

[*.neon]
indent_style = tab
Empty file added .env
Empty file.
21 changes: 16 additions & 5 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
/.* export-ignore
/tests export-ignore
/phpunit.xml.dist export-ignore
/psalm.xml.dist export-ignore
/README.md export-ignore
/.editorconfig export-ignore
/.env export-ignore
/.gitattributes export-ignore
/.github/ export-ignore
/.gitignore export-ignore
/.gitlab-ci.yml export-ignore
/.gitlab-ci/ export-ignore
/.php-cs-fixer.php 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
/sonar-project.properties export-ignore
/tests/ export-ignore
36 changes: 36 additions & 0 deletions .github/workflows/qa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Quality Assurance

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
qa:
name: Quality Checks
runs-on: ubuntu-latest

steps:
- name: Git Checkout
uses: actions/checkout@v4

- name: PHP Setup
uses: shivammathur/setup-php@v2
with:
php-version: 8.2

- name: Validate composer.json
run: composer validate --strict

- name: Install dependencies
uses: ramsey/composer-install@v2

- name: Check CS-Fixer
run: composer cs:check

- name: Check PHPStan
run: composer phpstan
43 changes: 43 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Tests

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
tests:
name: PHPUnit with PHP ${{ matrix.php-version }} ${{ matrix.dependencies }}
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
include:
- php-version: "8.1"
dependencies: "lowest"
- php-version: "8.1"
dependencies: "highest"
- php-version: "8.2"
dependencies: "highest"

steps:
- name: Git Checkout
uses: actions/checkout@v4

- name: PHP Setup
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}

- name: Install dependencies
uses: ramsey/composer-install@v2
with:
dependency-versions: ${{ matrix.dependencies }}

- name: Execute tests
run: composer tests
12 changes: 9 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@
/composer.lock
/vendor/

# Docker Compose
/compose.override.yaml

# PHP-CS-Fixer
/php-cs-fixer.cache
/.php-cs-fixer.cache

# PHPUnit
/.phpunit.result.cache
/.phpunit.cache/
/reports/

# Psalm
/.psalm.cache
# Optionally, ignore project files for common IDE
# A better alternative would be to globally ignore configuration files of your preferred IDE (see: https://stackoverflow.com/a/7335487)
#/.idea/
104 changes: 31 additions & 73 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -1,81 +1,39 @@
<?php

/*
* This document has been initially generated with
* https://mlocati.github.io/php-cs-fixer-configurator/#version:3.5.0|configurator
* and then adapted to our needs
*/

return (new PhpCsFixer\Config)
->setFinder((new PhpCsFixer\Finder)->in([
__DIR__.'/src',
__DIR__.'/tests',
]))
->setFinder((new PhpCsFixer\Finder)
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->notPath(['DependencyInjection/Configuration.php', 'app/var'])
)
->setRiskyAllowed(true)
->setRules([
// See: https://mlocati.github.io/php-cs-fixer-configurator
'@PHP74Migration' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'@DoctrineAnnotation' => true,
'@PHPUnit84Migration:risky' => true,
'array_push' => true,
'class_attributes_separation' => ['elements' => ['method' => 'one']],
'class_definition' => ['single_item_single_line' => true],
'combine_consecutive_unsets' => true,
'declare_strict_types' => true,
'echo_tag_syntax' => ['format' => 'long'],
'heredoc_indentation' => ['indentation' => 'same_as_start'],
'heredoc_to_nowdoc' => true,
'linebreak_after_opening_tag' => true,
'mb_str_functions' => true,
'method_chaining_indentation' => true,
'native_constant_invocation' => [
'fix_built_in' => false,
'include' => [
'DIRECTORY_SEPARATOR',
'PHP_INT_SIZE',
'PHP_SAPI',
'PHP_VERSION_ID',
],
'scope' => 'namespaced',
'strict' => true,
],
'native_function_invocation' => [
'include' => [
'@compiler_optimized',
],
'scope' => 'namespaced',
'strict' => true,
],
'new_with_braces' => false,
'no_extra_blank_lines' => [
'tokens' => [
'break',
'continue',
'extra',
'return',
'throw',
'use',
'parenthesis_brace_block',
'square_brace_block',
'curly_brace_block',
],
],
'no_null_property_initialization' => true,
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true, 'remove_inheritdoc' => true],
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_class_elements' => true,
'ordered_traits' => false,
'php_unit_method_casing' => false,
'php_unit_strict' => false,
'php_unit_test_annotation' => ['style' => 'annotation'],
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
'php_unit_test_class_requires_covers' => false,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_order' => true,
'phpdoc_summary' => false,
'return_assignment' => true,
'simple_to_complex_string_variable' => true,
'simplified_if_return' => true,
'single_line_throw' => false,
'strict_comparison' => true,
'strict_param' => true,
'visibility_required' => ['elements' => ['property', 'method', 'const']],

// 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'], // overwrite @Symfony

// 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, // overwrite @Symfony

// we want to leave the choice to the developer
'php_unit_test_annotation' => false, // overwrite @Symfony:risky
]);
31 changes: 25 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ Provides tools for Pimcore unit/integration testing with PHPUnit.

## Installation

```shell
composer require --dev teamneusta/pimcore-testing-framework
```
1. **Require the bundle**

```shell
composer require --dev teamneusta/pimcore-testing-framework
```

## Usage

Expand Down Expand Up @@ -41,10 +43,11 @@ Pimcore also expects some configuration
(e.g., for the [`security`](https://github.com/pimcore/skeleton/blob/10.2/config/packages/security.yaml)) to be present.

You can use the `\Neusta\Pimcore\TestingFramework\Kernel\TestKernel` as a base,
which already provides all necessary configurations with default values
which already provides all necessary configurations with default values
(see: `dist/config` and `dist/pimcore10/config` or `dist/pimcore11/config`, depending on your Pimcore version).

For a basic setup, you can use the `TestKernel` directly:

```php
# tests/bootstrap.php
<?php
Expand Down Expand Up @@ -79,7 +82,7 @@ We provide traits to switch common behavior on/off in whole test case classes.

#### Admin Mode

The admin mode is disabled by default when calling `BootstrapPimcore::bootstrap()`.
The admin mode is disabled by default when calling `BootstrapPimcore::bootstrap()`.

To enable it again, you can use the `WithAdminMode` trait.

Expand All @@ -104,7 +107,7 @@ It'll also reset the database between each test, so you don't have to worry abou
#### Using a Dump

If you already have a database dump that you want to use instead of a fresh Pimcore installation,
there's the `DATABASE_DUMP_LOCATION` environment variable.
there's the `DATABASE_DUMP_LOCATION` environment variable.
Point it to the location of your dump, and it'll be used instead.

#### Faster Database Reset
Expand Down Expand Up @@ -141,3 +144,19 @@ and it'll automatically be used.
Feel free to open issues for any bug, feature request, or other ideas.

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

### Local Development

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

```shell
bin/composer install
```

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

```shell
bin/composer cs:fix
bin/composer phpstan
bin/composer tests
```
3 changes: 3 additions & 0 deletions bin/composer
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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.2-latest
volumes:
- ./:/var/www/html/
environment:
MYSQL_SERVER_VERSION: mariadb-10.11.4
depends_on:
database:
condition: service_healthy
Loading