Skip to content

Commit

Permalink
Merge branch 'master' into add-dependabot-automation
Browse files Browse the repository at this point in the history
  • Loading branch information
jkniest authored Aug 23, 2023
2 parents 69f0ee8 + 4780588 commit 2ad2ce8
Show file tree
Hide file tree
Showing 16 changed files with 202 additions and 95 deletions.
22 changes: 12 additions & 10 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:

strategy:
matrix:
php-version: [ 7.4, 8.0, 8.1 ]
php-version: [ 8.1, 8.2 ]

steps:
- name: Set up PHP
Expand All @@ -31,15 +31,16 @@ jobs:
run: 'composer install --prefer-dist --no-ansi --no-interaction --no-progress --optimize-autoloader'

- name: Run PHP CS Fixer
run: './vendor/bin/php-cs-fixer fix --dry-run'
run: 'PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix --dry-run'

phpstan:
name: PHPStan
runs-on: ubuntu-latest

strategy:
matrix:
php-version: [ 7.4, 8.0, 8.1 ]
php-version: [ 8.1, 8.2 ]
composer-strategy: [ lowest, stable ]

steps:
- name: Set up PHP
Expand All @@ -55,12 +56,12 @@ jobs:
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
key: ${{ runner.os }}-php-strategy-${{ matrix.composer-strategy }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
${{ runner.os }}-php-strategy-${{ matrix.composer-strategy }}-
- name: Install dependencies
run: 'composer install --prefer-dist --no-ansi --no-interaction --no-progress --optimize-autoloader'
run: 'composer update -W --prefer-${{ matrix.composer-strategy }} --no-ansi --no-interaction --no-progress --optimize-autoloader'

- name: Run PHPStan
run: './vendor/bin/phpstan analyse --memory-limit=1G'
Expand All @@ -71,7 +72,8 @@ jobs:

strategy:
matrix:
php-version: [ 7.4, 8.0, 8.1 ]
php-version: [ 8.1, 8.2 ]
composer-strategy: [ lowest, stable ]

steps:
- name: Set up PHP
Expand All @@ -87,12 +89,12 @@ jobs:
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
key: ${{ runner.os }}-php-strategy-${{ matrix.composer-strategy }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
${{ runner.os }}-php-strategy-${{ matrix.composer-strategy }}-
- name: Install dependencies
run: 'composer install --prefer-dist --no-ansi --no-interaction --no-progress --optimize-autoloader'
run: 'composer update -W --prefer-${{ matrix.composer-strategy }} --no-ansi --no-interaction --no-progress --optimize-autoloader'

- name: Run Psalm
run: './vendor/bin/psalm --show-info=false'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
/coverage
/public/coverage
/src/Resources/app/storefront/node_modules/
composer.lock
23 changes: 22 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ 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).

## [Unreleased]
### Added
- Add new helper method to load a TaxEntity by its value.

## [2.2.1] - 2023-05-26
### Fixed
- Restored compatibility for Shopware 6.4 by removing typehints for **EntityRepository** in util classes.

## [2.2.0] - 2023-05-09
### Added
- Added tests for PHP 8.2

### Changed
- Switched from **EntityRepositoryInterface** to **EntityRepository** in util classes to support Shopware 6.5

## Removed
- Dropped support for PHP 7.4 and 8.0

## [2.1.0] - 2022-09-19
### Added
- Added the option `--with-dependencies` / `-w` to the `fixture:run:single` command
Expand Down Expand Up @@ -44,7 +62,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [1.6.0] - 2022-05-09
### Added
- Added more helper functions:
- `getMediaDefaultFolderId`
- `getMediaDefaultFolderId`

## [1.5.0] - 2022-04-20
### Added
Expand Down Expand Up @@ -110,6 +128,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `getNotSpecifiedSalutationId`
- `getGermanCountryId`

[2.2.1]: https://github.com/basecom/FixturesPlugin/compare/2.2.0...2.2.1
[2.2.0]: https://github.com/basecom/FixturesPlugin/compare/2.1.0...2.2.0
[2.1.0]: https://github.com/basecom/FixturesPlugin/compare/2.0.0...2.1.0
[2.0.0]: https://github.com/basecom/FixturesPlugin/compare/1.8.0...2.0.0
[1.8.0]: https://github.com/basecom/FixturesPlugin/compare/1.7.0...1.8.0
[1.7.0]: https://github.com/basecom/FixturesPlugin/compare/1.6.0...1.7.0
Expand Down
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ bin/console fixture:load:single <name>
bin/console fixture:load:single dummyFixture
```

By default, if you run a single fixture it will ignore all its dependencies. If you want to run the single fixture,
including all dependencies recursively, use the `--with-dependencies` option.

```bash
bin/console fixture:load:single --with-dependencies <name>

# fixture class is named "DummyFixture.php", (it´s case-insensitive)
bin/console fixture:load:single --with-dependencies dummyFixture
```

### Run group
To run a group of fixture, run this command with group name as parameter (specified via **groups()** method). It´s also case-insensitive.

Expand All @@ -101,8 +111,6 @@ bin/console fixture:load:group <name>
```




## Best Practices

### Plugin Development
Expand Down Expand Up @@ -171,8 +179,5 @@ host machine (not in shell):
```


### GitLab pipeline
The GitLab pipeline is already pre-configured. It contains multiple jobs for all linting, static analysis and testing tools.

The pipeline runs all tests for the latest stable Shopware 6 version. But you have several options for the PHPUnit tests:

### Github Actions
The Github actions pipeline is already pre-configured. It contains multiple jobs for all linting, static analysis and testing tools.
15 changes: 10 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,19 @@
}
},
"require": {
"php": "^7.4 || ^8.0 || ^8.1",
"shopware/core": "6.3.*|6.4.*",
"shopware/administration": "6.3.*|6.4.*",
"shopware/storefront": "6.3.*|6.4.*"
"php": "^8.1 || ^8.2",
"shopware/core": "6.3.*|6.4.*|6.5.*",
"shopware/administration": "6.3.*|6.4.*|6.5.*",
"shopware/storefront": "6.3.*|6.4.*|6.5.*"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"friendsofphp/php-cs-fixer": "3.23.0",
"phpstan/phpstan": "^1.4",
"vimeo/psalm": "^4.18"
},
"config": {
"allow-plugins": {
"symfony/runtime": true
}
}
}
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3"

services:
shopware:
image: 'dockware/dev:6.4.10.0'
image: 'dockware/dev:6.5.4.1'
ports:
- "80:80" # Webserver / Apache
- "3306:3306" # MySQL database
Expand All @@ -12,7 +12,7 @@ services:
- "9998:9998" # Storefront watcher (background)
environment:
- 'XDEBUG_ENABLED=1'
- 'PHP_VERSION=8.1'
- 'PHP_VERSION=8.2'
volumes:
- "./:/var/www/html/custom/static-plugins/plugin"
- "db:/var/lib/mysql"
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ parameters:
level: 9

checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
25 changes: 12 additions & 13 deletions src/FixtureLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
namespace Basecom\FixturePlugin;

use Symfony\Component\Console\Style\SymfonyStyle;
use Traversable;

class FixtureLoader
{
private array $fixtures;
private array $fixtureReference;

public function __construct(Traversable $fixtures)
public function __construct(\Traversable $fixtures)
{
$this->fixtures = iterator_to_array($fixtures);
}
Expand All @@ -26,7 +25,7 @@ public function runAll(SymfonyStyle $io): void
public function runSingle(SymfonyStyle $io, string $fixtureName, bool $withDependencies = false): void
{
foreach ($this->fixtures as $fixture) {
$className = \get_class($fixture) ?: '';
$className = $fixture::class ?: '';

if (!str_contains(strtolower($className), strtolower($fixtureName))) {
continue;
Expand Down Expand Up @@ -59,13 +58,13 @@ public function runFixtureGroup(SymfonyStyle $io, string $groupName): void

/** @var Fixture $fixture */
foreach ($this->fixtures as $fixture) {
//Check if fixture has been assigned to any group, if not stop the iteration
// Check if fixture has been assigned to any group, if not stop the iteration
if (\count($fixture->groups()) <= 0) {
continue;
}

foreach ($fixture->groups() as $group) {
//Check if fixture is in affected group(from the command parameter). If not, skip the iteration.
// Check if fixture is in affected group(from the command parameter). If not, skip the iteration.
if (strtolower($group) !== strtolower($groupName)) {
continue;
}
Expand All @@ -75,23 +74,23 @@ public function runFixtureGroup(SymfonyStyle $io, string $groupName): void
}
}

//If no fixture was found for the group, return.
// If no fixture was found for the group, return.
if (\count($fixturesInGroup) <= 0) {
$io->note('No fixtures in group '.$groupName);

return;
}

//Build the references, they are needed in dependency check.
// Build the references, they are needed in dependency check.
$this->fixtureReference = $this->buildFixtureReference($this->fixtures);

foreach ($fixturesInGroup as $fixture) {
//If fixture doesn´t has any dependencies, skip the check.
// If fixture doesn´t has any dependencies, skip the check.
if (\count($fixture->dependsOn()) <= 0) {
continue;
}

//Check if dependencies of fixture are in the same group.
// Check if dependencies of fixture are in the same group.
if (!$this->checkDependenciesAreInSameGroup($io, $fixture, $groupName)) {
return;
}
Expand All @@ -112,7 +111,7 @@ private function checkDependenciesAreInSameGroup(SymfonyStyle $io, Fixture $fixt
$fixtureReference = $this->fixtureReference[$dependency];
$lowerCaseDependencies = array_map('strtolower', $fixtureReference->groups());
if (!\in_array(strtolower($groupName), $lowerCaseDependencies, true)) {
$io->error('Dependency '.$dependency.' of fixture '.\get_class($fixture).' is not in the same group. Please add dependant fixture '.$dependency.' to group '.$groupName);
$io->error('Dependency '.$dependency.' of fixture '.$fixture::class.' is not in the same group. Please add dependant fixture '.$dependency.' to group '.$groupName);

return false;
}
Expand All @@ -131,7 +130,7 @@ private function runFixtures(SymfonyStyle $io, array $fixtures): void

$bag = new FixtureBag();
foreach ($fixtures as $fixture) {
$io->note('Running '.\get_class($fixture));
$io->note('Running '.$fixture::class);
$fixture->load($bag);
}
}
Expand All @@ -148,7 +147,7 @@ private function buildFixtureReference(array $fixtures): array
$result = [];

foreach ($fixtures as $fixture) {
$result[\get_class($fixture)] = $fixture;
$result[$fixture::class] = $fixture;
}

return $result;
Expand Down Expand Up @@ -178,7 +177,7 @@ private function buildDependencyTree(array $fixtures): array
foreach ($fixtures as $fixture) {
foreach ($sorted as $sort) {
foreach ($sort->dependsOn() as $dependent) {
if ($dependent !== \get_class($fixture)) {
if ($dependent !== $fixture::class) {
continue;
}

Expand Down
9 changes: 9 additions & 0 deletions src/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@ services:
Basecom\FixturePlugin\FixtureLoader:
arguments:
- !tagged_iterator basecom.fixture

Basecom\FixturePlugin\Utils\MediaUtils:
arguments:
$mediaRepository: '@media.repository'
$mediaFolderRepository: '@media_folder.repository'

Basecom\FixturePlugin\Utils\PaymentMethodUtils:
arguments:
$paymentMethodRepository: '@payment_method.repository'
18 changes: 12 additions & 6 deletions src/Utils/CategoryUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

use Shopware\Core\Content\Category\CategoryEntity;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;

class CategoryUtils
{
private EntityRepositoryInterface $categoryRepository;
private EntityRepository $categoryRepository;

public function __construct(EntityRepositoryInterface $categoryRepository)
public function __construct(EntityRepository $categoryRepository)
{
$this->categoryRepository = $categoryRepository;
}
Expand All @@ -26,9 +26,11 @@ public function getRootCategory(): ?CategoryEntity
->addFilter(new EqualsFilter('level', 1))
->setLimit(1);

return $this->categoryRepository
$category = $this->categoryRepository
->search($criteria, Context::createDefaultContext())
->first();

return $category instanceof CategoryEntity ? $category : null;
}

public function getFirst(): ?CategoryEntity
Expand All @@ -37,9 +39,11 @@ public function getFirst(): ?CategoryEntity
new EqualsFilter('level', '1')
)->setLimit(1);

return $this->categoryRepository
$category = $this->categoryRepository
->search($criteria, Context::createDefaultContext())
->first();

return $category instanceof CategoryEntity ? $category : null;
}

/**
Expand All @@ -51,8 +55,10 @@ public function getByName(string $name): ?CategoryEntity
$criteria->addFilter(new EqualsFilter('name', $name));
$criteria->setLimit(1);

return $this->categoryRepository
$category = $this->categoryRepository
->search($criteria, Context::createDefaultContext())
->first();

return $category instanceof CategoryEntity ? $category : null;
}
}
Loading

0 comments on commit 2ad2ce8

Please sign in to comment.