Compare commits

..

No commits in common. "main" and "0.2.0" have entirely different histories.
main ... 0.2.0

52 changed files with 2190 additions and 5556 deletions

4
.env
View file

@ -28,7 +28,3 @@ DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4" # DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
# DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8" # DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8"
###< doctrine/doctrine-bundle ### ###< doctrine/doctrine-bundle ###
###> nelmio/cors-bundle ###
CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$'
###< nelmio/cors-bundle ###

View file

@ -4,3 +4,4 @@ APP_SECRET='$ecretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=999999 SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_APP_ENV=panther PANTHER_APP_ENV=panther
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots
DATABASE_URL="sqlite:///%kernel.project_dir%/var/test-data.db"

View file

@ -23,7 +23,19 @@ jobs:
- name: lint - name: lint
run: composer lint run: composer lint
- name: test - name: test
run: composer 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"
- name: GIT commit and push all changed files - name: GIT commit and push all changed files
env: env:
CI_COMMIT_MESSAGE: Continuous Integration Fixes CI_COMMIT_MESSAGE: Continuous Integration Fixes

View file

@ -27,7 +27,7 @@ jobs:
- name: lint - name: lint
run: composer lint run: composer lint
- name: test - name: test
run: composer test run: composer mutation
- name: GIT commit and push all changed files - name: GIT commit and push all changed files
env: env:
CI_COMMIT_MESSAGE: Continuous Integration Fixes CI_COMMIT_MESSAGE: Continuous Integration Fixes

19
.gitignore vendored
View file

@ -1,3 +1,4 @@
###> symfony/framework-bundle ### ###> symfony/framework-bundle ###
/.env.local /.env.local
/.env.local.php /.env.local.php
@ -7,13 +8,17 @@
/var/ /var/
/vendor/ /vendor/
###< symfony/framework-bundle ### ###< symfony/framework-bundle ###
###> symfony/phpunit-bridge ###
.phpunit.result.cache
/phpunit.xml
###< symfony/phpunit-bridge ###
###> phpunit/phpunit ###
/phpunit.xml
.phpunit.result.cache
###< phpunit/phpunit ###
.idea/ .idea/
/deploy/var/ /deploy/var/
/deploy/app/ /deploy/app/
###> phpunit/phpunit ###
.phpunit.result.cache
.phpunit.cache
###< phpunit/phpunit ###
.DS_Store

23
bin/phpunit Executable file
View file

@ -0,0 +1,23 @@
#!/usr/bin/env php
<?php
if (!ini_get('date.timezone')) {
ini_set('date.timezone', 'UTC');
}
if (is_file(dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit')) {
if (PHP_VERSION_ID >= 80000) {
require dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit';
} else {
define('PHPUNIT_COMPOSER_INSTALL', dirname(__DIR__).'/vendor/autoload.php');
require PHPUNIT_COMPOSER_INSTALL;
PHPUnit\TextUI\Command::main();
}
} else {
if (!is_file(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php')) {
echo "Unable to find the `simple-phpunit.php` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
exit(1);
}
require dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php';
}

View file

@ -7,29 +7,18 @@
"php": ">=8.4", "php": ">=8.4",
"ext-ctype": "*", "ext-ctype": "*",
"ext-iconv": "*", "ext-iconv": "*",
"api-platform/doctrine-orm": "^4.0",
"api-platform/symfony": "^4.0",
"doctrine/dbal": "^4.1", "doctrine/dbal": "^4.1",
"doctrine/doctrine-bundle": "^2.12", "doctrine/doctrine-bundle": "^2.12",
"doctrine/doctrine-migrations-bundle": "^3.3.1", "doctrine/doctrine-migrations-bundle": "^3.3.1",
"doctrine/orm": "^3.2.1", "doctrine/orm": "^3.2.1",
"nelmio/cors-bundle": "^2.5",
"phpdocumentor/reflection-docblock": "^5.6",
"phpstan/phpdoc-parser": "^1.33",
"psr/clock": "^1.0", "psr/clock": "^1.0",
"symfony/asset": "7.2.*",
"symfony/console": "7.1.*", "symfony/console": "7.1.*",
"symfony/dotenv": "7.1.*", "symfony/dotenv": "7.1.*",
"symfony/expression-language": "7.2.*",
"symfony/flex": "^2.4.6", "symfony/flex": "^2.4.6",
"symfony/form": "7.1.*", "symfony/form": "7.1.*",
"symfony/framework-bundle": "7.1.*", "symfony/framework-bundle": "7.1.*",
"symfony/property-access": "7.2.*",
"symfony/property-info": "7.2.*",
"symfony/runtime": "7.1.*", "symfony/runtime": "7.1.*",
"symfony/security-bundle": "7.2.*",
"symfony/security-csrf": "7.1.*", "symfony/security-csrf": "7.1.*",
"symfony/serializer": "7.2.*",
"symfony/twig-bundle": "7.1.*", "symfony/twig-bundle": "7.1.*",
"symfony/uid": "7.1.*", "symfony/uid": "7.1.*",
"symfony/validator": "7.1.*", "symfony/validator": "7.1.*",
@ -37,24 +26,24 @@
}, },
"require-dev": { "require-dev": {
"doctrine/doctrine-fixtures-bundle": "^4.0", "doctrine/doctrine-fixtures-bundle": "^4.0",
"liip/test-fixtures-bundle": "^3.2", "infection/infection": "^0.29.6",
"lubiana/code-quality": "^1.7.2", "lubiana/code-quality": "^1.7.2",
"pestphp/pest": "^3.6", "phpunit/phpunit": "^9.6.20",
"symfony/browser-kit": "7.2.*", "symfony/browser-kit": "7.2.*",
"symfony/css-selector": "7.2.*", "symfony/css-selector": "7.2.*",
"symfony/http-client": "7.2.*",
"symfony/maker-bundle": "^1.60", "symfony/maker-bundle": "^1.60",
"symfony/phpunit-bridge": "7.2.*",
"symfony/stopwatch": "7.2.*", "symfony/stopwatch": "7.2.*",
"symfony/web-profiler-bundle": "7.2.*", "symfony/web-profiler-bundle": "7.2.*",
"symplify/config-transformer": "^12.3.4" "symplify/config-transformer": "^12.3.4"
}, },
"config": { "config": {
"allow-plugins": { "allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"pestphp/pest-plugin": true,
"php-http/discovery": true, "php-http/discovery": true,
"symfony/flex": true, "symfony/flex": true,
"symfony/runtime": true "symfony/runtime": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"infection/extension-installer": true
}, },
"sort-packages": true, "sort-packages": true,
"platform": { "platform": {
@ -79,8 +68,7 @@
"symfony/polyfill-php74": "*", "symfony/polyfill-php74": "*",
"symfony/polyfill-php80": "*", "symfony/polyfill-php80": "*",
"symfony/polyfill-php81": "*", "symfony/polyfill-php81": "*",
"symfony/polyfill-php82": "*", "symfony/polyfill-php82": "*"
"symfony/polyfill-php83": "*"
}, },
"scripts": { "scripts": {
"auto-scripts": { "auto-scripts": {
@ -98,7 +86,8 @@
"rector", "rector",
"ecs --fix || ecs --fix" "ecs --fix || ecs --fix"
], ],
"test": "pest --parallel" "test": "bin/phpunit",
"mutation": "infection --threads=8 --show-mutations"
}, },
"conflict": { "conflict": {
"symfony/symfony": "*" "symfony/symfony": "*"

5181
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,14 +1,10 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
use ApiPlatform\Symfony\Bundle\ApiPlatformBundle;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle; use Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle;
use Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle; use Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle;
use Liip\TestFixturesBundle\LiipTestFixturesBundle;
use Nelmio\CorsBundle\NelmioCorsBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle; use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\MakerBundle\MakerBundle; use Symfony\Bundle\MakerBundle\MakerBundle;
use Symfony\Bundle\SecurityBundle\SecurityBundle;
use Symfony\Bundle\TwigBundle\TwigBundle; use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Bundle\WebProfilerBundle\WebProfilerBundle; use Symfony\Bundle\WebProfilerBundle\WebProfilerBundle;
@ -36,17 +32,4 @@ return [
'dev' => true, 'dev' => true,
'test' => true, 'test' => true,
], ],
SecurityBundle::class => [
'all' => true,
],
NelmioCorsBundle::class => [
'all' => true,
],
ApiPlatformBundle::class => [
'all' => true,
],
LiipTestFixturesBundle::class => [
'dev' => true,
'test' => true,
],
]; ];

View file

@ -1,22 +0,0 @@
<?php declare(strict_types=1);
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->extension('api_platform', [
'title' => 'Futtern API',
'version' => '1.0.0',
'show_webby' => false,
'enable_swagger' => true,
'defaults' => [
'stateless' => true,
'cache_headers' => [
'vary' => [
'Content-Type',
'Authorization',
'Origin',
],
],
],
]);
};

View file

@ -1,33 +0,0 @@
<?php declare(strict_types=1);
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->extension('nelmio_cors', [
'defaults' => [
'origin_regex' => true,
'allow_origin' => [
'%env(CORS_ALLOW_ORIGIN)%',
],
'allow_methods' => [
'GET',
'OPTIONS',
'POST',
'PUT',
'PATCH',
'DELETE',
],
'allow_headers' => [
'Content-Type',
'Authorization',
],
'expose_headers' => [
'Link',
],
'max_age' => 3600,
],
'paths' => [
'^/' => null,
],
]);
};

View file

@ -1,40 +0,0 @@
<?php declare(strict_types=1);
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->extension('security', [
'password_hashers' => [
PasswordAuthenticatedUserInterface::class => 'auto',
],
'providers' => [
'users_in_memory' => [
'memory' => null,
],
],
'firewalls' => [
'dev' => [
'pattern' => '^/(_(profiler|wdt)|css|images|js)/',
'security' => false,
],
'main' => [
'lazy' => true,
'provider' => 'users_in_memory',
],
],
'access_control' => null,
]);
if ($containerConfigurator->env() === 'test') {
$containerConfigurator->extension('security', [
'password_hashers' => [
PasswordAuthenticatedUserInterface::class => [
'algorithm' => 'auto',
'cost' => 4,
'time_cost' => 3,
'memory_cost' => 10,
],
],
]);
}
};

View file

@ -1,8 +0,0 @@
<?php declare(strict_types=1);
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
return static function (RoutingConfigurator $routingConfigurator): void {
$routingConfigurator->import('.', 'api_platform')
->prefix('/api');
};

View file

@ -1,7 +0,0 @@
<?php declare(strict_types=1);
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
return static function (RoutingConfigurator $routingConfigurator): void {
$routingConfigurator->import('security.route_loader.logout', 'service');
};

View file

