diff --git a/.forgejo/workflows/pull_request.yml b/.forgejo/workflows/pull_request.yml index dd18b5b..6bbc920 100644 --- a/.forgejo/workflows/pull_request.yml +++ b/.forgejo/workflows/pull_request.yml @@ -23,19 +23,7 @@ jobs: - name: lint run: composer lint - name: test - run: composer mutation - - name: Add comment to pull request - run: | - echo '```' >> /tmp/pull-request-comment - cat var/log/infection.txt >> /tmp/pull-request-comment - cat var/log/summary.log >> /tmp/pull-request-comment - echo '```' >> /tmp/pull-request-comment - jq -n --arg msg "$(cat /tmp/pull-request-comment)" '{"body": $msg}' > /tmp/git-msg - curl -X POST \ - -H "Authorization: token ${GITHUB_TOKEN}" \ - -H "Content-Type: application/json" \ - -d @/tmp/git-msg \ - "${{ env.GITHUB_SERVER_URL }}/api/v1/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" + run: composer test - name: GIT commit and push all changed files env: CI_COMMIT_MESSAGE: Continuous Integration Fixes diff --git a/.forgejo/workflows/push.yml b/.forgejo/workflows/push.yml index 42aad3b..b4a5837 100644 --- a/.forgejo/workflows/push.yml +++ b/.forgejo/workflows/push.yml @@ -27,7 +27,7 @@ jobs: - name: lint run: composer lint - name: test - run: composer mutation + run: composer test - name: GIT commit and push all changed files env: CI_COMMIT_MESSAGE: Continuous Integration Fixes diff --git a/composer.json b/composer.json index 0485899..003b2b5 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,6 @@ }, "require-dev": { "doctrine/doctrine-fixtures-bundle": "^4.0", - "infection/infection": "^0.29.6", "lubiana/code-quality": "^1.7.2", "phpunit/phpunit": "^9.6.20", "symfony/browser-kit": "7.2.*", @@ -42,8 +41,7 @@ "php-http/discovery": true, "symfony/flex": true, "symfony/runtime": true, - "dealerdirect/phpcodesniffer-composer-installer": true, - "infection/extension-installer": true + "dealerdirect/phpcodesniffer-composer-installer": true }, "sort-packages": true, "platform": { @@ -68,7 +66,8 @@ "symfony/polyfill-php74": "*", "symfony/polyfill-php80": "*", "symfony/polyfill-php81": "*", - "symfony/polyfill-php82": "*" + "symfony/polyfill-php82": "*", + "symfony/polyfill-php83": "*" }, "scripts": { "auto-scripts": { @@ -86,8 +85,7 @@ "rector", "ecs --fix || ecs --fix" ], - "test": "bin/phpunit", - "mutation": "infection --threads=8 --show-mutations" + "test": "bin/phpunit" }, "conflict": { "symfony/symfony": "*" diff --git a/composer.lock b/composer.lock index 487eb49..2d25c27 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3d1e7e69822d02e0e2d6e84a5ff14087", + "content-hash": "9914f982d0228ab4735cb683fe2cb7e4", "packages": [ { "name": "doctrine/cache", @@ -3465,82 +3465,6 @@ ], "time": "2024-09-09T11:45:10+00:00" }, - { - "name": "symfony/polyfill-php83", - "version": "v1.31.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-php83.git", - "reference": "2fb86d65e2d424369ad2905e83b236a8805ba491" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php83/zipball/2fb86d65e2d424369ad2905e83b236a8805ba491", - "reference": "2fb86d65e2d424369ad2905e83b236a8805ba491", - "shasum": "" - }, - "require": { - "php": ">=7.2" - }, - "type": "library", - "extra": { - "thanks": { - "url": "https://github.com/symfony/polyfill", - "name": "symfony/polyfill" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Php83\\": "" - }, - "classmap": [ - "Resources/stubs" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill backporting some PHP 8.3+ features to lower PHP versions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "polyfill", - "portable", - "shim" - ], - "support": { - "source": "https://github.com/symfony/polyfill-php83/tree/v1.31.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2024-09-09T11:45:10+00:00" - }, { "name": "symfony/polyfill-uuid", "version": "v1.31.0", @@ -5156,239 +5080,6 @@ } ], "packages-dev": [ - { - "name": "colinodell/json5", - "version": "v3.0.0", - "source": { - "type": "git", - "url": "https://github.com/colinodell/json5.git", - "reference": "5724d21bc5c910c2560af1b8915f0cc0163579c8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/colinodell/json5/zipball/5724d21bc5c910c2560af1b8915f0cc0163579c8", - "reference": "5724d21bc5c910c2560af1b8915f0cc0163579c8", - "shasum": "" - }, - "require": { - "ext-json": "*", - "ext-mbstring": "*", - "php": "^8.0" - }, - "require-dev": { - "mikehaertl/php-shellcommand": "^1.7.0", - "phpstan/phpstan": "^1.10.57", - "scrutinizer/ocular": "^1.9", - "squizlabs/php_codesniffer": "^3.8.1", - "symfony/finder": "^6.0|^7.0", - "symfony/phpunit-bridge": "^7.0.3" - }, - "bin": [ - "bin/json5" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "4.0-dev" - } - }, - "autoload": { - "files": [ - "src/global.php" - ], - "psr-4": { - "ColinODell\\Json5\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Colin O'Dell", - "email": "colinodell@gmail.com", - "homepage": "https://www.colinodell.com", - "role": "Developer" - } - ], - "description": "UTF-8 compatible JSON5 parser for PHP", - "homepage": "https://github.com/colinodell/json5", - "keywords": [ - "JSON5", - "json", - "json5_decode", - "json_decode" - ], - "support": { - "issues": "https://github.com/colinodell/json5/issues", - "source": "https://github.com/colinodell/json5/tree/v3.0.0" - }, - "funding": [ - { - "url": "https://www.colinodell.com/sponsor", - "type": "custom" - }, - { - "url": "https://www.paypal.me/colinpodell/10.00", - "type": "custom" - }, - { - "url": "https://github.com/colinodell", - "type": "github" - }, - { - "url": "https://www.patreon.com/colinodell", - "type": "patreon" - } - ], - "time": "2024-02-09T13:06:12+00:00" - }, - { - "name": "composer/pcre", - "version": "3.3.2", - "source": { - "type": "git", - "url": "https://github.com/composer/pcre.git", - "reference": "b2bed4734f0cc156ee1fe9c0da2550420d99a21e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/composer/pcre/zipball/b2bed4734f0cc156ee1fe9c0da2550420d99a21e", - "reference": "b2bed4734f0cc156ee1fe9c0da2550420d99a21e", - "shasum": "" - }, - "require": { - "php": "^7.4 || ^8.0" - }, - "conflict": { - "phpstan/phpstan": "<1.11.10" - }, - "require-dev": { - "phpstan/phpstan": "^1.12 || ^2", - "phpstan/phpstan-strict-rules": "^1 || ^2", - "phpunit/phpunit": "^8 || ^9" - }, - "type": "library", - "extra": { - "phpstan": { - "includes": [ - "extension.neon" - ] - }, - "branch-alias": { - "dev-main": "3.x-dev" - } - }, - "autoload": { - "psr-4": { - "Composer\\Pcre\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jordi Boggiano", - "email": "j.boggiano@seld.be", - "homepage": "http://seld.be" - } - ], - "description": "PCRE wrapping library that offers type-safe preg_* replacements.", - "keywords": [ - "PCRE", - "preg", - "regex", - "regular expression" - ], - "support": { - "issues": "https://github.com/composer/pcre/issues", - "source": "https://github.com/composer/pcre/tree/3.3.2" - }, - "funding": [ - { - "url": "https://packagist.com", - "type": "custom" - }, - { - "url": "https://github.com/composer", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/composer/composer", - "type": "tidelift" - } - ], - "time": "2024-11-12T16:29:46+00:00" - }, - { - "name": "composer/xdebug-handler", - "version": "3.0.5", - "source": { - "type": "git", - "url": "https://github.com/composer/xdebug-handler.git", - "reference": "6c1925561632e83d60a44492e0b344cf48ab85ef" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/6c1925561632e83d60a44492e0b344cf48ab85ef", - "reference": "6c1925561632e83d60a44492e0b344cf48ab85ef", - "shasum": "" - }, - "require": { - "composer/pcre": "^1 || ^2 || ^3", - "php": "^7.2.5 || ^8.0", - "psr/log": "^1 || ^2 || ^3" - }, - "require-dev": { - "phpstan/phpstan": "^1.0", - "phpstan/phpstan-strict-rules": "^1.1", - "phpunit/phpunit": "^8.5 || ^9.6 || ^10.5" - }, - "type": "library", - "autoload": { - "psr-4": { - "Composer\\XdebugHandler\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "John Stevenson", - "email": "john-stevenson@blueyonder.co.uk" - } - ], - "description": "Restarts a process without Xdebug.", - "keywords": [ - "Xdebug", - "performance" - ], - "support": { - "irc": "ircs://irc.libera.chat:6697/composer", - "issues": "https://github.com/composer/xdebug-handler/issues", - "source": "https://github.com/composer/xdebug-handler/tree/3.0.5" - }, - "funding": [ - { - "url": "https://packagist.com", - "type": "custom" - }, - { - "url": "https://github.com/composer", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/composer/composer", - "type": "tidelift" - } - ], - "time": "2024-05-06T16:37:16+00:00" - }, { "name": "dealerdirect/phpcodesniffer-composer-installer", "version": "v1.0.0", @@ -5636,490 +5327,6 @@ ], "time": "2024-12-05T18:35:55+00:00" }, - { - "name": "fidry/cpu-core-counter", - "version": "1.2.0", - "source": { - "type": "git", - "url": "https://github.com/theofidry/cpu-core-counter.git", - "reference": "8520451a140d3f46ac33042715115e290cf5785f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/theofidry/cpu-core-counter/zipball/8520451a140d3f46ac33042715115e290cf5785f", - "reference": "8520451a140d3f46ac33042715115e290cf5785f", - "shasum": "" - }, - "require": { - "php": "^7.2 || ^8.0" - }, - "require-dev": { - "fidry/makefile": "^0.2.0", - "fidry/php-cs-fixer-config": "^1.1.2", - "phpstan/extension-installer": "^1.2.0", - "phpstan/phpstan": "^1.9.2", - "phpstan/phpstan-deprecation-rules": "^1.0.0", - "phpstan/phpstan-phpunit": "^1.2.2", - "phpstan/phpstan-strict-rules": "^1.4.4", - "phpunit/phpunit": "^8.5.31 || ^9.5.26", - "webmozarts/strict-phpunit": "^7.5" - }, - "type": "library", - "autoload": { - "psr-4": { - "Fidry\\CpuCoreCounter\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Théo FIDRY", - "email": "theo.fidry@gmail.com" - } - ], - "description": "Tiny utility to get the number of CPU cores.", - "keywords": [ - "CPU", - "core" - ], - "support": { - "issues": "https://github.com/theofidry/cpu-core-counter/issues", - "source": "https://github.com/theofidry/cpu-core-counter/tree/1.2.0" - }, - "funding": [ - { - "url": "https://github.com/theofidry", - "type": "github" - } - ], - "time": "2024-08-06T10:04:20+00:00" - }, - { - "name": "infection/abstract-testframework-adapter", - "version": "0.5.0", - "source": { - "type": "git", - "url": "https://github.com/infection/abstract-testframework-adapter.git", - "reference": "18925e20d15d1a5995bb85c9dc09e8751e1e069b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/infection/abstract-testframework-adapter/zipball/18925e20d15d1a5995bb85c9dc09e8751e1e069b", - "reference": "18925e20d15d1a5995bb85c9dc09e8751e1e069b", - "shasum": "" - }, - "require": { - "php": "^7.4 || ^8.0" - }, - "require-dev": { - "ergebnis/composer-normalize": "^2.8", - "friendsofphp/php-cs-fixer": "^2.17", - "phpunit/phpunit": "^9.5" - }, - "type": "library", - "autoload": { - "psr-4": { - "Infection\\AbstractTestFramework\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Maks Rafalko", - "email": "maks.rafalko@gmail.com" - } - ], - "description": "Abstract Test Framework Adapter for Infection", - "support": { - "issues": "https://github.com/infection/abstract-testframework-adapter/issues", - "source": "https://github.com/infection/abstract-testframework-adapter/tree/0.5.0" - }, - "funding": [ - { - "url": "https://github.com/infection", - "type": "github" - }, - { - "url": "https://opencollective.com/infection", - "type": "open_collective" - } - ], - "time": "2021-08-17T18:49:12+00:00" - }, - { - "name": "infection/extension-installer", - "version": "0.1.2", - "source": { - "type": "git", - "url": "https://github.com/infection/extension-installer.git", - "reference": "9b351d2910b9a23ab4815542e93d541e0ca0cdcf" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/infection/extension-installer/zipball/9b351d2910b9a23ab4815542e93d541e0ca0cdcf", - "reference": "9b351d2910b9a23ab4815542e93d541e0ca0cdcf", - "shasum": "" - }, - "require": { - "composer-plugin-api": "^1.1 || ^2.0" - }, - "require-dev": { - "composer/composer": "^1.9 || ^2.0", - "friendsofphp/php-cs-fixer": "^2.18, <2.19", - "infection/infection": "^0.15.2", - "php-coveralls/php-coveralls": "^2.4", - "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "^0.12.10", - "phpstan/phpstan-phpunit": "^0.12.6", - "phpstan/phpstan-strict-rules": "^0.12.2", - "phpstan/phpstan-webmozart-assert": "^0.12.2", - "phpunit/phpunit": "^9.5", - "vimeo/psalm": "^4.8" - }, - "type": "composer-plugin", - "extra": { - "class": "Infection\\ExtensionInstaller\\Plugin" - }, - "autoload": { - "psr-4": { - "Infection\\ExtensionInstaller\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Maks Rafalko", - "email": "maks.rafalko@gmail.com" - } - ], - "description": "Infection Extension Installer", - "support": { - "issues": "https://github.com/infection/extension-installer/issues", - "source": "https://github.com/infection/extension-installer/tree/0.1.2" - }, - "funding": [ - { - "url": "https://github.com/infection", - "type": "github" - }, - { - "url": "https://opencollective.com/infection", - "type": "open_collective" - } - ], - "time": "2021-10-20T22:08:34+00:00" - }, - { - "name": "infection/include-interceptor", - "version": "0.2.5", - "source": { - "type": "git", - "url": "https://github.com/infection/include-interceptor.git", - "reference": "0cc76d95a79d9832d74e74492b0a30139904bdf7" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/infection/include-interceptor/zipball/0cc76d95a79d9832d74e74492b0a30139904bdf7", - "reference": "0cc76d95a79d9832d74e74492b0a30139904bdf7", - "shasum": "" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "^2.16", - "infection/infection": "^0.15.0", - "phan/phan": "^2.4 || ^3", - "php-coveralls/php-coveralls": "^2.2", - "phpstan/phpstan": "^0.12.8", - "phpunit/phpunit": "^8.5", - "vimeo/psalm": "^3.8" - }, - "type": "library", - "autoload": { - "psr-4": { - "Infection\\StreamWrapper\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Maks Rafalko", - "email": "maks.rafalko@gmail.com" - } - ], - "description": "Stream Wrapper: Include Interceptor. Allows to replace included (autoloaded) file with another one.", - "support": { - "issues": "https://github.com/infection/include-interceptor/issues", - "source": "https://github.com/infection/include-interceptor/tree/0.2.5" - }, - "funding": [ - { - "url": "https://github.com/infection", - "type": "github" - }, - { - "url": "https://opencollective.com/infection", - "type": "open_collective" - } - ], - "time": "2021-08-09T10:03:57+00:00" - }, - { - "name": "infection/infection", - "version": "0.29.10", - "source": { - "type": "git", - "url": "https://github.com/infection/infection.git", - "reference": "cac7d20e5d286a37488527e477f5a695a9d7a44c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/infection/infection/zipball/cac7d20e5d286a37488527e477f5a695a9d7a44c", - "reference": "cac7d20e5d286a37488527e477f5a695a9d7a44c", - "shasum": "" - }, - "require": { - "colinodell/json5": "^2.2 || ^3.0", - "composer-runtime-api": "^2.0", - "composer/xdebug-handler": "^2.0 || ^3.0", - "ext-dom": "*", - "ext-json": "*", - "ext-libxml": "*", - "ext-mbstring": "*", - "fidry/cpu-core-counter": "^0.4.0 || ^0.5.0 || ^1.0", - "infection/abstract-testframework-adapter": "^0.5.0", - "infection/extension-installer": "^0.1.0", - "infection/include-interceptor": "^0.2.5", - "infection/mutator": "^0.4", - "justinrainbow/json-schema": "^5.3", - "nikic/php-parser": "^5.3", - "ondram/ci-detector": "^4.1.0", - "php": "^8.2", - "sanmai/later": "^0.1.1", - "sanmai/pipeline": "^5.1 || ^6", - "sebastian/diff": "^3.0.2 || ^4.0 || ^5.0 || ^6.0", - "shish/safe": "^2.6", - "symfony/console": "^5.4 || ^6.0 || ^7.0", - "symfony/filesystem": "^5.4 || ^6.0 || ^7.0", - "symfony/finder": "^5.4 || ^6.0 || ^7.0", - "symfony/process": "^5.4 || ^6.0 || ^7.0", - "webmozart/assert": "^1.11" - }, - "conflict": { - "antecedent/patchwork": "<2.1.25", - "dg/bypass-finals": "<1.4.1", - "phpunit/php-code-coverage": ">9,<9.1.4 || >9.2.17,<9.2.21" - }, - "require-dev": { - "ext-simplexml": "*", - "fidry/makefile": "^1.0", - "helmich/phpunit-json-assert": "^3.0", - "phpstan/extension-installer": "^1.1.0", - "phpstan/phpstan": "^1.10.15", - "phpstan/phpstan-phpunit": "^1.0.0", - "phpstan/phpstan-strict-rules": "^1.1.0", - "phpstan/phpstan-webmozart-assert": "^1.0.2", - "phpunit/phpunit": "^10.5", - "rector/rector": "^1.0", - "sidz/phpstan-rules": "^0.4", - "symfony/yaml": "^5.4 || ^6.0 || ^7.0" - }, - "bin": [ - "bin/infection" - ], - "type": "library", - "autoload": { - "psr-4": { - "Infection\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Maks Rafalko", - "email": "maks.rafalko@gmail.com", - "homepage": "https://twitter.com/maks_rafalko" - }, - { - "name": "Oleg Zhulnev", - "homepage": "https://github.com/sidz" - }, - { - "name": "Gert de Pagter", - "homepage": "https://github.com/BackEndTea" - }, - { - "name": "Théo FIDRY", - "email": "theo.fidry@gmail.com", - "homepage": "https://twitter.com/tfidry" - }, - { - "name": "Alexey Kopytko", - "email": "alexey@kopytko.com", - "homepage": "https://www.alexeykopytko.com" - }, - { - "name": "Andreas Möller", - "email": "am@localheinz.com", - "homepage": "https://localheinz.com" - } - ], - "description": "Infection is a Mutation Testing framework for PHP. The mutation adequacy score can be used to measure the effectiveness of a test set in terms of its ability to detect faults.", - "keywords": [ - "coverage", - "mutant", - "mutation framework", - "mutation testing", - "testing", - "unit testing" - ], - "support": { - "issues": "https://github.com/infection/infection/issues", - "source": "https://github.com/infection/infection/tree/0.29.10" - }, - "funding": [ - { - "url": "https://github.com/infection", - "type": "github" - }, - { - "url": "https://opencollective.com/infection", - "type": "open_collective" - } - ], - "time": "2024-12-17T19:11:10+00:00" - }, - { - "name": "infection/mutator", - "version": "0.4.0", - "source": { - "type": "git", - "url": "https://github.com/infection/mutator.git", - "reference": "51d6d01a2357102030aee9d603063c4bad86b144" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/infection/mutator/zipball/51d6d01a2357102030aee9d603063c4bad86b144", - "reference": "51d6d01a2357102030aee9d603063c4bad86b144", - "shasum": "" - }, - "require": { - "nikic/php-parser": "^5.0" - }, - "require-dev": { - "phpunit/phpunit": "^9.6 || ^10" - }, - "type": "library", - "autoload": { - "psr-4": { - "Infection\\Mutator\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Maks Rafalko", - "email": "maks.rafalko@gmail.com" - } - ], - "description": "Mutator interface to implement custom mutators (mutation operators) for Infection", - "support": { - "issues": "https://github.com/infection/mutator/issues", - "source": "https://github.com/infection/mutator/tree/0.4.0" - }, - "funding": [ - { - "url": "https://github.com/infection", - "type": "github" - }, - { - "url": "https://opencollective.com/infection", - "type": "open_collective" - } - ], - "time": "2024-05-14T22:39:59+00:00" - }, - { - "name": "justinrainbow/json-schema", - "version": "5.3.0", - "source": { - "type": "git", - "url": "https://github.com/jsonrainbow/json-schema.git", - "reference": "feb2ca6dd1cebdaf1ed60a4c8de2e53ce11c4fd8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/jsonrainbow/json-schema/zipball/feb2ca6dd1cebdaf1ed60a4c8de2e53ce11c4fd8", - "reference": "feb2ca6dd1cebdaf1ed60a4c8de2e53ce11c4fd8", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "~2.2.20||~2.15.1", - "json-schema/json-schema-test-suite": "1.2.0", - "phpunit/phpunit": "^4.8.35" - }, - "bin": [ - "bin/validate-json" - ], - "type": "library", - "autoload": { - "psr-4": { - "JsonSchema\\": "src/JsonSchema/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Bruno Prieto Reis", - "email": "bruno.p.reis@gmail.com" - }, - { - "name": "Justin Rainbow", - "email": "justin.rainbow@gmail.com" - }, - { - "name": "Igor Wiedler", - "email": "igor@wiedler.ch" - }, - { - "name": "Robert Schönthal", - "email": "seroscho@googlemail.com" - } - ], - "description": "A library to validate a json schema.", - "homepage": "https://github.com/justinrainbow/json-schema", - "keywords": [ - "json", - "schema" - ], - "support": { - "issues": "https://github.com/jsonrainbow/json-schema/issues", - "source": "https://github.com/jsonrainbow/json-schema/tree/5.3.0" - }, - "time": "2024-07-06T21:00:26+00:00" - }, { "name": "lubiana/code-quality", "version": "1.7.2", @@ -6334,84 +5541,6 @@ }, "time": "2024-12-30T11:07:19+00:00" }, - { - "name": "ondram/ci-detector", - "version": "4.2.0", - "source": { - "type": "git", - "url": "https://github.com/OndraM/ci-detector.git", - "reference": "8b0223b5ed235fd377c75fdd1bfcad05c0f168b8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/OndraM/ci-detector/zipball/8b0223b5ed235fd377c75fdd1bfcad05c0f168b8", - "reference": "8b0223b5ed235fd377c75fdd1bfcad05c0f168b8", - "shasum": "" - }, - "require": { - "php": "^7.4 || ^8.0" - }, - "require-dev": { - "ergebnis/composer-normalize": "^2.13.2", - "lmc/coding-standard": "^3.0.0", - "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/extension-installer": "^1.1.0", - "phpstan/phpstan": "^1.2.0", - "phpstan/phpstan-phpunit": "^1.0.0", - "phpunit/phpunit": "^9.6.13" - }, - "type": "library", - "autoload": { - "psr-4": { - "OndraM\\CiDetector\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Ondřej Machulda", - "email": "ondrej.machulda@gmail.com" - } - ], - "description": "Detect continuous integration environment and provide unified access to properties of current build", - "keywords": [ - "CircleCI", - "Codeship", - "Wercker", - "adapter", - "appveyor", - "aws", - "aws codebuild", - "azure", - "azure devops", - "azure pipelines", - "bamboo", - "bitbucket", - "buddy", - "ci-info", - "codebuild", - "continuous integration", - "continuousphp", - "devops", - "drone", - "github", - "gitlab", - "interface", - "jenkins", - "pipelines", - "sourcehut", - "teamcity", - "travis" - ], - "support": { - "issues": "https://github.com/OndraM/ci-detector/issues", - "source": "https://github.com/OndraM/ci-detector/tree/4.2.0" - }, - "time": "2024-03-12T13:22:30+00:00" - }, { "name": "phar-io/manifest", "version": "2.0.4", @@ -7116,135 +6245,6 @@ ], "time": "2024-11-08T13:59:10+00:00" }, - { - "name": "sanmai/later", - "version": "0.1.4", - "source": { - "type": "git", - "url": "https://github.com/sanmai/later.git", - "reference": "e24c4304a4b1349c2a83151a692cec0c10579f60" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sanmai/later/zipball/e24c4304a4b1349c2a83151a692cec0c10579f60", - "reference": "e24c4304a4b1349c2a83151a692cec0c10579f60", - "shasum": "" - }, - "require": { - "php": ">=7.4" - }, - "require-dev": { - "ergebnis/composer-normalize": "^2.8", - "friendsofphp/php-cs-fixer": "^3.35.1", - "infection/infection": ">=0.27.6", - "phan/phan": ">=2", - "php-coveralls/php-coveralls": "^2.0", - "phpstan/phpstan": ">=1.4.5", - "phpunit/phpunit": ">=9.5 <10", - "vimeo/psalm": ">=2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "0.1.x-dev" - } - }, - "autoload": { - "files": [ - "src/functions.php" - ], - "psr-4": { - "Later\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache-2.0" - ], - "authors": [ - { - "name": "Alexey Kopytko", - "email": "alexey@kopytko.com" - } - ], - "description": "Later: deferred wrapper object", - "support": { - "issues": "https://github.com/sanmai/later/issues", - "source": "https://github.com/sanmai/later/tree/0.1.4" - }, - "funding": [ - { - "url": "https://github.com/sanmai", - "type": "github" - } - ], - "time": "2023-10-24T00:25:28+00:00" - }, - { - "name": "sanmai/pipeline", - "version": "6.12", - "source": { - "type": "git", - "url": "https://github.com/sanmai/pipeline.git", - "reference": "ad7dbc3f773eeafb90d5459522fbd8f188532e25" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sanmai/pipeline/zipball/ad7dbc3f773eeafb90d5459522fbd8f188532e25", - "reference": "ad7dbc3f773eeafb90d5459522fbd8f188532e25", - "shasum": "" - }, - "require": { - "php": "^7.4 || ^8.0" - }, - "require-dev": { - "ergebnis/composer-normalize": "^2.8", - "friendsofphp/php-cs-fixer": "^3.17", - "infection/infection": ">=0.10.5", - "league/pipeline": "^0.3 || ^1.0", - "phan/phan": ">=1.1", - "php-coveralls/php-coveralls": "^2.4.1", - "phpstan/phpstan": ">=0.10", - "phpunit/phpunit": ">=9.4", - "vimeo/psalm": ">=2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "v6.x-dev" - } - }, - "autoload": { - "files": [ - "src/functions.php" - ], - "psr-4": { - "Pipeline\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache-2.0" - ], - "authors": [ - { - "name": "Alexey Kopytko", - "email": "alexey@kopytko.com" - } - ], - "description": "General-purpose collections pipeline", - "support": { - "issues": "https://github.com/sanmai/pipeline/issues", - "source": "https://github.com/sanmai/pipeline/tree/6.12" - }, - "funding": [ - { - "url": "https://github.com/sanmai", - "type": "github" - } - ], - "time": "2024-10-17T02:22:57+00:00" - }, { "name": "sebastian/cli-parser", "version": "1.0.2", @@ -8208,157 +7208,6 @@ ], "time": "2020-09-28T06:39:44+00:00" }, - { - "name": "shish/safe", - "version": "v2.6.4", - "source": { - "type": "git", - "url": "https://github.com/shish/safe.git", - "reference": "482e6227330a70b21c1c9e9301cc99b5658ccb89" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/shish/safe/zipball/482e6227330a70b21c1c9e9301cc99b5658ccb89", - "reference": "482e6227330a70b21c1c9e9301cc99b5658ccb89", - "shasum": "" - }, - "require": { - "php": ">= 8.2" - }, - "replace": { - "thecodingmachine/safe": "2.5.0" - }, - "require-dev": { - "phpstan/phpstan": "^1", - "phpunit/phpunit": "^10.0 || ^11.0", - "squizlabs/php_codesniffer": "^3", - "thecodingmachine/phpstan-strict-rules": "^1.0" - }, - "type": "library", - "autoload": { - "files": [ - "deprecated/apc.php", - "deprecated/array.php", - "deprecated/datetime.php", - "deprecated/libevent.php", - "deprecated/misc.php", - "deprecated/password.php", - "deprecated/mssql.php", - "deprecated/stats.php", - "deprecated/strings.php", - "lib/special_cases.php", - "deprecated/mysqli.php", - "generated/apache.php", - "generated/apcu.php", - "generated/array.php", - "generated/bzip2.php", - "generated/calendar.php", - "generated/classobj.php", - "generated/com.php", - "generated/cubrid.php", - "generated/curl.php", - "generated/datetime.php", - "generated/dir.php", - "generated/eio.php", - "generated/errorfunc.php", - "generated/exec.php", - "generated/fileinfo.php", - "generated/filesystem.php", - "generated/filter.php", - "generated/fpm.php", - "generated/ftp.php", - "generated/funchand.php", - "generated/gettext.php", - "generated/gnupg.php", - "generated/hash.php", - "generated/ibase.php", - "generated/ibmDb2.php", - "generated/iconv.php", - "generated/image.php", - "generated/imap.php", - "generated/info.php", - "generated/inotify.php", - "generated/json.php", - "generated/ldap.php", - "generated/libxml.php", - "generated/lzf.php", - "generated/mailparse.php", - "generated/mbstring.php", - "generated/misc.php", - "generated/mysql.php", - "generated/network.php", - "generated/oci8.php", - "generated/opcache.php", - "generated/openssl.php", - "generated/outcontrol.php", - "generated/pcntl.php", - "generated/pcre.php", - "generated/pgsql.php", - "generated/posix.php", - "generated/ps.php", - "generated/pspell.php", - "generated/readline.php", - "generated/rnp.php", - "generated/rpminfo.php", - "generated/rrd.php", - "generated/sem.php", - "generated/session.php", - "generated/shmop.php", - "generated/sockets.php", - "generated/sodium.php", - "generated/solr.php", - "generated/spl.php", - "generated/sqlsrv.php", - "generated/ssdeep.php", - "generated/ssh2.php", - "generated/stream.php", - "generated/strings.php", - "generated/swoole.php", - "generated/uodbc.php", - "generated/uopz.php", - "generated/url.php", - "generated/var.php", - "generated/xdiff.php", - "generated/xml.php", - "generated/xmlrpc.php", - "generated/yaml.php", - "generated/yaz.php", - "generated/zip.php", - "generated/zlib.php" - ], - "classmap": [ - "lib/DateTime.php", - "lib/DateTimeImmutable.php", - "lib/Exceptions/", - "deprecated/Exceptions/", - "generated/Exceptions/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "PHP core functions that throw exceptions instead of returning FALSE on error (a less-abandoned fork of thecodingmachine/safe)", - "support": { - "issues": "https://github.com/shish/safe/issues", - "source": "https://github.com/shish/safe/tree/v2.6.4" - }, - "funding": [ - { - "url": "https://github.com/OskarStark", - "type": "github" - }, - { - "url": "https://github.com/shish", - "type": "github" - }, - { - "url": "https://github.com/staabm", - "type": "github" - } - ], - "time": "2024-12-18T13:36:07+00:00" - }, { "name": "slevomat/coding-standard", "version": "8.15.0", @@ -9177,64 +8026,6 @@ } ], "time": "2024-03-03T12:36:25+00:00" - }, - { - "name": "webmozart/assert", - "version": "1.11.0", - "source": { - "type": "git", - "url": "https://github.com/webmozarts/assert.git", - "reference": "11cb2199493b2f8a3b53e7f19068fc6aac760991" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/webmozarts/assert/zipball/11cb2199493b2f8a3b53e7f19068fc6aac760991", - "reference": "11cb2199493b2f8a3b53e7f19068fc6aac760991", - "shasum": "" - }, - "require": { - "ext-ctype": "*", - "php": "^7.2 || ^8.0" - }, - "conflict": { - "phpstan/phpstan": "<0.12.20", - "vimeo/psalm": "<4.6.1 || 4.6.2" - }, - "require-dev": { - "phpunit/phpunit": "^8.5.13" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.10-dev" - } - }, - "autoload": { - "psr-4": { - "Webmozart\\Assert\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Bernhard Schussek", - "email": "bschussek@gmail.com" - } - ], - "description": "Assertions to validate method input/output with nice error messages.", - "keywords": [ - "assert", - "check", - "validate" - ], - "support": { - "issues": "https://github.com/webmozarts/assert/issues", - "source": "https://github.com/webmozarts/assert/tree/1.11.0" - }, - "time": "2022-06-03T18:03:27+00:00" } ], "aliases": [], diff --git a/src/Form/MenuItemType.php b/src/Form/MenuItemType.php index 641cf1b..e3c07f8 100644 --- a/src/Form/MenuItemType.php +++ b/src/Form/MenuItemType.php @@ -4,6 +4,7 @@ namespace App\Form; use App\Entity\MenuItem; use App\Repository\MenuItemRepository; +use Doctrine\DBAL\Types\TextType; use Doctrine\ORM\QueryBuilder; use Override; use Symfony\Bridge\Doctrine\Form\Type\EntityType; @@ -13,6 +14,7 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Uid\Ulid; +use Symfony\Component\Validator\Constraints\NotBlank; use function array_map; use function assert; @@ -22,41 +24,21 @@ final class MenuItemType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options): void { $item = $options['data']; - assert($item instanceof MenuItem); // Ensure it's of the correct type - $vendorId = $item->getFoodVendor()?->getId(); // Use safe navigation operator in case FoodVendor is null + assert($item instanceof MenuItem); - $builder->add('name'); // Basic field + $builder->add('name', \Symfony\Component\Form\Extension\Core\Type\TextType::class, [ + 'constraints' => [ + new NotBlank(), + new \Symfony\Component\Validator\Constraints\Length(['min' => 3]), + ] + ]); $builder->add('aliases', EntityType::class, [ 'class' => MenuItem::class, 'choice_label' => 'name', 'multiple' => true, 'expanded' => true, - 'query_builder' => static function (MenuItemRepository $repository) use ($item, $vendorId): QueryBuilder { - - $ids = $repository->createQueryBuilder('m') - ->select('DISTINCT IDENTITY(m.aliasOf)') - ->where('m.deletedAt IS NULL') - ->andWhere('m.aliasOf IS NOT NULL') - ->getquery(); - $ids = $ids->getScalarResult(); - $ids = array_map(static fn(array $id): Ulid => Ulid::fromBinary($id[1]), $ids); - - // Build the main query with a NOT EXISTS constraint - $qb = $repository->createQueryBuilder('m'); - $qb - ->where('m.foodVendor = :vendorId') - ->andWhere('m.deletedAt IS NULL') - ->andWhere('m.id != :id'); - foreach ($ids as $key => $id) { - $qb->andWhere("m.id != :idBy{$key}"); - $qb->setParameter("idBy{$key}", $id, UlidType::NAME); - } - $qb - ->orderBy('m.name', 'ASC') - ->setParameter('vendorId', $vendorId, UlidType::NAME) // ULID or appropriate type - ->setParameter('id', $item->getId()); // ULID or appropriate type - return $qb; - }, + 'query_builder' => static fn (MenuItemRepository $repository): QueryBuilder + => $repository->getSuitableAliasQueryBuilder($item), ]); } diff --git a/src/Repository/MenuItemRepository.php b/src/Repository/MenuItemRepository.php index dbcb4f2..51ca1a3 100644 --- a/src/Repository/MenuItemRepository.php +++ b/src/Repository/MenuItemRepository.php @@ -5,6 +5,8 @@ namespace App\Repository; use App\Entity\MenuItem; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; +use Symfony\Bridge\Doctrine\Types\UlidType; +use Symfony\Component\Uid\Ulid; /** * @extends ServiceEntityRepository @@ -16,28 +18,29 @@ final class MenuItemRepository extends ServiceEntityRepository parent::__construct($registry, MenuItem::class); } - // /** - // * @return MenuItem[] Returns an array of MenuItem objects - // */ - // public function findByExampleField($value): array - // { - // return $this->createQueryBuilder('m') - // ->andWhere('m.exampleField = :val') - // ->setParameter('val', $value) - // ->orderBy('m.id', 'ASC') - // ->setMaxResults(10) - // ->getQuery() - // ->getResult() - // ; - // } + public function getSuitableAliasQueryBuilder(MenuItem $menuItem): \Doctrine\ORM\QueryBuilder + { + $ids = $this->createQueryBuilder('m') + ->select('DISTINCT IDENTITY(m.aliasOf)') + ->where('m.deletedAt IS NULL') + ->andWhere('m.aliasOf IS NOT NULL') + ->getquery(); + $ids = $ids->getScalarResult(); + $ids = array_map(static fn(array $id): Ulid => Ulid::fromBinary($id[1]), $ids); - // public function findOneBySomeField($value): ?MenuItem - // { - // return $this->createQueryBuilder('m') - // ->andWhere('m.exampleField = :val') - // ->setParameter('val', $value) - // ->getQuery() - // ->getOneOrNullResult() - // ; - // } + $qb = $this->createQueryBuilder('m'); + $qb + ->where('m.foodVendor = :vendorId') + ->andWhere('m.deletedAt IS NULL') + ->andWhere('m.id != :id'); + foreach ($ids as $key => $id) { + $qb->andWhere("m.id != :idBy{$key}") + ->setParameter("idBy{$key}", $id, UlidType::NAME); + } + $qb + ->orderBy('m.name', 'ASC') + ->setParameter('vendorId', $menuItem->getFoodVendor()->getId(), UlidType::NAME) + ->setParameter('id', $menuItem->getId(), UlidType::NAME); + return $qb; + } } diff --git a/templates/menu_item/show.html.twig b/templates/menu_item/show.html.twig index 80731e6..a07b969 100644 --- a/templates/menu_item/show.html.twig +++ b/templates/menu_item/show.html.twig @@ -21,6 +21,18 @@ {{ menu_item.aliasOf.name }} {% endif %} + {% if(menu_item.aliases|length > 0) %} + + Aliases + + + + + {% endif %} diff --git a/tests/Controller/FoodVendorControllerTest.php b/tests/Controller/FoodVendorControllerTest.php index 5e50526..d000d79 100644 --- a/tests/Controller/FoodVendorControllerTest.php +++ b/tests/Controller/FoodVendorControllerTest.php @@ -9,6 +9,7 @@ use Override; use function sprintf; + final class FoodVendorControllerTest extends DbWebTest { private string $path = '/food/vendor/'; @@ -23,15 +24,20 @@ final class FoodVendorControllerTest extends DbWebTest public function testNew(): void { + self::assertSame(0, $this->repository->count([])); $this->client->request('GET', sprintf('%snew', $this->path)); self::assertResponseStatusCodeSame(200); $this->client->submitForm('Save', [ - 'food_vendor[name]' => 'Testing', + 'food_vendor[name]' => 'TestingNew', ]); + $newVendor = $this->repository->findOneBy(['name' => 'TestingNew']); + $this->assertInstanceof(FoodVendor::class, $newVendor); self::assertSame(1, $this->repository->count([])); + + } public function testShow(): void diff --git a/tests/Controller/MenuItemControllerTest.php b/tests/Controller/MenuItemControllerTest.php index 4d6dd02..05b2a1e 100644 --- a/tests/Controller/MenuItemControllerTest.php +++ b/tests/Controller/MenuItemControllerTest.php @@ -14,6 +14,9 @@ final class MenuItemControllerTest extends DbWebTest { private string $path = '/menu/item/'; private FoodVendor $vendor; + private MenuItem $menuItem; + private MenuItem $aliasOne; + private MenuItem $aliasTwo; #[Override] public function setUp(): void @@ -23,7 +26,30 @@ final class MenuItemControllerTest extends DbWebTest $this->vendor->setName('Food Vendor'); $this->manager->persist($this->vendor); + + $this->menuItem = new MenuItem; + $this->menuItem->setName('Testing 1 2'); + + $this->vendor->addMenuItem($this->menuItem); + $this->manager->persist($this->vendor); + $this->manager->persist($this->menuItem); + + $this->aliasOne = new MenuItem; + $this->aliasOne->setName('AliasOne'); + $this->aliasOne->setFoodVendor($this->vendor); + $this->menuItem->addAlias($this->aliasOne); + + $this->aliasTwo = new MenuItem; + $this->aliasTwo->setName('AliasTwo'); + $this->aliasTwo->setFoodVendor($this->vendor); + $this->aliasTwo->setAliasOf($this->menuItem); + $this->menuItem->addAlias($this->aliasTwo); + + $this->manager->persist($this->aliasOne); + $this->manager->persist($this->aliasTwo); + $this->manager->persist($this->menuItem); $this->manager->flush(); + } #[Override] @@ -34,70 +60,82 @@ final class MenuItemControllerTest extends DbWebTest public function testShow(): void { - $menuItem = new MenuItem; - $menuItem->setName('Testing 1 2'); - $this->vendor->addMenuItem($menuItem); - $this->manager->persist($this->vendor); - $this->manager->persist($menuItem); - $this->manager->flush(); - - $crawler = $this->client->request('GET', "{$this->path}{$menuItem->getId()}"); + $crawler = $this->client->request('GET', "{$this->path}{$this->menuItem->getId()}"); $idValue = $crawler->filter( '.table > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2)' )->text(); $nameValue = $crawler->filter( '.table > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(2)' )->text(); + + $aliasTwoNameValue = $crawler->filter( + '.table > tbody:nth-child(1) > tr:nth-child(3) > td:nth-child(2) > ul:nth-child(1) > li:nth-child(1)' + )->text(); + $aliasOneNameValue = $crawler->filter( + '.table > tbody:nth-child(1) > tr:nth-child(3) > td:nth-child(2) > ul:nth-child(1) > li:nth-child(2)' + )->text(); self::assertResponseStatusCodeSame(200); - $this->assertEquals($idValue, $menuItem->getId()); - $this->assertEquals($nameValue, $menuItem->getName()); + $this->assertEquals($idValue, $this->menuItem->getId()); + $this->assertEquals($nameValue, $this->menuItem->getName()); + $this->assertEquals($aliasTwoNameValue, $this->aliasOne->getName()); + $this->assertEquals($aliasOneNameValue, $this->aliasTwo->getName()); } public function testEdit(): void { - $menuItem = new MenuItem; - $menuItem->setName('Testing 1 2'); - - $this->vendor->addMenuItem($menuItem); - $this->manager->persist($this->vendor); - $this->manager->persist($menuItem); - $this->manager->flush(); - - $crawler = $this->client->request('GET', sprintf('%s%s/edit', $this->path, $menuItem->getId())); + $crawler = $this->client->request('GET', sprintf('%s%s/edit', $this->path, $this->menuItem->getId())); $nameElem = $crawler->filter('#menu_item_name'); $this->assertEquals( 'Testing 1 2', $nameElem->attr('value') ); - $this->client->submitForm('Update', [ - 'menu_item[name]' => 'Testing-1', - ]); + $form = $crawler->selectButton('Update')->form(); + $form['menu_item[name]'] = 'Testing-1'; + $form['menu_item[aliases]'][0]->untick(); - self::assertResponseRedirects(sprintf('/menu/item/%s', $menuItem->getId())); + $this->client->submit($form); + + self::assertResponseRedirects(sprintf('/menu/item/%s', $this->menuItem->getId())); + $menuItem = $this->repository->find($this->menuItem->getId()); + $this->assertEquals('Testing-1', $menuItem->getName()); + $this->assertEquals(1, $menuItem->getAliases()->count()); + $aliasOne = $this->repository->find($this->aliasOne->getId()); + $this->assertNull($aliasOne->getAliasOf()); } + public function testEditInvalid(): void + { + $crawler = $this->client->request('GET', sprintf('%s%s/edit', $this->path, $this->menuItem->getId())); + $nameElem = $crawler->filter('#menu_item_name'); + $this->assertEquals( + 'Testing 1 2', + $nameElem->attr('value') + ); + + $form = $crawler->selectButton('Update')->form(); + $form['menu_item[name]'] = 'a'; + + $this->client->submit($form); + + self::assertResponseStatusCodeSame(422); + } + + public function testDelete(): void { - $menuItem = new MenuItem; - $menuItem->setName('Testing 1 2'); - - $this->vendor->addMenuItem($menuItem); - $this->manager->persist($this->vendor); - $this->manager->persist($menuItem); - $order = new FoodOrder; $order->setFoodVendor($this->vendor); $this->manager->persist($order); $this->manager->flush(); - $this->assertFalse($menuItem->isDeleted()); + $this->assertFalse($this->menuItem->isDeleted()); - $this->client->request('GET', "{$this->path}{$menuItem->getId()}"); + $this->client->request('GET', "{$this->path}{$this->menuItem->getId()}"); $this->client->submitForm('Delete', []); - $menuItem = $this->repository->find($menuItem->getId()); + $menuItem = $this->repository->find($this->menuItem->getId()); $this->assertTrue($menuItem->isDeleted()); @@ -105,7 +143,7 @@ final class MenuItemControllerTest extends DbWebTest $count = $crawler->filter('body > main:nth-child(2) > div:nth-child(5)') ->children() ->count(); - $this->assertSame(0, $count); + $this->assertSame(2, $count); $this->assertResponseIsSuccessful(); diff --git a/tests/Entity/MenuItemTest.php b/tests/Entity/MenuItemTest.php index ccc34d6..a30de40 100644 --- a/tests/Entity/MenuItemTest.php +++ b/tests/Entity/MenuItemTest.php @@ -27,4 +27,29 @@ final class MenuItemTest extends TestCase $this->assertTrue($item->isDeleted()); $this->assertInstanceOf(DateTimeImmutable::class, $item->getDeletedAt()); } + + public function testMenuItemAlias(): void + { + $item = new MenuItem; + $item->setName('Test'); + $this->assertEquals('Test', $item->getName()); + + $vendor = new FoodVendor; + $vendor->setName('Test'); + $item->setFoodVendor($vendor); + + $item2 = new MenuItem; + $item2->setName('Test2'); + $item2->setFoodVendor($vendor); + + $item->addAlias($item2); + + $this->assertCount(1, $item->getAliases()); + $this->assertSame($item, $item2->getAliasOf()); + + $item->removeAlias($item2); + $this->assertCount(0, $item->getAliases()); + $this->assertNull($item2->getAliasOf()); + + } }