From 7674b6a6bd929d61c7460ffeee286cdba6b8bbf8 Mon Sep 17 00:00:00 2001 From: lubiana Date: Sun, 15 Sep 2024 22:11:42 +0200 Subject: [PATCH] add mutation testing --- .forgejo/workflows/pull_request.yml | 11 +- .forgejo/workflows/push.yml | 2 +- composer.json | 7 +- composer.lock | 1126 ++++++++++++++++- infection.json5 | 19 + phpunit.xml.dist | 6 +- src/Command/FakeDataCommand.php | 35 - .../MigrateOrderitemsMenuitemsCommand.php | 66 - src/Controller/FoodOrderController.php | 6 +- src/Controller/MenuItemController.php | 1 - src/Entity/FoodOrder.php | 2 +- src/Entity/FoodVendor.php | 4 +- src/Form/FoodOrderType.php | 10 - src/Form/UserNameFormType.php | 13 +- src/Repository/FoodOrderRepository.php | 4 +- src/Service/FakeData.php | 100 -- tests/Controller/FoodVendorControllerTest.php | 8 +- tests/Controller/HomeControllerTest.php | 15 + tests/Controller/OrderItemControllerTest.php | 25 +- tests/Entity/FoodOrderTest.php | 3 +- tests/Entity/FoodVendorTest.php | 20 + tests/Entity/MenuItemTest.php | 3 + 22 files changed, 1239 insertions(+), 247 deletions(-) create mode 100644 infection.json5 delete mode 100644 src/Command/FakeDataCommand.php delete mode 100644 src/Command/MigrateOrderitemsMenuitemsCommand.php delete mode 100644 src/Service/FakeData.php diff --git a/.forgejo/workflows/pull_request.yml b/.forgejo/workflows/pull_request.yml index 4530c52..3dcf937 100644 --- a/.forgejo/workflows/pull_request.yml +++ b/.forgejo/workflows/pull_request.yml @@ -23,7 +23,16 @@ jobs: - name: lint run: composer lint - name: test - run: composer test + run: composer mutation + - name: Add comment to pull request + run: | + cat var/log/infection.txt >> /tmp/pull-request-comment + cat var/log/summary.log >> /tmp/pull-request-comment + curl -X POST \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Content-Type: application/json" \ + -d '{"body": "$(cat /tmp/pull-request-comment)"}' \ + "${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}/issues/${GITHUB_EVENT_PULL_REQUEST_NUMBER}/comments" - 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 837b78f..259579e 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 test + run: composer mutation - name: GIT commit and push all changed files env: CI_COMMIT_MESSAGE: Continuous Integration Fixes diff --git a/composer.json b/composer.json index 74eed1e..4a14071 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,7 @@ "symfony/yaml": "7.1.*" }, "require-dev": { + "infection/infection": "^0.29.6", "lubiana/code-quality": "^1.7.2", "phpunit/phpunit": "^9.6.20", "symfony/browser-kit": "7.1.*", @@ -38,7 +39,8 @@ "php-http/discovery": true, "symfony/flex": true, "symfony/runtime": true, - "dealerdirect/phpcodesniffer-composer-installer": true + "dealerdirect/phpcodesniffer-composer-installer": true, + "infection/extension-installer": true }, "sort-packages": true, "platform": { @@ -81,7 +83,8 @@ "rector", "ecs --fix || ecs --fix" ], - "test": "bin/phpunit" + "test": "bin/phpunit", + "mutation": "infection --threads=8 --show-mutations" }, "conflict": { "symfony/symfony": "*" diff --git a/composer.lock b/composer.lock index 23daf70..ed05a1b 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": "0bd724c70530c5264dc15e7e7803e7e6", + "content-hash": "bc40af7a698e5c0c5eb44b337b8b1274", "packages": [ { "name": "doctrine/cache", @@ -5163,6 +5163,239 @@ } ], "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.1", + "source": { + "type": "git", + "url": "https://github.com/composer/pcre.git", + "reference": "63aaeac21d7e775ff9bc9d45021e1745c97521c4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/pcre/zipball/63aaeac21d7e775ff9bc9d45021e1745c97521c4", + "reference": "63aaeac21d7e775ff9bc9d45021e1745c97521c4", + "shasum": "" + }, + "require": { + "php": "^7.4 || ^8.0" + }, + "conflict": { + "phpstan/phpstan": "<1.11.10" + }, + "require-dev": { + "phpstan/phpstan": "^1.11.10", + "phpstan/phpstan-strict-rules": "^1.1", + "phpunit/phpunit": "^8 || ^9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.x-dev" + }, + "phpstan": { + "includes": [ + "extension.neon" + ] + } + }, + "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.1" + }, + "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-08-27T18:44:43+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", @@ -5241,6 +5474,493 @@ }, "time": "2023-01-05T11:28:13+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.6", + "source": { + "type": "git", + "url": "https://github.com/infection/infection.git", + "reference": "a8510c1d472892dda2ae32e2c4b2e795533db810" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/infection/infection/zipball/a8510c1d472892dda2ae32e2c4b2e795533db810", + "reference": "a8510c1d472892dda2ae32e2c4b2e795533db810", + "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.2.10", + "nikic/php-parser": "^5.0", + "ondram/ci-detector": "^4.1.0", + "php": "^8.1", + "sanmai/later": "^0.1.1", + "sanmai/pipeline": "^5.1 || ^6", + "sebastian/diff": "^3.0.2 || ^4.0 || ^5.0 || ^6.0", + "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", + "thecodingmachine/safe": "^2.1.2", + "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", + "phpspec/prophecy": "^1.15", + "phpspec/prophecy-phpunit": "^2.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", + "thecodingmachine/phpstan-safe-rule": "^1.2.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.6" + }, + "funding": [ + { + "url": "https://github.com/infection", + "type": "github" + }, + { + "url": "https://opencollective.com/infection", + "type": "open_collective" + } + ], + "time": "2024-06-21T10:21:05+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", @@ -5455,6 +6175,84 @@ }, "time": "2024-07-01T20:03:41+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", @@ -6159,6 +6957,135 @@ ], "time": "2024-08-23T09:03:01+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": "v6.11", + "source": { + "type": "git", + "url": "https://github.com/sanmai/pipeline.git", + "reference": "a5fa2a6c6ca93efa37e7c24aab72f47448a6b110" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sanmai/pipeline/zipball/a5fa2a6c6ca93efa37e7c24aab72f47448a6b110", + "reference": "a5fa2a6c6ca93efa37e7c24aab72f47448a6b110", + "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/v6.11" + }, + "funding": [ + { + "url": "https://github.com/sanmai", + "type": "github" + } + ], + "time": "2024-06-15T03:11:19+00:00" + }, { "name": "sebastian/cli-parser", "version": "1.0.2", @@ -7805,6 +8732,145 @@ ], "time": "2024-08-08T08:43:50+00:00" }, + { + "name": "thecodingmachine/safe", + "version": "v2.5.0", + "source": { + "type": "git", + "url": "https://github.com/thecodingmachine/safe.git", + "reference": "3115ecd6b4391662b4931daac4eba6b07a2ac1f0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thecodingmachine/safe/zipball/3115ecd6b4391662b4931daac4eba6b07a2ac1f0", + "reference": "3115ecd6b4391662b4931daac4eba6b07a2ac1f0", + "shasum": "" + }, + "require": { + "php": "^8.0" + }, + "require-dev": { + "phpstan/phpstan": "^1.5", + "phpunit/phpunit": "^9.5", + "squizlabs/php_codesniffer": "^3.2", + "thecodingmachine/phpstan-strict-rules": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.2.x-dev" + } + }, + "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/gmp.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/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", + "support": { + "issues": "https://github.com/thecodingmachine/safe/issues", + "source": "https://github.com/thecodingmachine/safe/tree/v2.5.0" + }, + "time": "2023-04-05T11:54:14+00:00" + }, { "name": "theseer/tokenizer", "version": "1.2.3", @@ -7854,6 +8920,64 @@ } ], "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/infection.json5 b/infection.json5 new file mode 100644 index 0000000..e6f50cc --- /dev/null +++ b/infection.json5 @@ -0,0 +1,19 @@ +{ + "$schema": "vendor/infection/infection/resources/schema.json", + "source": { + "directories": [ + "src" + ] + }, + "timeout": 30, + "logs": { + "text": "var/log/infection.txt", + "summary": "var/log/summary.log", + }, + "mutators": { + "@default": true, + "global-ignore": [ + "App\\Service\\Favicon::__toString" + ] + } +} \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4e78739..e0c28a4 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -7,6 +7,8 @@ colors="true" bootstrap="tests/bootstrap.php" convertDeprecationsToExceptions="true" + executionOrder="random" + resolveDependencies="true" > @@ -28,10 +30,6 @@ src - - src/Command - src/Service/FakeData.php - diff --git a/src/Command/FakeDataCommand.php b/src/Command/FakeDataCommand.php deleted file mode 100644 index c4fdd5d..0000000 --- a/src/Command/FakeDataCommand.php +++ /dev/null @@ -1,35 +0,0 @@ -fakeData->resetDb(); - $this->fakeData->generate(); - - $io->success('Added some fake data to database'); - return Command::SUCCESS; - } -} diff --git a/src/Command/MigrateOrderitemsMenuitemsCommand.php b/src/Command/MigrateOrderitemsMenuitemsCommand.php deleted file mode 100644 index 101d354..0000000 --- a/src/Command/MigrateOrderitemsMenuitemsCommand.php +++ /dev/null @@ -1,66 +0,0 @@ -orderItemRepository->findAll(); - - foreach ($orderItems as $orderItem) { - - $menuItem = $this->menuItemRepository->findOneBy([ - 'name' => $orderItem->getName(), - 'foodVendor' => $orderItem->getFoodOrder() - ->getFoodVendor(), - ]); - - if ($menuItem === null) { - $menuItem = new MenuItem; - $menuItem->setName($orderItem->getName()); - $menuItem->setFoodVendor($orderItem->getFoodOrder()->getFoodVendor()); - $this->entityManager->persist($menuItem); - $this->entityManager->flush(); - $output->writeln(sprintf('Menu item %s added', $menuItem->getName())); - } - $orderItem->setMenuItem($menuItem); - $this->entityManager->persist($orderItem); - } - - $this->entityManager->flush(); - $io->success('You have a new command! Now make it your own! Pass --help to see your options.'); - - return Command::SUCCESS; - } -} diff --git a/src/Controller/FoodOrderController.php b/src/Controller/FoodOrderController.php index f78cd09..250c2e4 100644 --- a/src/Controller/FoodOrderController.php +++ b/src/Controller/FoodOrderController.php @@ -95,7 +95,8 @@ final class FoodOrderController extends AbstractController #[Route('/{id}/close', name: 'app_food_order_close', methods: ['GET'])] public function close(FoodOrder $foodOrder, FoodOrderRepository $repository): Response { - $repository->save($foodOrder->close()); + $foodOrder->close(); + $repository->save(); return $this->redirectToRoute('app_food_order_show', [ 'id' => $foodOrder->getId(), ], Response::HTTP_SEE_OTHER); @@ -104,7 +105,8 @@ final class FoodOrderController extends AbstractController #[Route('/{id}/open', name: 'app_food_order_open', methods: ['GET'])] public function open(FoodOrder $foodOrder, FoodOrderRepository $repository): Response { - $repository->save($foodOrder->open()); + $foodOrder->open(); + $repository->save(); return $this->redirectToRoute('app_food_order_show', [ 'id' => $foodOrder->getId(), ], Response::HTTP_SEE_OTHER); diff --git a/src/Controller/MenuItemController.php b/src/Controller/MenuItemController.php index dc3f63c..ea91e86 100644 --- a/src/Controller/MenuItemController.php +++ b/src/Controller/MenuItemController.php @@ -46,7 +46,6 @@ final class MenuItemController extends AbstractController { if ($this->isCsrfTokenValid('delete' . $menuItem->getId(), $request->getPayload()->getString('_token'))) { $menuItem->delete(); - $entityManager->persist($menuItem); $entityManager->flush(); } diff --git a/src/Entity/FoodOrder.php b/src/Entity/FoodOrder.php index 4fe29f5..0672e5c 100644 --- a/src/Entity/FoodOrder.php +++ b/src/Entity/FoodOrder.php @@ -134,7 +134,7 @@ class FoodOrder public function removeOrderItem(OrderItem $orderItem): static { // set the owning side to null (unless already changed) - if ($this->orderItems->removeElement($orderItem) && $orderItem->getFoodOrder() === $this) { + if ($this->orderItems->removeElement($orderItem)) { $orderItem->setFoodOrder(null); } diff --git a/src/Entity/FoodVendor.php b/src/Entity/FoodVendor.php index e4e430a..b688136 100644 --- a/src/Entity/FoodVendor.php +++ b/src/Entity/FoodVendor.php @@ -80,7 +80,7 @@ class FoodVendor public function removeFoodOrder(FoodOrder $foodOrder): static { // set the owning side to null (unless already changed) - if ($this->foodOrders->removeElement($foodOrder) && $foodOrder->getFoodVendor() === $this) { + if ($this->foodOrders->removeElement($foodOrder)) { $foodOrder->setFoodVendor(null); } @@ -113,7 +113,7 @@ class FoodVendor public function removeMenuItem(MenuItem $menuItem): static { // set the owning side to null (unless already changed) - if ($this->menuItems->removeElement($menuItem) && $menuItem->getFoodVendor() === $this) { + if ($this->menuItems->removeElement($menuItem)) { $menuItem->setFoodVendor(null); } diff --git a/src/Form/FoodOrderType.php b/src/Form/FoodOrderType.php index f45f35f..73eee66 100644 --- a/src/Form/FoodOrderType.php +++ b/src/Form/FoodOrderType.php @@ -2,13 +2,11 @@ namespace App\Form; -use App\Entity\FoodOrder; use App\Entity\FoodVendor; use Override; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\OptionsResolver\OptionsResolver; final class FoodOrderType extends AbstractType { @@ -31,12 +29,4 @@ final class FoodOrderType extends AbstractType $builder->setAction($action); } } - - #[Override] - public function configureOptions(OptionsResolver $resolver): void - { - $resolver->setDefaults([ - 'data_class' => FoodOrder::class, - ]); - } } diff --git a/src/Form/UserNameFormType.php b/src/Form/UserNameFormType.php index 6d2a011..292be12 100644 --- a/src/Form/UserNameFormType.php +++ b/src/Form/UserNameFormType.php @@ -5,7 +5,6 @@ namespace App\Form; use Override; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\OptionsResolver\OptionsResolver; final class UserNameFormType extends AbstractType { @@ -13,17 +12,7 @@ final class UserNameFormType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options): void { $builder - ->add(child: 'username', options: [ - 'required' => false, - ]) + ->add(child: 'username') ; } - - #[Override] - public function configureOptions(OptionsResolver $resolver): void - { - $resolver->setDefaults([ - // Configure your form options here - ]); - } } diff --git a/src/Repository/FoodOrderRepository.php b/src/Repository/FoodOrderRepository.php index c0b2405..0df83aa 100644 --- a/src/Repository/FoodOrderRepository.php +++ b/src/Repository/FoodOrderRepository.php @@ -19,10 +19,8 @@ final class FoodOrderRepository extends ServiceEntityRepository parent::__construct($registry, FoodOrder::class); } - public function save(FoodOrder $order): void + public function save(): void { - $this->getEntityManager() - ->persist($order); $this->getEntityManager() ->flush(); } diff --git a/src/Service/FakeData.php b/src/Service/FakeData.php deleted file mode 100644 index 379f8e7..0000000 --- a/src/Service/FakeData.php +++ /dev/null @@ -1,100 +0,0 @@ -orderItemRepository->findAll() as $item) { - $this->entityManager->remove($item); - } - foreach ($this->foodOrderRepository->findAll() as $item) { - $this->entityManager->remove($item); - } - foreach ($this->foodVendorRepository->findAll() as $item) { - $this->entityManager->remove($item); - } - } - - public function generate(int $vendorAmount = 3, int $orderAmount = 4, int $itemAmount = 10): void - { - $vendors = $this->generateVendors($vendorAmount); - foreach ($vendors as $vendor) { - $orders = $this->generateOrdersForVendor($vendor, $orderAmount); - foreach ($orders as $order) { - $this->generateItemsForOrder($order, $itemAmount); - } - } - $this->entityManager->flush(); - } - - /** - * @return FoodVendor[] - */ - public function generateVendors(int $amount = 10): array - { - $vendors = []; - foreach (range(1, $amount) as $i) { - $vendor = new FoodVendor; - $vendor->setName('Food Vendor ' . $i); - $this->entityManager->persist($vendor); - $vendors[] = $vendor; - } - return $vendors; - } - - /** - * @return FoodOrder[] - */ - public function generateOrdersForVendor(FoodVendor $vendor, int $amount = 10): array - { - $orders = []; - foreach (range(1, $amount) as $i) { - $order = new FoodOrder; - $order->setFoodVendor($vendor); - if ($i % 2 === 0) { - $order->close(); - } - $this->entityManager->persist($order); - $orders[] = $order; - } - return $orders; - } - - /** - * @return OrderItem[] - */ - public function generateItemsForOrder(FoodOrder $order, int $amount = 10): array - { - $items = []; - foreach (range(1, $amount) as $i) { - $item = new OrderItem; - $item->setName('Item ' . $i); - $item->setFoodOrder($order); - if ($i % 2 === 0) { - $item->setExtras('Extra ' . $i); - } - $this->entityManager->persist($item); - $items[] = $item; - } - return $items; - } -} diff --git a/tests/Controller/FoodVendorControllerTest.php b/tests/Controller/FoodVendorControllerTest.php index 6c4c52b..b475fa1 100644 --- a/tests/Controller/FoodVendorControllerTest.php +++ b/tests/Controller/FoodVendorControllerTest.php @@ -118,7 +118,13 @@ final class FoodVendorControllerTest extends DbWebTest $this->manager->persist($fixture); $this->manager->flush(); - $this->client->request('GET', sprintf('%s%s/edit', $this->path, $fixture->getId())); + $crawler = $this->client->request('GET', sprintf('%s%s/edit', $this->path, $fixture->getId())); + $this->assertSame( + $crawler->filter('#food_vendor_name') + ->last() + ->attr('value', ''), + 'Value' + ); $this->client->submitForm('Update', [ 'food_vendor[name]' => 'Something New', diff --git a/tests/Controller/HomeControllerTest.php b/tests/Controller/HomeControllerTest.php index 821e8f4..cc6080c 100644 --- a/tests/Controller/HomeControllerTest.php +++ b/tests/Controller/HomeControllerTest.php @@ -34,6 +34,21 @@ final class HomeControllerTest extends DbWebTest self::assertResponseStatusCodeSame(302); self::assertResponseHeaderSame('Location', '/food/order/list'); self::assertResponseCookieValueSame('username', 'Testing-1'); + + $crawler = $this->client->request( + 'GET', + '/username', + ); + + self::assertResponseStatusCodeSame(200); + + $this->assertSame( + $crawler->filter('#user_name_form_username') + ->last() + ->attr('value', ''), + 'Testing-1' + ); + } public function testRemoveUsername(): void diff --git a/tests/Controller/OrderItemControllerTest.php b/tests/Controller/OrderItemControllerTest.php index 1c65fb8..2c9c9ad 100644 --- a/tests/Controller/OrderItemControllerTest.php +++ b/tests/Controller/OrderItemControllerTest.php @@ -38,6 +38,16 @@ final class OrderItemControllerTest extends DbWebTest $this->menuItem->setName('Testing'); $this->menuItem->setFoodVendor($this->vendor); + $vendor2 = new FoodVendor; + $vendor2->setName('Vendor 2'); + + $menuItem2 = new MenuItem; + $menuItem2->setName('Testing2'); + $menuItem2->setFoodVendor($vendor2); + + $this->manager->persist($vendor2); + $this->manager->persist($menuItem2); + $this->manager->persist($this->menuItem); $this->manager->flush(); @@ -46,11 +56,16 @@ final class OrderItemControllerTest extends DbWebTest public function testNew(): void { - $this->client->request( + $crawler = $this->client->request( 'GET', sprintf('%snew/%s', $this->path, $this->order->getId()) ); + $children = $crawler->filter('body > main:nth-child(2) > div:nth-child(5)') + ->children(); + + $this->assertCount(1, $children); + self::assertResponseStatusCodeSame(200); $this->client->submitForm('Save', [ @@ -61,7 +76,9 @@ final class OrderItemControllerTest extends DbWebTest self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId())); self::assertSame(1, $this->repository->count([])); - self::assertSame(1, $this->menuItemRepository->count([])); + self::assertSame(1, $this->menuItemRepository->count([ + 'foodVendor' => $this->vendor->getId(), + ])); } public function testNewOrderClosed(): void @@ -98,7 +115,7 @@ final class OrderItemControllerTest extends DbWebTest self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId())); self::assertSame(1, $this->repository->count([])); - self::assertSame(2, $this->menuItemRepository->count([])); + self::assertSame(3, $this->menuItemRepository->count([])); } public function testRemove(): void @@ -171,7 +188,7 @@ final class OrderItemControllerTest extends DbWebTest self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId())); self::assertSame(1, $this->repository->count([])); - self::assertSame(2, $this->menuItemRepository->count([])); + self::assertSame(3, $this->menuItemRepository->count([])); } diff --git a/tests/Entity/FoodOrderTest.php b/tests/Entity/FoodOrderTest.php index 08fe6e6..5ed5ca7 100644 --- a/tests/Entity/FoodOrderTest.php +++ b/tests/Entity/FoodOrderTest.php @@ -16,8 +16,9 @@ final class FoodOrderTest extends TestCase $order->addOrderItem($orderItem); $order->addOrderItem($orderItem); $this->assertCount(1, $order->getOrderItems()); + $this->assertSame($order, $orderItem->getFoodOrder()); $order->removeOrderItem($orderItem); $this->assertCount(0, $order->getOrderItems()); - + $this->assertNull($orderItem->getFoodOrder()); } } diff --git a/tests/Entity/FoodVendorTest.php b/tests/Entity/FoodVendorTest.php index 8df1836..daa90c6 100644 --- a/tests/Entity/FoodVendorTest.php +++ b/tests/Entity/FoodVendorTest.php @@ -22,9 +22,16 @@ final class FoodVendorTest extends TestCase $vendor->addFoodOrder($order1); $vendor->addFoodOrder($order1); $this->assertCount(1, $vendor->getFoodOrders()); + $this->assertSame($vendor, $order1->getFoodVendor()); $vendor->removeFoodOrder($order1); $this->assertCount(0, $vendor->getFoodOrders()); + $this->assertNull($order1->getFoodVendor()); + } + + public function testMenuItem(): void + { + $vendor = new FoodVendor; $menuItem1 = new MenuItem; $menuItem2 = new MenuItem; $this->assertCount(0, $vendor->getMenuItems()); @@ -33,11 +40,24 @@ final class FoodVendorTest extends TestCase $this->assertCount(1, $vendor->getMenuItems()); $vendor->removeMenuItem($menuItem1); $this->assertCount(0, $vendor->getMenuItems()); + $this->assertNull($menuItem1->getFoodVendor()); $vendor->addMenuItem($menuItem1); $menuItem2->delete(); $vendor->addMenuItem($menuItem2); $this->assertCount(1, $vendor->getMenuItems()); $this->assertCount(2, $vendor->getMenuItems(true)); + } + public function testRemoveForeignMenuItem(): void + { + $vendor1 = new FoodVendor; + $vendor2 = new FoodVendor; + $item1 = new MenuItem; + + $vendor1->addMenuItem($item1); + $this->assertCount(1, $vendor1->getMenuItems()); + $vendor2->removeMenuItem($item1); + $this->assertCount(1, $vendor1->getMenuItems()); + $this->assertSame($vendor1, $item1->getFoodVendor()); } } diff --git a/tests/Entity/MenuItemTest.php b/tests/Entity/MenuItemTest.php index 4a0fd91..ccc34d6 100644 --- a/tests/Entity/MenuItemTest.php +++ b/tests/Entity/MenuItemTest.php @@ -4,6 +4,7 @@ namespace App\Tests\Entity; use App\Entity\FoodVendor; use App\Entity\MenuItem; +use DateTimeImmutable; use PHPUnit\Framework\TestCase; final class MenuItemTest extends TestCase @@ -21,7 +22,9 @@ final class MenuItemTest extends TestCase $this->assertEquals($vendor, $item->getFoodVendor()); $this->assertFalse($item->isDeleted()); + $this->assertNull($item->getDeletedAt()); $item->delete(); $this->assertTrue($item->isDeleted()); + $this->assertInstanceOf(DateTimeImmutable::class, $item->getDeletedAt()); } } -- 2.39.5