@ -15,6 +15,7 @@ do
cp -r ../../"$path" ./ cp -r ../../"$path" ./
done done
rm ./bin/phpunit
APP_ENV=prod composer install --no-dev -a APP_ENV=prod composer install --no-dev -a
rm -rf ./var/cache rm -rf ./var/cache

View file

@ -26,12 +26,12 @@ ExecStart=/usr/bin/podman run \
--replace \ --replace \
-d \ -d \
--name futtern-php \ --name futtern-php \
--volume %h/futtern/etc/php84/php-fpm.d/www.conf:/etc/php84/php-fpm.d/www.conf \ --volume %h/futtern/etc/php83/php-fpm.d/www.conf:/etc/php83/php-fpm.d/www.conf \
--volume %h/futtern/app:/var/www/html \ --volume %h/futtern/app:/var/www/html \
--volume %h/futtern/app/var:/var/www/html/var \ --volume %h/futtern/app/var:/var/www/html/var \
--env APP_ENV=prod \ --env APP_ENV=prod \
--env APP_SECRET=UwUtHiSisNotSecurePlZcHanGeMe \ --env APP_SECRET=UwUtHiSisNotSecurePlZcHanGeMe \
git.php.fail/lubiana/container/php:8.4-fpm git.php.fail/lubiana/container/php:8.3-fpm
ExecStop=/usr/bin/podman stop \ ExecStop=/usr/bin/podman stop \
--ignore -t 10 \ --ignore -t 10 \
--cidfile=%t/%n.ctr-id --cidfile=%t/%n.ctr-id

20
infection.json5 Normal file
View file

@ -0,0 +1,20 @@
{
"$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",
"ORM\\Column.*"
]
}
}

View file

@ -1,38 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="tests/bootstrap.php"
cacheDirectory=".phpunit.cache"
executionOrder="depends,defects"
shortenArraysForExportThreshold="10"
requireCoverageMetadata="false"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
displayDetailsOnPhpunitDeprecations="true"
failOnPhpunitDeprecation="true"
failOnRisky="true"
failOnWarning="true">
<testsuites>
<testsuite name="default">
<directory>tests/Feature</directory>
<directory>tests/Unit</directory>
</testsuite>
</testsuites>
<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true">
<include>
<directory>src</directory>
</include>
<exclude>
<file>src/Kernel.php</file>
<file>src/Service/Favicon.php</file>
</exclude>
</source>
<php>
<ini name="display_errors" value="1" />
<ini name="error_reporting" value="-1" />
<server name="KERNEL_CLASS" value="App\Kernel" />
<server name="APP_ENV" value="test" force="true" />
<server name="SHELL_VERBOSITY" value="-1" />
</php>
</phpunit>

View file

@ -6,7 +6,9 @@
backupGlobals="false" backupGlobals="false"
colors="true" colors="true"
bootstrap="tests/bootstrap.php" bootstrap="tests/bootstrap.php"
convertDeprecationsToExceptions="false" convertDeprecationsToExceptions="true"
executionOrder="random"
resolveDependencies="true"
> >
<php> <php>
<ini name="display_errors" value="1" /> <ini name="display_errors" value="1" />
@ -14,7 +16,8 @@
<server name="APP_ENV" value="test" force="true" /> <server name="APP_ENV" value="test" force="true" />
<server name="SHELL_VERBOSITY" value="-1" /> <server name="SHELL_VERBOSITY" value="-1" />
<server name="SYMFONY_PHPUNIT_REMOVE" value="" /> <server name="SYMFONY_PHPUNIT_REMOVE" value="" />
<server name="SYMFONY_PHPUNIT_VERSION" value="9.5" /> <server name="SYMFONY_PHPUNIT_VERSION" value="9.6" />
<server name="KERNEL_CLASS" value="App\Kernel" />
</php> </php>
<testsuites> <testsuites>

View file

@ -1,965 +0,0 @@
/* SPDX-License-Identifier: MIT
SPDX-FileCopyrightText: Copyright (c) 2022-2025 zichy
*/
/* Custom properties
========================================
*/
:root {
--f-sans: ui-sans-serif, sans-serif;
--f-body: ui-serif;
--f-heading: var(--f-sans);
--f-form: var(--f-sans);
--f-code: ui-monospace;
--f-size: clamp(1.6rem, 1.75vw, 2rem);
--f-size-small: 0.85em;
--f-size-large: 1.25em;
--f-line: 1.5;
--c-gray: #666;
--c-red: #b30;
--c-yellow: #fe9;
--i-triangle: url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"%3E%3Cpolygon fill="black" points="5 10 10 0 0 0"/%3E%3C/svg%3E');
--w-body: 80ch;
}
/* Dark theme */
@media (prefers-color-scheme: dark) {
:root {
--c-gray: #999;
--c-red: #f99;
--c-yellow: #ff9;
--i-triangle: url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"%3E%3Cpolygon fill="white" points="5 10 10 0 0 0"/%3E%3C/svg%3E');
}
}
/* Globals
========================================
*/
/* Box sizing */
*,
*::before,
*::after {
box-sizing: border-box;
}
/* Text rendering */
* {
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
}
/* Interaction */
::selection {
background: Highlight;
color: HighlightText;
text-shadow: none;
}
*:focus {
outline: 2px solid LinkText;
outline-offset: 0.25rem;
}
/* Font size & Scrolling */
html {
font-size: 62.5%;
scroll-behavior: smooth;
scroll-padding-top: 2rem;
}
/* Backdrop */
::backdrop {
background-color: rgba(255, 255, 255, 0.6);
}
@media (prefers-color-scheme: dark) {
::backdrop {
background-color: rgba(0, 0, 0, 0.6);
}
}
/* Hidden elements */
[hidden] {
display: none;
}
/* Print spacing */
@page {
margin: 15mm 20mm;
}
/* Body
========================================
*/
/* Colors & Typography */
body {
background-color: Canvas;
color: CanvasText;
font-size: var(--f-size);
font-family: var(--f-body);
line-height: var(--f-line);
}
/* Body sizing */
@media screen {
body {
max-width: var(--w-body, 100%);
min-width: 320px;
padding: 2rem;
margin: 0 auto;
overflow-x: hidden;
overflow-y: scroll;
}
}
/* Print colors */
@media print {
body {
background-color: white;
color: black;
}
}
/* Links
========================================
*/
a:any-link {
color: LinkText;
text-decoration: underline;
text-decoration-thickness: 0.125em;
}
a:any-link:hover {
background-color: LinkText;
color: Canvas;
text-decoration-line: none;
}
@media print {
a[href^="http"]::after {
content: ' ('attr(href)')';
font-size: var(--f-size-small);
word-break: break-all;
}
}
/* Media
========================================
*/
/* Reset */
:where(iframe, img, svg, canvas, audio, video) {
display: block;
max-width: 100%;
}
@media print {
:where(audio, video) {
display: none;
}
}
figure {
margin-inline: 0;
break-inside: avoid;
}
/* Image */
img {
height: auto;
position: relative;
}
img::before {
content: '';
background-color: Highlight;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
@media screen {
picture img {
width: 100%;
}
}
/* Video */
video {
width: 100%;
height: auto;
}
/* Iframe */
iframe {
border-style: none;
}
/* Headings
========================================
*/
:where(h1, h2, h3, h4, h5, h6) {
font-family: var(--f-heading);
line-height: calc(var(--f-line) / 1.25);
hyphens: auto;
}
:where(h3, h5) {
color: var(--c-gray);
}
:where(h4, h5, h6) {
text-transform: uppercase;
}
:where(h2, h3, h4, h5, h6):target {
background-color: var(--c-yellow);
color: MarkText;
}
/* Lists
========================================
*/
:where(ul, ol) {
padding-inline-start: 1em;
}
ul {
list-style-type: disc;
}
li::marker {
color: var(--c-gray);
}
li p {
margin: 0;
}
/* Description */
dt {
font-style: italic;
}
/* Navigation */
nav ul {
display: flex;
flex-wrap: wrap;
gap: 0.5rem 2rem;
list-style-type: none;
padding: 0;
}
@media print {
nav {
display: none;
}
}
/* Inline elements
========================================
*/
/* Bold text */
:where(b, strong) {
font-weight: bolder;
}
/* Small text */
small {
font-size: var(--f-size-small);
}
/* Mark */
mark {
background-color: var(--c-yellow);
}
/* Abbreviation */
abbr[title] {
text-decoration-line: underline;
text-decoration-style: dotted;
cursor: help;
}
a abbr[title] {
text-decoration: none;
}
/* Subscript & Superscript */
:where(sub, sup) {
line-height: 0;
}
/* Quote */
q {
font-style: italic;
quotes: none;
}
/* Keyboard input */
kbd {
background: linear-gradient(0deg, Canvas 0%, ButtonFace 100%);
font-size: var(--f-size-small);
font-family: var(--f-sans);
font-weight: bold;
padding: 0.2em 0.4em;
border-radius: 0.5rem;
box-shadow: 1px 1px 1px 0px var(--c-gray);
}
/* Ruby annotation
========================================
*/
rt {
color: var(--c-gray);
font-family: var(--f-sans);
letter-spacing: -0.05em;
padding: 0 0.25em;
}
/* Horizontal rule
========================================
*/
hr {
height: 0;
margin: 2em 0;
border: 0;
border-top: 2px solid var(--c-gray);
}
/* Blockquote
========================================
*/
blockquote {
font-size: var(--f-size-large);
font-style: italic;
line-height: calc(var(--f-line) / 1.25);
margin: 0;
}
blockquote > *:first-child {
margin-block-start: 0;
}
blockquote > *:last-child {
margin-block-end: 0;
}
/* Captions
========================================
*/
:where(caption, figcaption) {
color: var(--c-gray);
font-family: var(--f-heading);
font-size: var(--f-size-small);
font-style: italic;
margin-block-start: 0.5rem;
}
caption {
text-align: left;
caption-side: bottom;
}
[dir='rtl' i] caption {
text-align: right;
}
/* Code
========================================
*/
:where(pre, code, samp, var) {
background-color: ButtonFace;
}
:where(code, samp, var) {
font-size: var(--f-size-small);
font-family: var(--f-code);
padding: 0.2em 0.4em;
}
pre {
font-size: var(--f-size-small);
padding: 2rem;
}
@media screen {
pre {
overflow-x: scroll;
}
}
pre code {
background-color: transparent;
display: block;
white-space: pre-wrap;
padding: 0;
}
/* Details
========================================
*/
details {
background-color: ButtonFace;
padding: 2rem;
margin: 1em 0;
border-radius: 0.5rem;
}
details > *:nth-child(2) {
margin-block-start: 0;
}
details > *:last-child {
margin-block-end: 0;
}
summary {
color: LinkText;
font-family: var(--f-heading);
font-weight: bold;
cursor: pointer;
}
summary:hover {
text-decoration: underline;
}
details[open] summary {
margin-block-end: 2rem;
}
/* Aside
========================================
*/
aside {
color: var(--c-gray);
}
@media (min-width: 769px) {
aside {
font-size: var(--f-size-small);
float: right;
width: calc(var(--w-body) / 2.5);
padding-block-end: 2rem;
padding-inline-start: 4rem;
}
aside > *:first-child {
margin-block-start: 0;
}
aside > *:last-child {
margin-block-end: 0;
}
}
/* Table
========================================
*/
table {
width: 100%;
margin: 1em 0;
border-collapse: collapse;
border-spacing: 0;
break-inside: avoid;
}
@media screen and (max-width: 768px) {
table {
display: block;
overflow-x: auto;
overflow-y: hidden;
}
}
thead {
border-bottom: 2px solid var(--c-gray);
}
tbody tr:nth-child(odd) {
background-color: ButtonFace;
}
tfoot {
border-top: 2px solid var(--c-gray);
}
:where(th, td) {
padding: 0.5rem 1rem;
}
@media (max-width: 768px) {
:where(th, td) {
min-width: 10rem;
}
}
th {
font-family: var(--f-heading);
text-align: left;
vertical-align: bottom;
}
[dir='rtl' i] th {
text-align: right;
}
/* Forms & Inputs
========================================
*/
/* Reset */
:where(input, textarea, select, button, progress) {
-webkit-appearance: none;
background-color: transparent;
break-inside: avoid;
}
:where(input, textarea, select, button) {
font-family: var(--f-form);
font-size: 1em;
border-radius: 0.5rem;
}
:where(input:not([type='button' i]):not([type='submit' i]):not([type='reset' i]):not([type='checkbox' i]):not([type='radio' i]):not([type='image' i]), textarea, select) {
color: CanvasText;
font-size: var(--f-size-small);
display: block;
width: 100%;
padding: 0.75rem 1rem;
border: 2px solid LinkText;
}
/* Placeholder */
::placeholder {
color: var(--c-gray);
}
/* Fieldset */
fieldset {
padding: 2rem;
border: 2px solid LinkText;
border-radius: 0.5rem;
break-inside: avoid;
}
/* Label & Legend */
:where(legend, label) {
font-family: var(--f-form);
font-weight: bold;
display: block;
}
legend {
padding: 0 1rem;
}
:where(legend, label) small {
color: var(--c-gray);
font-weight: normal;
}
/* Textarea */
textarea {
resize: vertical;
}
/* Checkbox & Radio input */
label:has([type='checkbox' i], [type='radio' i]) {
font-family: var(--f-form);
font-size: var(--f-size-small);
font-weight: normal;
display: grid;
grid-template-columns: 1.25em 1fr;
column-gap: 0.5em;
padding-block-end: 0;
}
label:has([type='checkbox' i][disabled], [type='radio' i][disabled]) {
color: var(--c-gray);
}
:where([type='checkbox' i], [type='radio' i]) {
width: 1.25em;
height: 1.25em;
position: relative;
margin: 0.2rem 0 0;
border: 2px solid LinkText;
cursor: pointer;
}
[type='radio' i] {
border-radius: 50%;
}
:where([type='checkbox' i], [type='radio' i]):checked {
background-color: LinkText;
}
[type='checkbox' i]:checked::after {
content: '\2713';
color: Canvas;
font-family: var(--f-form);
font-weight: bold;
line-height: 1;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
/* Color input */
[type='color' i] {
height: 4rem;
padding: 0.5rem;
cursor: pointer;
}
::-webkit-color-swatch-wrapper {
padding: 0;
}
::-webkit-color-swatch {
border: 0;
}
::-moz-color-swatch {
border: 0;
}
/* Range input */
[type='range' i] {
margin: 1.25rem 0 0;
padding: 0;
border: 0;
}
[type='range' i]:focus {
outline: none;
}
::-webkit-slider-runnable-track {
background-color: LinkText;
height: 4px;
border-radius: 0.5rem;
}
[disabled]::-webkit-slider-runnable-track {
background-color: var(--c-gray);
}
::-moz-range-track {
background-color: LinkText;
height: 4px;
border-radius: 0.5rem;
}
[disabled]::-moz-range-track {
background-color: var(--c-gray);
}
::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
background-color: Canvas;
height: 2rem;
width: 2rem;
margin-block-start: calc(-1rem + 2px);
border: 2px solid LinkText;
border-radius: 50%;
cursor: ew-resize;
}
[disabled]::-webkit-slider-thumb {
border-color: var(--c-gray);
}
[type='range' i]:focus::-webkit-slider-thumb {
outline: 2px solid LinkText;
outline-offset: 0.25rem;
}
::-moz-range-thumb {
appearance: none;
background-color: Canvas;
height: 2rem;
width: 2rem;
margin-block-start: calc(-1rem + 2px);
border: 2px solid LinkText;
border-radius: 50%;
cursor: ew-resize;
}
[disabled]::-moz-range-thumb {
border-color: var(--c-gray);
}
[type='range' i]:focus::-moz-range-thumb {
outline: 2px solid LinkText;
outline-offset: 0.25rem;
}
/* Select */
select {
background: Canvas var(--i-triangle) no-repeat calc(100% - 1rem) center / 1.5rem;
text-overflow: ellipsis;
white-space: nowrap;
padding-inline-end: 3.5rem;
overflow: hidden;
cursor: pointer;
}
[dir='rtl' i] select {
background-position: 1rem center;
padding-inline: 3.5rem 1rem;
}
select[multiple] {
background-image: none;
padding-inline-end: 1rem;
}
/* Buttons */
:where(button, [type='button' i], [type='submit' i], [type='reset' i]) {
font-size: var(--f-size-small);
font-weight: bold;
text-align: center;
text-decoration: none;
line-height: 1;
display: inline-block;
min-width: 5rem;
padding: 0.2em 0.4em;
border: 2px solid LinkText;
-webkit-user-select: text;
user-select: text;
cursor: pointer;
touch-action: manipulation;
}
:where(button:not([disabled]), [type='button' i]:not([disabled]), [type='submit' i]:not([disabled]), [type='reset' i]:not([disabled])):hover {
text-decoration: underline;
}
@media screen {
:where(button, [type='button' i], [type='submit' i], [type='reset' i]) {
background-color: LinkText;
color: Canvas;
}
:where(button[disabled], [type='button' i][disabled], [type='submit' i][disabled], [type='reset' i][disabled]) {
background-color: var(--c-gray);
color: currentColor;
}
}
form :where(button, [type='button' i], [type='submit' i], [type='reset' i]) {
padding: 1rem 1.5rem;
}
/* Meter & Progress */
:where(meter, progress) {
width: 100%;
height: 3rem;
border: 2px solid var(--c-gray);
}
label + :where(meter, progress) {
margin-block-start: 0.5rem;
}
meter {
background: transparent;
display: block;
margin-block-end: 1em;
border: 2px solid var(--c-gray);
}
::-webkit-meter-bar {
background: Canvas;
height: 3rem;
border: 2px solid var(--c-gray);
border-radius: 0;
}
::-webkit-progress-bar {
background-color: Canvas;
}
::-moz-progress-bar {
background-color: var(--c-gray);
}
::-webkit-progress-value {
background-color: var(--c-gray);
}
/* Disabled state */
[disabled] {
border-color: var(--c-gray);
cursor: not-allowed;
}
/* Error state */
[aria-invalid] {
border-color: var(--c-red) !important;
}
[aria-invalid]:focus {
outline-color: var(--c-red);
}
[aria-invalid] + p[id] {
color: var(--c-red);
}
/* Form spacing */
form label:not(:first-of-type) {
margin-block-start: 3rem;
}
form label + :where(input, textarea, select) {
margin-block-start: 0.5rem;
}
form fieldset {
margin: 3rem 0;
}
fieldset label:not(:first-of-type) {
margin-block-start: 2rem;
}
form p[id] {
margin-block-start: 0.5rem;
}
/* Dialog
========================================
*/
dialog[open] {
background-color: Canvas;
color: currentColor;
display: block;
max-width: var(--w-body, 100%);
min-width: calc(var(--w-body) / 2);
padding: 2rem;
border: 2px solid var(--c-gray);
border-radius: 0.5rem;
}
body:has(dialog[open]) {
overflow: hidden;
}
dialog:not([open]) {
display: none;
}
dialog > *:first-child {
margin-block-start: 0;
}
dialog > *:last-child {
margin-block-end: 0;
}
/* Opinionated layout
========================================
*/
@media screen {
body > header {
margin-block-end: 4em;
}
main > :where(section, article),
body > footer {
margin-block-start: 4em;
clear: both;
}
body > footer {
margin-block-start: 4em;
}
}

View file

View file

@ -2,10 +2,8 @@
namespace App\DataFixtures; namespace App\DataFixtures;
use App\Entity\FoodOrder;
use App\Entity\FoodVendor; use App\Entity\FoodVendor;
use App\Entity\MenuItem; use App\Entity\MenuItem;
use App\Entity\OrderItem;
use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager; use Doctrine\Persistence\ObjectManager;
use Override; use Override;
@ -41,26 +39,12 @@ final class AppFixtures extends Fixture
public function addMenuItemsToVendor(FoodVendor $vendor): void public function addMenuItemsToVendor(FoodVendor $vendor): void
{ {
$menuItems = [];
foreach (range(1, 10) as $i) { foreach (range(1, 10) as $i) {
$item = new MenuItem; $item = new MenuItem;
$item->setName("{$vendor->getName()} Item {$i}"); $item->setName("{$vendor->getName()} Item {$i}");
$item->setFoodVendor($vendor); $item->setFoodVendor($vendor);
$this->manager->persist($item); $this->manager->persist($item);
$this->manager->flush(); $this->manager->flush();
$menuItems[] = $item;
}
$order = new FoodOrder;
$order->setFoodVendor($vendor);
$this->manager->persist($order);
foreach ($menuItems as $item) {
$orderItem = new OrderItem;
$orderItem->setMenuItem($item);
$orderItem->setCreatedBy('John');
$order->addOrderItem($orderItem);
$this->manager->persist($orderItem);
} }
} }
} }

View file

@ -2,7 +2,6 @@
namespace App\Entity; namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\FoodOrderRepository; use App\Repository\FoodOrderRepository;
use DateInterval; use DateInterval;
use DateTimeImmutable; use DateTimeImmutable;
@ -15,7 +14,6 @@ use Symfony\Component\Uid\Ulid;
use function iterator_to_array; use function iterator_to_array;
#[ORM\Entity(repositoryClass: FoodOrderRepository::class)] #[ORM\Entity(repositoryClass: FoodOrderRepository::class)]
#[ApiResource]
class FoodOrder class FoodOrder
{ {
#[ORM\Column(nullable: true)] #[ORM\Column(nullable: true)]
@ -41,7 +39,6 @@ class FoodOrder
#[ORM\Column(type: UlidType::NAME, unique: true)] #[ORM\Column(type: UlidType::NAME, unique: true)]
private Ulid|null $id = new Ulid private Ulid|null $id = new Ulid
) { ) {
$this->id ??= new Ulid;
$this->orderItems = new ArrayCollection; $this->orderItems = new ArrayCollection;
$this->open(); $this->open();
} }

View file

@ -2,7 +2,6 @@
namespace App\Entity; namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\FoodVendorRepository; use App\Repository\FoodVendorRepository;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
@ -12,7 +11,6 @@ use Symfony\Bridge\Doctrine\Types\UlidType;
use Symfony\Component\Uid\Ulid; use Symfony\Component\Uid\Ulid;
#[ORM\Entity(repositoryClass: FoodVendorRepository::class)] #[ORM\Entity(repositoryClass: FoodVendorRepository::class)]
#[ApiResource]
class FoodVendor class FoodVendor
{ {
#[ORM\Column(length: 50)] #[ORM\Column(length: 50)]
@ -45,7 +43,6 @@ class FoodVendor
#[ORM\CustomIdGenerator(class: UlidGenerator::class)] #[ORM\CustomIdGenerator(class: UlidGenerator::class)]
private Ulid|null $id = new Ulid private Ulid|null $id = new Ulid
) { ) {
$this->id ??= new Ulid;
$this->foodOrders = new ArrayCollection; $this->foodOrders = new ArrayCollection;
$this->menuItems = new ArrayCollection; $this->menuItems = new ArrayCollection;
} }

View file

@ -2,7 +2,6 @@
namespace App\Entity; namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\MenuItemRepository; use App\Repository\MenuItemRepository;
use DateTimeImmutable; use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
@ -13,7 +12,6 @@ use Symfony\Bridge\Doctrine\Types\UlidType;
use Symfony\Component\Uid\Ulid; use Symfony\Component\Uid\Ulid;
#[ORM\Entity(repositoryClass: MenuItemRepository::class)] #[ORM\Entity(repositoryClass: MenuItemRepository::class)]
#[ApiResource]
class MenuItem class MenuItem
{ {
#[ORM\Column(length: 255)] #[ORM\Column(length: 255)]
@ -42,7 +40,6 @@ class MenuItem
#[ORM\CustomIdGenerator(class: UlidGenerator::class)] #[ORM\CustomIdGenerator(class: UlidGenerator::class)]
private Ulid|null $id = new Ulid private Ulid|null $id = new Ulid
) { ) {
$this->id ??= new Ulid;
$this->aliases = new ArrayCollection; $this->aliases = new ArrayCollection;
} }

View file

@ -2,7 +2,6 @@
namespace App\Entity; namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\OrderItemRepository; use App\Repository\OrderItemRepository;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator; use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
@ -10,9 +9,14 @@ use Symfony\Bridge\Doctrine\Types\UlidType;
use Symfony\Component\Uid\Ulid; use Symfony\Component\Uid\Ulid;
#[ORM\Entity(repositoryClass: OrderItemRepository::class)] #[ORM\Entity(repositoryClass: OrderItemRepository::class)]
#[ApiResource]
class OrderItem class OrderItem
{ {
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\Column(type: UlidType::NAME, unique: true)]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
private Ulid|null $id = null;
#[ORM\Column(length: 255)] #[ORM\Column(length: 255)]
private string|null $name = null; private string|null $name = null;
@ -32,16 +36,6 @@ class OrderItem
])] ])]
private string|null $createdBy = 'nobody'; private string|null $createdBy = 'nobody';
public function __construct(
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\Column(type: UlidType::NAME, unique: true)]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
private Ulid|null $id = new Ulid
) {
$this->id ??= new Ulid;
}
public function getId(): Ulid|null public function getId(): Ulid|null
{ {
return $this->id; return $this->id;
@ -91,7 +85,6 @@ class OrderItem
public function setMenuItem(MenuItem|null $menuItem): static public function setMenuItem(MenuItem|null $menuItem): static
{ {
$this->menuItem = $menuItem; $this->menuItem = $menuItem;
$this->name = $menuItem->getName();
return $this; return $this;
} }

View file

@ -7,12 +7,14 @@ use App\Repository\MenuItemRepository;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Override; use Override;
use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Bridge\Doctrine\Types\UlidType;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Length; use Symfony\Component\Uid\Ulid;
use Symfony\Component\Validator\Constraints\NotBlank;
use function array_map;
use function assert;
final class MenuItemType extends AbstractType final class MenuItemType extends AbstractType
{ {
@ -20,22 +22,41 @@ final class MenuItemType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options): void public function buildForm(FormBuilderInterface $builder, array $options): void
{ {
$item = $options['data']; $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
$builder->add('name', TextType::class, [ $builder->add('name'); // Basic field
'constraints' => [
new NotBlank,
new Length([
'min' => 3,
]),
],
]);
$builder->add('aliases', EntityType::class, [ $builder->add('aliases', EntityType::class, [
'class' => MenuItem::class, 'class' => MenuItem::class,
'choice_label' => 'name', 'choice_label' => 'name',
'multiple' => true, 'multiple' => true,
'expanded' => true, 'expanded' => true,
'query_builder' => static fn(MenuItemRepository $repository): QueryBuilder 'query_builder' => static function (MenuItemRepository $repository) use ($item, $vendorId): QueryBuilder {
=> $repository->getSuitableAliasQueryBuilder($item),
$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;
},
]); ]);
} }

View file

@ -8,15 +8,4 @@ use Symfony\Component\HttpKernel\Kernel as BaseKernel;
final class Kernel extends BaseKernel final class Kernel extends BaseKernel
{ {
use MicroKernelTrait; use MicroKernelTrait;
public function __construct(
protected string $environment,
protected bool $debug,
) {
parent::__construct($environment, $debug);
if ($environment === 'test') {
$this->debug = false;
}
}
} }

View file

@ -4,12 +4,7 @@ namespace App\Repository;
use App\Entity\MenuItem; use App\Entity\MenuItem;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ManagerRegistry; use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bridge\Doctrine\Types\UlidType;
use Symfony\Component\Uid\Ulid;
use function array_map;
/** /**
* @extends ServiceEntityRepository<MenuItem> * @extends ServiceEntityRepository<MenuItem>
@ -21,29 +16,28 @@ final class MenuItemRepository extends ServiceEntityRepository
parent::__construct($registry, MenuItem::class); parent::__construct($registry, MenuItem::class);
} }
public function getSuitableAliasQueryBuilder(MenuItem $menuItem): QueryBuilder // /**
{ // * @return MenuItem[] Returns an array of MenuItem objects
$ids = $this->createQueryBuilder('m') // */
->select('DISTINCT IDENTITY(m.aliasOf)') // public function findByExampleField($value): array
->where('m.deletedAt IS NULL') // {
->andWhere('m.aliasOf IS NOT NULL') // return $this->createQueryBuilder('m')
->getquery(); // ->andWhere('m.exampleField = :val')
$ids = $ids->getScalarResult(); // ->setParameter('val', $value)
$ids = array_map(static fn(array $id): Ulid => Ulid::fromBinary($id[1]), $ids); // ->orderBy('m.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
$qb = $this->createQueryBuilder('m'); // public function findOneBySomeField($value): ?MenuItem
$qb // {
->where('m.foodVendor = :vendorId') // return $this->createQueryBuilder('m')
->andWhere('m.deletedAt IS NULL') // ->andWhere('m.exampleField = :val')
->andWhere('m.id != :id'); // ->setParameter('val', $value)
foreach ($ids as $key => $id) { // ->getQuery()
$qb->andWhere("m.id != :idBy{$key}") // ->getOneOrNullResult()
->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;
}
} }

View file

@ -1,18 +1,4 @@
{ {
"api-platform/symfony": {
"version": "4.0",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "4.0",
"ref": "e9952e9f393c2d048f10a78f272cd35e807d972b"
},
"files": [
"config/packages/api_platform.yaml",
"config/routes/api_platform.yaml",
"src/ApiResource/.gitignore"
]
},
"doctrine/doctrine-bundle": { "doctrine/doctrine-bundle": {
"version": "2.12", "version": "2.12",
"recipe": { "recipe": {
@ -52,21 +38,6 @@
"migrations/.gitignore" "migrations/.gitignore"
] ]
}, },
"liip/test-fixtures-bundle": {
"version": "3.2.1"
},
"nelmio/cors-bundle": {
"version": "2.5",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "1.5",
"ref": "6bea22e6c564fba3a1391615cada1437d0bde39c"
},
"files": [
"config/packages/nelmio_cors.yaml"
]
},
"phpstan/phpstan": { "phpstan/phpstan": {
"version": "1.11", "version": "1.11",
"recipe": { "recipe": {
@ -77,7 +48,7 @@
} }
}, },
"phpunit/phpunit": { "phpunit/phpunit": {
"version": "11.4", "version": "9.6",
"recipe": { "recipe": {
"repo": "github.com/symfony/recipes", "repo": "github.com/symfony/recipes",
"branch": "main", "branch": "main",
@ -151,6 +122,21 @@
"ref": "fadbfe33303a76e25cb63401050439aa9b1a9c7f" "ref": "fadbfe33303a76e25cb63401050439aa9b1a9c7f"
} }
}, },
"symfony/phpunit-bridge": {
"version": "7.1",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "6.3",
"ref": "a411a0480041243d97382cac7984f7dce7813c08"
},
"files": [
".env.test",
"bin/phpunit",
"phpunit.xml.dist",
"tests/bootstrap.php"
]
},
"symfony/routing": { "symfony/routing": {
"version": "7.1", "version": "7.1",
"recipe": { "recipe": {
@ -164,19 +150,6 @@
"config/routes.yaml" "config/routes.yaml"
] ]
}, },
"symfony/security-bundle": {
"version": "7.2",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "6.4",
"ref": "2ae08430db28c8eb4476605894296c82a642028f"
},
"files": [
"config/packages/security.yaml",
"config/routes/security.yaml"
]
},
"symfony/twig-bundle": { "symfony/twig-bundle": {
"version": "7.1", "version": "7.1",
"recipe": { "recipe": {

View file

@ -2,21 +2,16 @@
<html> <html>
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="color-scheme" content="dark light">
<meta name="theme-color" content="#0000ff" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#222222" media="(prefers-color-scheme: dark)">
<title>{% block title %}Welcome!{% endblock %}</title> <title>{% block title %}Welcome!{% endblock %}</title>
<link rel="icon" type="image/svg+xml" <link rel="icon" type="image/svg+xml"
href="{{ favicon }}" /> href="{{ favicon }}" />
{% set currentDate = "now"|date("d") %} {% set currentDate = "now"|date("d") %}
{% if currentDate % 4 == 0 %} {% if currentDate % 3 == 0 %}
<link rel="stylesheet" href="/static/css/new.min.css"> <link rel="stylesheet" href="/static/css/new.min.css">
{% elseif currentDate % 4 == 1 %} {% elseif currentDate % 3 == 1 %}
<link rel="stylesheet" href="/static/css/simple.min.css"> <link rel="stylesheet" href="/static/css/simple.min.css">
{% elseif currentDate % 4 == 2 %}
<link rel="stylesheet" href="/static/css/water.min.css">
{% else %} {% else %}
<link rel="stylesheet" href="/static/css/fieber.css"> <link rel="stylesheet" href="/static/css/water.min.css">
{% endif %} {% endif %}
<style> <style>
label{ label{
@ -34,8 +29,7 @@
<a <a
href="https://git.hannover.ccc.de/lubiana/futtern/issues/new" href="https://git.hannover.ccc.de/lubiana/futtern/issues/new"
target="_blank" target="_blank"
>Create Issue</a> / >Create Issue</a>
<a href="/api">API</a>
</nav> </nav>
</header> </header>
<main> <main>

View file

@ -40,7 +40,6 @@
<table class="table"> <table class="table">
<thead> <thead>
<tr> <tr>
<th>Index</th>
<th>username</th> <th>username</th>
<th>name</th> <th>name</th>
<th>extras</th> <th>extras</th>
@ -50,7 +49,6 @@
<tbody> <tbody>
{% for item in food_order.orderItemsSortedByName %} {% for item in food_order.orderItemsSortedByName %}
<tr> <tr>
<td>{{ loop.index }}</td>
<td>{{ item.createdBy }}</td> <td>{{ item.createdBy }}</td>
<td>{{ item.name }}</td> <td>{{ item.name }}</td>
<td>{{ item.extras }}</td> <td>{{ item.extras }}</td>

View file

@ -21,18 +21,6 @@
<td>{{ menu_item.aliasOf.name }}</td> <td>{{ menu_item.aliasOf.name }}</td>
</tr> </tr>
{% endif %} {% endif %}
{% if(menu_item.aliases|length > 0) %}
<tr>
<th>Aliases</th>
<td>
<ul>
{% for alias in menu_item.aliases %}
<li>{{ alias.name }}</li>
{% endfor %}
</ul>
</td>
</tr>
{% endif %}
</tbody> </tbody>
</table> </table>

View file

@ -1,40 +1,45 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
namespace App\Tests\Feature\Controller; namespace App\Tests\Controller;
use App\Controller\FoodOrderController;
use App\Entity\FoodOrder; use App\Entity\FoodOrder;
use App\Entity\FoodVendor; use App\Entity\FoodVendor;
use App\Entity\MenuItem; use App\Entity\MenuItem;
use App\Entity\OrderItem; use App\Entity\OrderItem;
use App\Form\FoodOrderType; use App\Tests\DbWebTest;
use App\Repository\FoodOrderRepository; use Override;
use App\Repository\FoodVendorRepository;
use Symfony\Component\BrowserKit\Cookie; use Symfony\Component\BrowserKit\Cookie;
use Symfony\Component\DomCrawler\Crawler; use Symfony\Component\DomCrawler\Crawler;
use function assert; use function assert;
use function describe;
use function pest;
use function range; use function range;
use function sprintf; use function sprintf;
use function str_ends_with; use function str_ends_with;
use function test;
pest() final class FoodOrderControllerTest extends DbWebTest
->beforeEach(function (): void { {
$this->setEntityClass(FoodOrder::class); private string $path = '/food/order/';
$this->setPath('/food/order/'); private FoodVendor $vendor;
$this->repository = $this->manager->getRepository($this->entityClass);
#[Override]
public function setUp(): void
{
parent::setUp();
$this->vendor = new FoodVendor; $this->vendor = new FoodVendor;
$this->vendor->setName('Food Vendor'); $this->vendor->setName('Food Vendor');
$this->manager->persist($this->vendor); $this->manager->persist($this->vendor);
$this->manager->flush(); $this->manager->flush();
}); }
describe(FoodOrderController::class, function (): void { #[Override]
test('index', function (): void { public function getEntityClass(): string
{
return FoodOrder::class;
}
public function testIndex(): void
{
$order = new FoodOrder; $order = new FoodOrder;
$order->setFoodVendor($this->vendor); $order->setFoodVendor($this->vendor);
@ -43,16 +48,17 @@ describe(FoodOrderController::class, function (): void {
$this->manager->flush(); $this->manager->flush();
$crawler = $this->client->request('GET', "{$this->path}list"); $crawler = $this->client->request('GET', "{$this->path}list");
$this->assertResponseStatusCodeSame(200); self::assertResponseStatusCodeSame(200);
$this->assertPageTitleContains('FoodOrder index'); self::assertPageTitleContains('FoodOrder index');
$this->assertCount( $this->assertCount(
1, 1,
$crawler->filter('td') $crawler->filter('td')
->reduce(fn(Crawler $node, $i): bool => $node->text() === $this->vendor->getName()), ->reduce(fn(Crawler $node, $i): bool => $node->text() === $this->vendor->getName()),
); );
}); }
test('orderedItems', function (): void { public function testOrderedItems(): void
{
$order = new FoodOrder; $order = new FoodOrder;
$order->setFoodVendor($this->vendor); $order->setFoodVendor($this->vendor);
@ -98,7 +104,7 @@ describe(FoodOrderController::class, function (): void {
$this->manager->flush(); $this->manager->flush();
$crawler = $this->client->request('GET', "{$this->path}{$order->getId()}"); $crawler = $this->client->request('GET', "{$this->path}{$order->getId()}");
$this->assertResponseIsSuccessful(); self::assertResponseIsSuccessful();
$tdContent = $crawler->filter( $tdContent = $crawler->filter(
'table.table:nth-child(6) > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(2)' 'table.table:nth-child(6) > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(2)'
)->text(); )->text();
@ -111,20 +117,14 @@ describe(FoodOrderController::class, function (): void {
'table.table:nth-child(6) > tbody:nth-child(2) > tr:nth-child(3) > td:nth-child(2)' 'table.table:nth-child(6) > tbody:nth-child(2) > tr:nth-child(3) > td:nth-child(2)'
)->text(); )->text();
$this->assertEquals('C', $tdContent); $this->assertEquals('C', $tdContent);
}); }
test('paginatedIndex', function (): void { public function testPaginatedIndex(): void
foreach (range(1, 35) as $i) { {
$order = new FoodOrder($this->generateOldUlid()); $this->generatePaginatedOrders();
$order->setFoodVendor($this->vendor);
$order->close();
$this->manager->persist($order);
}
$this->manager->flush();
$crawler = $this->client->request('GET', "{$this->path}list"); $crawler = $this->client->request('GET', "{$this->path}list");
$this->assertResponseStatusCodeSame(200); self::assertResponseStatusCodeSame(200);
$this->assertPageTitleContains('FoodOrder index'); self::assertPageTitleContains('FoodOrder index');
$this->assertElementContainsCount( $this->assertElementContainsCount(
$crawler, $crawler,
'td', 'td',
@ -137,20 +137,20 @@ describe(FoodOrderController::class, function (): void {
0, 0,
'next page' 'next page'
); );
}); }
test('paginatedFirstPage', function (int $page, int $prevPage, int $nextPage, int $items = 10): void { /**
foreach (range(1, 35) as $i) { * @testWith [1, 0, 2]
$order = new FoodOrder($this->generateOldUlid()); * [2, 1, 3]
$order->setFoodVendor($this->vendor); * [3, 2, 4]
$order->close(); * [4, 3, 0, 5]
$this->manager->persist($order); */
public function testPaginatedFirstPage(int $page, int $prevPage, int $nextPage, int $items = 10): void
} {
$this->manager->flush(); $this->generatePaginatedOrders();
$crawler = $this->client->request('GET', "{$this->path}list/archive/{$page}"); $crawler = $this->client->request('GET', "{$this->path}list/archive/{$page}");
$this->assertResponseStatusCodeSame(200); self::assertResponseStatusCodeSame(200);
$this->assertPageTitleContains('FoodOrder index'); self::assertPageTitleContains('FoodOrder index');
$this->assertElementContainsCount( $this->assertElementContainsCount(
$crawler, $crawler,
'td', 'td',
@ -172,36 +172,30 @@ describe(FoodOrderController::class, function (): void {
$target = $node->attr('href'); $target = $node->attr('href');
$this->assertTrue(str_ends_with((string) $target, "/{$nextPage}")); $this->assertTrue(str_ends_with((string) $target, "/{$nextPage}"));
} }
}) }
->with(
[
[1, 0, 2],
[2, 1, 3],
[3, 2, 4],
[4, 3, 0, 5],
]
);
test('new', function (): void { public function testNew(): void
{
$this->client->getCookieJar() $this->client->getCookieJar()
->set(new Cookie('username', 'Testing-1')); ->set(new Cookie('username', 'Testing-1'));
$this->client->request('GET', sprintf('%snew', $this->path)); $this->client->request('GET', sprintf('%snew', $this->path));
$this->assertResponseStatusCodeSame(200); self::assertResponseStatusCodeSame(200);
$this->client->submitForm('Save', [ $this->client->submitForm('Save', [
'food_order[foodVendor]' => $this->vendor->getId(), 'food_order[foodVendor]' => $this->vendor->getId(),
]); ]);
$this->assertResponseRedirects("{$this->path}list"); self::assertResponseRedirects("{$this->path}list");
$this->assertSame(1, $this->repository->count([])); self::assertSame(1, $this->repository->count([]));
$order = $this->repository->findOneBy([ $order = $this->repository->findOneBy([
'createdBy' => 'Testing-1', 'createdBy' => 'Testing-1',
]); ]);
assert($order instanceof FoodOrder); assert($order instanceof FoodOrder);
}); }
test('open', function (): void { public function testOpen(): void
{
$order = new FoodOrder; $order = new FoodOrder;
$order->setFoodVendor($this->vendor); $order->setFoodVendor($this->vendor);
$order->close(); $order->close();
@ -211,12 +205,13 @@ describe(FoodOrderController::class, function (): void {
$this->manager->flush(); $this->manager->flush();
$this->client->request('GET', sprintf('%s%s/open', $this->path, $order->getId())); $this->client->request('GET', sprintf('%s%s/open', $this->path, $order->getId()));
$this->assertResponseRedirects("{$this->path}{$order->getId()}"); self::assertResponseRedirects("{$this->path}{$order->getId()}");
$openOrder = $this->repository->find($order->getId()); $openOrder = $this->repository->find($order->getId());
$this->assertFalse($openOrder->isClosed()); $this->assertFalse($openOrder->isClosed());
}); }
test('close', function (): void { public function testClose(): void
{
$order = new FoodOrder; $order = new FoodOrder;
$order->setClosedAt(); $order->setClosedAt();
$order->setFoodVendor($this->vendor); $order->setFoodVendor($this->vendor);
@ -226,19 +221,20 @@ describe(FoodOrderController::class, function (): void {
$this->manager->flush(); $this->manager->flush();
$this->client->request('GET', sprintf('%s%s/close', $this->path, $order->getId())); $this->client->request('GET', sprintf('%s%s/close', $this->path, $order->getId()));
$this->assertResponseRedirects("{$this->path}{$order->getId()}"); self::assertResponseRedirects("{$this->path}{$order->getId()}");
$openOrder = $this->repository->find($order->getId()); $openOrder = $this->repository->find($order->getId());
$this->assertTrue($openOrder->isClosed()); $this->assertTrue($openOrder->isClosed());
}); }
}) private function generatePaginatedOrders(): void
->covers( {
FoodOrderController::class, foreach (range(1, 35) as $i) {
FoodOrder::class, $order = new FoodOrder($this->generateOldUlid());
FoodVendor::class, $order->setFoodVendor($this->vendor);
FoodOrderRepository::class, $order->close();
MenuItem::class, $this->manager->persist($order);
OrderItem::class,
FoodOrderType::class, }
FoodVendorRepository::class $this->manager->flush();
); }
}

View file

@ -1,56 +1,41 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
namespace App\Tests\Feature\Controller; namespace App\Tests\Controller;
use App\Controller\FoodVendorController;
use App\Entity\FoodOrder;
use App\Entity\FoodVendor; use App\Entity\FoodVendor;
use App\Entity\MenuItem; use App\Entity\MenuItem;
use App\Entity\OrderItem; use App\Tests\DbWebTest;
use App\Form\FoodOrderType; use Override;
use App\Form\FoodVendorType;
use App\Repository\FoodOrderRepository;
use App\Repository\FoodVendorRepository;
use function describe;
use function pest;
use function sprintf; use function sprintf;
use function test;
pest() final class FoodVendorControllerTest extends DbWebTest
->beforeEach(function (): void { {
$this->setEntityClass(FoodVendor::class); private string $path = '/food/vendor/';
$this->setPath('/food/vendor/');
$this->repository = $this->manager->getRepository($this->entityClass);
});
describe(FoodVendorController::class, function (): void { public function testIndex(): void
test('index', function (): void { {
$this->client->request('GET', $this->path); $this->client->request('GET', $this->path);
$this->assertResponseStatusCodeSame(200); self::assertResponseStatusCodeSame(200);
$this->assertPageTitleContains('FoodVendor index'); self::assertPageTitleContains('FoodVendor index');
}); }
test('new', function (): void { public function testNew(): void
$this->assertSame(0, $this->repository->count([])); {
$this->client->request('GET', sprintf('%snew', $this->path)); $this->client->request('GET', sprintf('%snew', $this->path));
$this->assertResponseStatusCodeSame(200); self::assertResponseStatusCodeSame(200);
$this->client->submitForm('Save', [ $this->client->submitForm('Save', [
'food_vendor[name]' => 'TestingNew', 'food_vendor[name]' => 'Testing',
]); ]);
$newVendor = $this->repository->findOneBy([ self::assertSame(1, $this->repository->count([]));
'name' => 'TestingNew', }
]);
$this->assertInstanceof(FoodVendor::class, $newVendor);
$this->assertSame(1, $this->repository->count([]));
}); public function testShow(): void
{
test('show', function (): void {
$fixture = new FoodVendor; $fixture = new FoodVendor;
$fixture->setName('My Title'); $fixture->setName('My Title');
$fixture->setMenuLink('https://example.com/'); $fixture->setMenuLink('https://example.com/');
@ -72,9 +57,10 @@ describe(FoodVendorController::class, function (): void {
)->text(); )->text();
$this->assertSame('My Title', $nameNode); $this->assertSame('My Title', $nameNode);
$this->assertSame('https://example.com/', $menuLinkNode); $this->assertSame('https://example.com/', $menuLinkNode);
}); }
test('show with menu items', function (): void { public function testShowMenuItems(): void
{
$fixture = new FoodVendor; $fixture = new FoodVendor;
$fixture->setName('My Title'); $fixture->setName('My Title');
@ -122,9 +108,10 @@ describe(FoodVendorController::class, function (): void {
$itemNodes = $crawler->filter('li'); $itemNodes = $crawler->filter('li');
$this->assertCount(4, $itemNodes); $this->assertCount(4, $itemNodes);
}); }
test('edit', function (): void { public function testEdit(): void
{
$fixture = new FoodVendor; $fixture = new FoodVendor;
$fixture->setName('Value'); $fixture->setName('Value');
$fixture->setMenuLink('Value'); $fixture->setMenuLink('Value');
@ -159,26 +146,18 @@ describe(FoodVendorController::class, function (): void {
'food_vendor[phone]' => '1234567890', 'food_vendor[phone]' => '1234567890',
]); ]);
$this->assertResponseRedirects('/food/vendor/'); self::assertResponseRedirects('/food/vendor/');
$fixture = $this->repository->findAll(); $fixture = $this->repository->findAll();
$this->assertSame('Something New', $fixture[0]->getName()); self::assertSame('Something New', $fixture[0]->getName());
$this->assertSame('https://example.com/', $fixture[0]->getMenuLink()); self::assertSame('https://example.com/', $fixture[0]->getMenuLink());
$this->assertSame('1234567890', $fixture[0]->getPhone()); self::assertSame('1234567890', $fixture[0]->getPhone());
}); }
}) #[Override]
->covers( public function getEntityClass(): string
FoodOrder::class, {
FoodVendor::class, return FoodVendor::class;
FoodOrderRepository::class, }
MenuItem::class, }
OrderItem::class,
FoodOrderType::class,
FoodVendorRepository::class,
FoodVendorController::class,
FoodVendorType::class
)
;

View file

@ -0,0 +1,76 @@
<?php declare(strict_types=1);
namespace App\Tests\Controller;
use App\Tests\DbWebTest;
use Override;
final class HomeControllerTest extends DbWebTest
{
public function testIndex(): void
{
$this->client->request(
'GET',
'/'
);
self::assertResponseStatusCodeSame(302);
self::assertResponseHeaderSame('Location', '/food/order/list');
}
public function testSetUsername(): void
{
$this->client->request(
'GET',
'/username',
);
self::assertResponseStatusCodeSame(200);
$this->client->submitForm('Save', [
'user_name_form[username]' => 'Testing-1',
]);
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
{
$this->client->request(
'GET',
'/username',
);
self::assertResponseStatusCodeSame(200);
$this->client->submitForm('Save', [
'user_name_form[username]' => '',
]);
self::assertResponseStatusCodeSame(302);
self::assertResponseHeaderSame('Location', '/food/order/list');
self::assertResponseCookieValueSame('username', '');
}
#[Override]
public function getEntityClass(): string
{
return '';
}
}

View file

@ -0,0 +1,113 @@
<?php declare(strict_types=1);
namespace App\Tests\Controller;
use App\Entity\FoodOrder;
use App\Entity\FoodVendor;
use App\Entity\MenuItem;
use App\Tests\DbWebTest;
use Override;
use function sprintf;
final class MenuItemControllerTest extends DbWebTest
{
private string $path = '/menu/item/';
private FoodVendor $vendor;
#[Override]
public function setUp(): void
{
parent::setUp();
$this->vendor = new FoodVendor;
$this->vendor->setName('Food Vendor');
$this->manager->persist($this->vendor);
$this->manager->flush();
}
#[Override]
public function getEntityClass(): string
{
return MenuItem::class;
}
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()}");
$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();
self::assertResponseStatusCodeSame(200);
$this->assertEquals($idValue, $menuItem->getId());
$this->assertEquals($nameValue, $menuItem->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()));
$nameElem = $crawler->filter('#menu_item_name');
$this->assertEquals(
'Testing 1 2',
$nameElem->attr('value')
);
$this->client->submitForm('Update', [
'menu_item[name]' => 'Testing-1',
]);
self::assertResponseRedirects(sprintf('/menu/item/%s', $menuItem->getId()));
}
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->client->request('GET', "{$this->path}{$menuItem->getId()}");
$this->client->submitForm('Delete', []);
$menuItem = $this->repository->find($menuItem->getId());
$this->assertTrue($menuItem->isDeleted());
$crawler = $this->client->request('GET', '/order/item/new/' . $order->getId());
$count = $crawler->filter('body > main:nth-child(2) > div:nth-child(5)')
->children()
->count();
$this->assertSame(0, $count);
$this->assertResponseIsSuccessful();
}
}

View file

@ -1,29 +1,30 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
namespace App\Tests\Feature\Controller; namespace App\Tests\Controller;
use App\Controller\OrderItemController;
use App\Entity\FoodOrder; use App\Entity\FoodOrder;
use App\Entity\FoodVendor; use App\Entity\FoodVendor;
use App\Entity\MenuItem; use App\Entity\MenuItem;
use App\Entity\OrderItem; use App\Entity\OrderItem;
use App\Form\OrderItemType;
use App\Repository\FoodOrderRepository;
use App\Repository\MenuItemRepository; use App\Repository\MenuItemRepository;
use App\Repository\OrderItemRepository; use App\Tests\DbWebTest;
use DateTimeImmutable; use DateTimeImmutable;
use Override;
use function describe;
use function pest;
use function sprintf; use function sprintf;
use function test;
pest() final class OrderItemControllerTest extends DbWebTest
->beforeEach(function (): void { {
$this->setEntityClass(OrderItem::class); public FoodVendor $vendor;
$this->setPath('/order/item/'); public FoodOrder $order;
$this->repository = $this->manager->getRepository($this->entityClass); public Menuitem $menuItem;
public MenuItemRepository $menuItemRepository;
private string $path = '/order/item/';
#[Override]
public function setUp(): void
{
parent::setUp();
$this->vendor = new FoodVendor; $this->vendor = new FoodVendor;
$this->vendor->setName('Food Vendor'); $this->vendor->setName('Food Vendor');
@ -50,11 +51,11 @@ pest()
$this->manager->persist($this->menuItem); $this->manager->persist($this->menuItem);
$this->manager->flush(); $this->manager->flush();
$this->menuItemRepository = $this::getContainer()->get(MenuItemRepository::class); $this->menuItemRepository = static::getContainer()->get(MenuItemRepository::class);
}); }
describe(OrderItemController::class, function (): void { public function testNew(): void
test('new', function (): void { {
$crawler = $this->client->request( $crawler = $this->client->request(
'GET', 'GET',
sprintf('%snew/%s', $this->path, $this->order->getId()) sprintf('%snew/%s', $this->path, $this->order->getId())
@ -65,22 +66,23 @@ describe(OrderItemController::class, function (): void {
$this->assertCount(1, $children); $this->assertCount(1, $children);
$this->assertResponseStatusCodeSame(200); self::assertResponseStatusCodeSame(200);
$this->client->submitForm('Save', [ $this->client->submitForm('Save', [
'order_item[name]' => 'Testing', 'order_item[name]' => 'Testing',
'order_item[extras]' => 'Testing', 'order_item[extras]' => 'Testing',
]); ]);
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId())); self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
$this->assertSame(1, $this->repository->count([])); self::assertSame(1, $this->repository->count([]));
$this->assertSame(1, $this->menuItemRepository->count([ self::assertSame(1, $this->menuItemRepository->count([
'foodVendor' => $this->vendor->getId(), 'foodVendor' => $this->vendor->getId(),
])); ]));
}); }
test('new order closed', function (): void { public function testNewOrderClosed(): void
{
$this->order->setClosedAt(new DateTimeImmutable('-1 Hour')); $this->order->setClosedAt(new DateTimeImmutable('-1 Hour'));
$this->manager->persist($this->order); $this->manager->persist($this->order);
@ -91,31 +93,33 @@ describe(OrderItemController::class, function (): void {
sprintf('%snew/%s', $this->path, $this->order->getId()) sprintf('%snew/%s', $this->path, $this->order->getId())
); );
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId())); self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
$this->assertSame(0, $this->repository->count([])); self::assertSame(0, $this->repository->count([]));
}); }
test('new create menu item', function (): void { public function testNewCreateMenuItem(): void
{
$this->client->request( $this->client->request(
'GET', 'GET',
sprintf('%snew/%s', $this->path, $this->order->getId()) sprintf('%snew/%s', $this->path, $this->order->getId())
); );
$this->assertResponseStatusCodeSame(200); self::assertResponseStatusCodeSame(200);
$this->client->submitForm('Save', [ $this->client->submitForm('Save', [
'order_item[name]' => 'Testing-1', 'order_item[name]' => 'Testing-1',
'order_item[extras]' => 'Testing-1', 'order_item[extras]' => 'Testing-1',
]); ]);
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId())); self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
$this->assertSame(1, $this->repository->count([])); self::assertSame(1, $this->repository->count([]));
$this->assertSame(3, $this->menuItemRepository->count([])); self::assertSame(3, $this->menuItemRepository->count([]));
}); }
test('remove', function (): void { public function testRemove(): void
{
$fixture = new OrderItem; $fixture = new OrderItem;
$fixture->setName('Testing'); $fixture->setName('Testing');
$fixture->setExtras('Value'); $fixture->setExtras('Value');
@ -128,11 +132,12 @@ describe(OrderItemController::class, function (): void {
$this->client->request('GET', sprintf('%sdelete/%s', $this->path, $fixture->getId())); $this->client->request('GET', sprintf('%sdelete/%s', $this->path, $fixture->getId()));
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId())); self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
$this->assertSame(0, $this->repository->count([])); self::assertSame(0, $this->repository->count([]));
}); }
test('order closed', function (): void { public function testOrderClosed(): void
{
$fixture = new OrderItem; $fixture = new OrderItem;
$fixture->setName('Testing'); $fixture->setName('Testing');
$fixture->setExtras('Value'); $fixture->setExtras('Value');
@ -147,11 +152,12 @@ describe(OrderItemController::class, function (): void {
$this->client->request('GET', sprintf('%sdelete/%s', $this->path, $fixture->getId())); $this->client->request('GET', sprintf('%sdelete/%s', $this->path, $fixture->getId()));
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId())); self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
$this->assertSame(1, $this->repository->count([])); self::assertSame(1, $this->repository->count([]));
}); }
test('edit', function (): void { public function testEdit(): void
{
$orderItem = new OrderItem; $orderItem = new OrderItem;
$orderItem->setName('Testing'); $orderItem->setName('Testing');
$orderItem->setExtras('My Extra'); $orderItem->setExtras('My Extra');
@ -179,14 +185,15 @@ describe(OrderItemController::class, function (): void {
'order_item[extras]' => 'Testing-1', 'order_item[extras]' => 'Testing-1',
]); ]);
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId())); self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
$this->assertSame(1, $this->repository->count([])); self::assertSame(1, $this->repository->count([]));
$this->assertSame(3, $this->menuItemRepository->count([])); self::assertSame(3, $this->menuItemRepository->count([]));
}); }
test('edit order closed', function (): void { public function testEditOrderClosed(): void
{
$orderItem = new OrderItem; $orderItem = new OrderItem;
$orderItem->setName('Testing'); $orderItem->setName('Testing');
$orderItem->setExtras('My Extra'); $orderItem->setExtras('My Extra');
@ -200,10 +207,11 @@ describe(OrderItemController::class, function (): void {
$this->manager->flush(); $this->manager->flush();
$this->client->request('GET', sprintf('%s%s/edit', $this->path, $orderItem->getId())); $this->client->request('GET', sprintf('%s%s/edit', $this->path, $orderItem->getId()));
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId())); self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
}); }
test('copy', function (): void { public function testCopy(): void
{
$orderItem = new OrderItem; $orderItem = new OrderItem;
$orderItem->setName('My Title'); $orderItem->setName('My Title');
$orderItem->setExtras('My Title'); $orderItem->setExtras('My Title');
@ -214,7 +222,7 @@ describe(OrderItemController::class, function (): void {
$this->manager->flush(); $this->manager->flush();
$this->client->request('GET', sprintf('%s%s/copy', $this->path, $orderItem->getId())); $this->client->request('GET', sprintf('%s%s/copy', $this->path, $orderItem->getId()));
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId())); self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
$result = $this->repository->findBy([ $result = $this->repository->findBy([
'foodOrder' => $this->order->getId(), 'foodOrder' => $this->order->getId(),
@ -224,9 +232,10 @@ describe(OrderItemController::class, function (): void {
$this->assertSame($orderItem->getName(), $item->getName()); $this->assertSame($orderItem->getName(), $item->getName());
$this->assertSame($orderItem->getExtras(), $item->getExtras()); $this->assertSame($orderItem->getExtras(), $item->getExtras());
} }
}); }
test('copy order closed', function (): void { public function testCopyOrderClosed(): void
{
$orderItem = new OrderItem; $orderItem = new OrderItem;
$orderItem->setName('My Title'); $orderItem->setName('My Title');
$orderItem->setExtras('My Title'); $orderItem->setExtras('My Title');
@ -239,23 +248,17 @@ describe(OrderItemController::class, function (): void {
$this->manager->flush(); $this->manager->flush();
$this->client->request('GET', sprintf('%s%s/copy', $this->path, $orderItem->getId())); $this->client->request('GET', sprintf('%s%s/copy', $this->path, $orderItem->getId()));
$this->assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId())); self::assertResponseRedirects(sprintf('/food/order/%s', $this->order->getId()));
$result = $this->repository->findBy([ $result = $this->repository->findBy([
'foodOrder' => $this->order->getId(), 'foodOrder' => $this->order->getId(),
]); ]);
$this->assertCount(1, $result); $this->assertCount(1, $result);
}); }
}) #[Override]
->covers( public function getEntityClass(): string
OrderItemController::class, {
MenuItemRepository::class, return OrderItem::class;
OrderItemRepository::class, }
OrderItemType::class, }
FoodOrder::class,
FoodVendor::class,
MenuItem::class,
OrderItem::class,
FoodOrderRepository::class,
);

View file

@ -1,26 +0,0 @@
<?php declare(strict_types=1);
namespace App\Tests;
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
use ApiPlatform\Symfony\Bundle\Test\Client;
use App\DataFixtures\AppFixtures;
use Doctrine\ORM\EntityManagerInterface;
use Liip\TestFixturesBundle\Services\DatabaseToolCollection;
use Override;
abstract class DbApiTestCase extends ApiTestCase
{
protected EntityManagerInterface $manager;
protected Client $client;
#[Override]
protected function setUp(): void
{
parent::setUp();
$this->client = static::createClient();
$this->manager = static::getContainer()->get('doctrine')->getManager();
$toolKit = self::getContainer()->get(DatabaseToolCollection::class)->get();
$toolKit->loadFixtures([AppFixtures::class]);
}
}

View file

@ -17,11 +17,11 @@ use function str_contains;
abstract class DbWebTest extends WebTestCase abstract class DbWebTest extends WebTestCase
{ {
abstract public function getEntityClass(): string;
protected KernelBrowser $client; protected KernelBrowser $client;
protected EntityManagerInterface $manager; protected EntityManagerInterface $manager;
protected EntityRepository $repository; protected EntityRepository $repository;
protected string $entityClass = '';
protected string $path = '';
#[Override] #[Override]
protected function setUp(): void protected function setUp(): void
@ -33,6 +33,10 @@ abstract class DbWebTest extends WebTestCase
->getAllMetadata(); ->getAllMetadata();
$schemaTool->dropDatabase(); $schemaTool->dropDatabase();
$schemaTool->updateSchema($metadata); $schemaTool->updateSchema($metadata);
if ($this->getEntityClass() !== '') {
$this->repository = $this->manager->getRepository($this->getEntityClass());
}
} }
protected function generateOldUlid(int $daysToSubtract = 10): Ulid protected function generateOldUlid(int $daysToSubtract = 10): Ulid
@ -52,15 +56,4 @@ abstract class DbWebTest extends WebTestCase
) )
); );
} }
protected function setEntityClass(string $entityClass): void
{
$this->entityClass = $entityClass;
$this->repository = $this->manager->getRepository($this->entityClass);
}
protected function setPath(string $path): void
{
$this->path = $path;
}
} }

View file

@ -0,0 +1,24 @@
<?php declare(strict_types=1);
namespace App\Tests\Entity;
use App\Entity\FoodOrder;
use App\Entity\OrderItem;
use PHPUnit\Framework\TestCase;
final class FoodOrderTest extends TestCase
{
public function testFoodOrder(): void
{
$order = new FoodOrder;
$orderItem = new OrderItem;
$this->assertCount(0, $order->getOrderItems());
$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());
}
}

View file

@ -1,17 +1,17 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
namespace App\Tests\Unit\Entity; namespace App\Tests\Entity;
use App\Entity\FoodOrder; use App\Entity\FoodOrder;
use App\Entity\FoodVendor; use App\Entity\FoodVendor;
use App\Entity\MenuItem; use App\Entity\MenuItem;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Uid\Ulid; use Symfony\Component\Uid\Ulid;
use function describe; final class FoodVendorTest extends TestCase
use function test; {
public function testFoodVendor(): void
describe(FoodVendor::class, function (): void { {
test('FoodVendor entity', function (): void {
$vendor = new FoodVendor; $vendor = new FoodVendor;
$vendor->setName('Test'); $vendor->setName('Test');
$this->assertEquals('Test', $vendor->getName()); $this->assertEquals('Test', $vendor->getName());
@ -29,9 +29,11 @@ describe(FoodVendor::class, function (): void {
$vendor->removeFoodOrder($order1); $vendor->removeFoodOrder($order1);
$this->assertCount(0, $vendor->getFoodOrders()); $this->assertCount(0, $vendor->getFoodOrders());
$this->assertNull($order1->getFoodVendor()); $this->assertNull($order1->getFoodVendor());
});
test('MenutItem entity', function (): void { }
public function testMenuItem(): void
{
$vendor = new FoodVendor; $vendor = new FoodVendor;
$menuItem1 = new MenuItem; $menuItem1 = new MenuItem;
$menuItem2 = new MenuItem; $menuItem2 = new MenuItem;
@ -47,9 +49,10 @@ describe(FoodVendor::class, function (): void {
$vendor->addMenuItem($menuItem2); $vendor->addMenuItem($menuItem2);
$this->assertCount(1, $vendor->getMenuItems()); $this->assertCount(1, $vendor->getMenuItems());
$this->assertCount(2, $vendor->getMenuItems(true)); $this->assertCount(2, $vendor->getMenuItems(true));
}); }
test('remove foreign menu item', function (): void { public function testRemoveForeignMenuItem(): void
{
$vendor1 = new FoodVendor; $vendor1 = new FoodVendor;
$vendor2 = new FoodVendor; $vendor2 = new FoodVendor;
$item1 = new MenuItem; $item1 = new MenuItem;
@ -59,6 +62,5 @@ describe(FoodVendor::class, function (): void {
$vendor2->removeMenuItem($item1); $vendor2->removeMenuItem($item1);
$this->assertCount(1, $vendor1->getMenuItems()); $this->assertCount(1, $vendor1->getMenuItems());
$this->assertSame($vendor1, $item1->getFoodVendor()); $this->assertSame($vendor1, $item1->getFoodVendor());
}); }
}
})->covers(FoodVendor::class, FoodOrder::class, MenuItem::class);

View file

@ -0,0 +1,30 @@
<?php declare(strict_types=1);
namespace App\Tests\Entity;
use App\Entity\FoodVendor;
use App\Entity\MenuItem;
use DateTimeImmutable;
use PHPUnit\Framework\TestCase;
final class MenuItemTest extends TestCase
{
public function testMenuItem(): void
{
$item = new MenuItem;
$item->setName('Test');
$this->assertEquals('Test', $item->getName());
$vendor = new FoodVendor;
$vendor->setName('Test');
$item->setFoodVendor($vendor);
$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());
}
}

View file

@ -1,15 +0,0 @@
<?php declare(strict_types=1);
test('orders', function (): void {
$response = $this->client->request('GET', '/api/food_orders');
$this->assertResponseIsSuccessful();
$this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
$this->assertJsonContains([
'@context' => '/api/contexts/FoodOrder',
'@id' => '/api/food_orders',
'@type' => 'Collection',
'totalItems' => 1,
]);
$array = $response->toArray();
expect($array['member'][0]['orderItems'])->toHaveCount(10);
});

View file

@ -1,71 +0,0 @@
<?php declare(strict_types=1);
namespace App\Tests\Feature\Controller;
use App\Controller\HomeController;
use App\Form\UserNameFormType;
use function describe;
use function test;
describe(HomeController::class, function (): void {
test('index', function (): void {
$this->client->request(
'GET',
'/'
);
$this->assertResponseStatusCodeSame(302);
$this->assertResponseHeaderSame('Location', '/food/order/list');
});
test('username', function (): void {
$this->client->request(
'GET',
'/username',
);
$this->assertResponseStatusCodeSame(200);
$this->client->submitForm('Save', [
'user_name_form[username]' => 'Testing-1',
]);
$this->assertResponseStatusCodeSame(302);
$this->assertResponseHeaderSame('Location', '/food/order/list');
$this->assertResponseCookieValueSame('username', 'Testing-1');
$crawler = $this->client->request(
'GET',
'/username',
);
$this->assertResponseStatusCodeSame(200);
$this->assertSame(
$crawler->filter('#user_name_form_username')
->last()
->attr('value', ''),
'Testing-1'
);
});
test('username empty', function (): void {
$this->client->request(
'GET',
'/username',
);
$this->assertResponseStatusCodeSame(200);
$this->client->submitForm('Save', [
'user_name_form[username]' => '',
]);
$this->assertResponseStatusCodeSame(302);
$this->assertResponseHeaderSame('Location', '/food/order/list');
$this->assertResponseCookieValueSame('username', '');
});
})
->covers(HomeController::class, UserNameFormType::class);

View file

@ -1,159 +0,0 @@
<?php declare(strict_types=1);
namespace App\Tests\Feature\Controller;
use App\Controller\MenuItemController;
use App\Controller\OrderItemController;
use App\Entity\FoodOrder;
use App\Entity\FoodVendor;
use App\Entity\MenuItem;
use App\Entity\OrderItem;
use App\Form\MenuItemType;
use App\Form\OrderItemType;
use App\Repository\FoodOrderRepository;
use App\Repository\MenuItemRepository;
use function describe;
use function pest;
use function sprintf;
use function test;
pest()
->beforeEach(function (): void {
$this->setEntityClass(MenuItem::class);
$this->setPath('/menu/item/');
$this->repository = $this->manager->getRepository($this->entityClass);
$this->vendor = new FoodVendor;
$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();
});
describe(MenuItemController::class, function (): void {
test('show', function (): void {
$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();
$this->assertResponseStatusCodeSame(200);
$this->assertEquals($idValue, $this->menuItem->getId());
$this->assertEquals($nameValue, $this->menuItem->getName());
$this->assertEquals($aliasTwoNameValue, $this->aliasOne->getName());
$this->assertEquals($aliasOneNameValue, $this->aliasTwo->getName());
});
test('edit', function (): 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]'] = 'Testing-1';
$form['menu_item[aliases]'][0]->untick();
$this->client->submit($form);
$this->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());
});
test('edit invalid', function (): 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);
$this->assertResponseStatusCodeSame(422);
});
test('delete', function (): void {
$order = new FoodOrder;
$order->setFoodVendor($this->vendor);
$this->manager->persist($order);
$this->manager->flush();
$this->assertFalse($this->menuItem->isDeleted());
$this->client->request('GET', "{$this->path}{$this->menuItem->getId()}");
$this->client->submitForm('Delete', []);
$menuItem = $this->repository->find($this->menuItem->getId());
$this->assertTrue($menuItem->isDeleted());
$crawler = $this->client->request('GET', '/order/item/new/' . $order->getId());
$count = $crawler->filter('body > main:nth-child(2) > div:nth-child(5)')
->children()
->count();
$this->assertSame(2, $count);
$this->assertResponseIsSuccessful();
});
})
->covers(
MenuItemController::class,
OrderItemController::class,
OrderItemType::class,
MenuItemRepository::class,
FoodOrder::class,
FoodVendor::class,
MenuItem::class,
OrderItem::class,
FoodOrderRepository::class,
MenuItemType::class,
);

View file

@ -1,36 +0,0 @@
<?php declare(strict_types=1);
use App\Tests\DbApiTestCase;
use App\Tests\DbWebTest;
/*
|--------------------------------------------------------------------------
| Test Case
|--------------------------------------------------------------------------
|
| The closure you provide to your test functions is always bound to a specific PHPUnit test
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
| need to change it using the "pest()" function to bind a different classes or traits.
|
*/
pest()
->extends(DbWebTest::class)->in('Feature/Controller/*.php');
pest()
->extends(DbApiTestCase::class)->in('Feature/Api/*.php');
/*
|--------------------------------------------------------------------------
| Functions
|--------------------------------------------------------------------------
|
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
| project that you don't want to repeat in every file. Here you can also expose helpers as
| global functions to help you to reduce the number of lines of code in your test files.
|
*/
function something(): void
{
// ..
}

View file

@ -1,10 +0,0 @@
<?php declare(strict_types=1);
namespace Tests;
use PHPUnit\Framework\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
//
}

View file

@ -1,32 +0,0 @@
<?php declare(strict_types=1);
namespace App\Tests\Unit\Entity;
use App\Entity\FoodOrder;
use App\Entity\OrderItem;
use function expect;
use function test;
test('FoodOrder Entity', function (): void {
$order = new FoodOrder;
$orderItem = new OrderItem;
expect($order->getOrderItems())
->toBeEmpty();
$order->addOrderItem($orderItem);
$order->addOrderItem($orderItem);
expect($order->getOrderItems())
->toHaveCount(1)
->and($orderItem->getFoodOrder())
->toBe($order);
$order->removeOrderItem($orderItem);
expect($order->getOrderItems())
->toBeEmpty()
->and($orderItem->getFoodOrder())
->toBeNull();
})
->covers(FoodOrder::class, OrderItem::class);

View file

@ -1,53 +0,0 @@
<?php declare(strict_types=1);
namespace App\Tests\Unit\Entity;
use App\Entity\FoodVendor;
use App\Entity\MenuItem;
use DateTimeImmutable;
use function describe;
use function test;
describe(MenuItem::class, function (): void {
test('MenuItem entity', function (): void {
$item = new MenuItem;
$item->setName('Test');
$this->assertEquals('Test', $item->getName());
$vendor = new FoodVendor;
$vendor->setName('Test');
$item->setFoodVendor($vendor);
$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());
});
test('MenuItem alias', function (): 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());
});
})->covers(MenuItem::class, FoodVendor::class);

View file

@ -6,8 +6,6 @@ require dirname(__DIR__) . '/vendor/autoload.php';
if (method_exists(Dotenv::class, 'bootEnv')) { if (method_exists(Dotenv::class, 'bootEnv')) {
(new Dotenv)->bootEnv(dirname(__DIR__) . '/.env'); (new Dotenv)->bootEnv(dirname(__DIR__) . '/.env');
$token = $_SERVER['TEST_TOKEN'] ?? '';
$_ENV['DATABASE_URL'] .= $token;
} }
if ($_SERVER['APP_DEBUG']) { if ($_SERVER['APP_DEBUG']) {