Compare commits

...

6 commits
0.2.3 ... main

Author SHA1 Message Date
696760659f
add index to loop
Some checks failed
/ ls (pull_request) Failing after 1m26s
/ ls (release) Successful in 56s
/ ls (push) Failing after 1m22s
2025-02-07 19:34:01 +01:00
5a0df96142
add link to api
Some checks failed
/ ls (pull_request) Failing after 24s
/ ls (release) Successful in 55s
/ ls (push) Successful in 1m27s
2025-02-07 12:27:16 +01:00
b00b923d43
add simple apitest
All checks were successful
/ ls (pull_request) Successful in 1m30s
/ ls (push) Successful in 1m28s
/ ls (release) Successful in 1m1s
2025-02-06 20:35:49 +01:00
d92a63fd7d
add rest api
All checks were successful
/ ls (pull_request) Successful in 1m30s
/ ls (push) Successful in 1m27s
/ ls (release) Successful in 59s
2025-02-02 21:15:44 +01:00
2b5d943116
enable parallel testing
All checks were successful
/ ls (pull_request) Successful in 1m27s
/ ls (push) Successful in 1m24s
2025-02-02 21:01:45 +01:00
9119029419
update deployment folder for php 8.4
Some checks failed
/ ls (pull_request) Failing after 22s
/ ls (push) Successful in 2m5s
2025-02-01 22:44:28 +01:00
25 changed files with 2771 additions and 292 deletions

4
.env
View file

@ -28,3 +28,7 @@ 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="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8"
###< doctrine/doctrine-bundle ###
###> nelmio/cors-bundle ###
CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$'
###< nelmio/cors-bundle ###

View file

@ -7,18 +7,29 @@
"php": ">=8.4",
"ext-ctype": "*",
"ext-iconv": "*",
"api-platform/doctrine-orm": "^4.0",
"api-platform/symfony": "^4.0",
"doctrine/dbal": "^4.1",
"doctrine/doctrine-bundle": "^2.12",
"doctrine/doctrine-migrations-bundle": "^3.3.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",
"symfony/asset": "7.2.*",
"symfony/console": "7.1.*",
"symfony/dotenv": "7.1.*",
"symfony/expression-language": "7.2.*",
"symfony/flex": "^2.4.6",
"symfony/form": "7.1.*",
"symfony/framework-bundle": "7.1.*",
"symfony/property-access": "7.2.*",
"symfony/property-info": "7.2.*",
"symfony/runtime": "7.1.*",
"symfony/security-bundle": "7.2.*",
"symfony/security-csrf": "7.1.*",
"symfony/serializer": "7.2.*",
"symfony/twig-bundle": "7.1.*",
"symfony/uid": "7.1.*",
"symfony/validator": "7.1.*",
@ -26,10 +37,12 @@
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^4.0",
"liip/test-fixtures-bundle": "^3.2",
"lubiana/code-quality": "^1.7.2",
"pestphp/pest": "^3.6",
"symfony/browser-kit": "7.2.*",
"symfony/css-selector": "7.2.*",
"symfony/http-client": "7.2.*",
"symfony/maker-bundle": "^1.60",
"symfony/stopwatch": "7.2.*",
"symfony/web-profiler-bundle": "7.2.*",
@ -85,7 +98,7 @@
"rector",
"ecs --fix || ecs --fix"
],
"test": "pest"
"test": "pest --parallel"
},
"conflict": {
"symfony/symfony": "*"

2775
composer.lock generated

File diff suppressed because it is too large Load diff

View file

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

View file

@ -0,0 +1,22 @@
<?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

@ -0,0 +1,33 @@
<?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

@ -0,0 +1,40 @@
<?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

@ -0,0 +1,8 @@
<?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

@ -0,0 +1,7 @@
<?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,7 +15,6 @@ do
cp -r ../../"$path" ./
done
rm ./bin/phpunit
APP_ENV=prod composer install --no-dev -a
rm -rf ./var/cache

View file

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

0
src/ApiResource/.gitignore vendored Normal file
View file

View file

@ -2,8 +2,10 @@
namespace App\DataFixtures;
use App\Entity\FoodOrder;
use App\Entity\FoodVendor;
use App\Entity\MenuItem;
use App\Entity\OrderItem;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use Override;
@ -39,12 +41,26 @@ final class AppFixtures extends Fixture
public function addMenuItemsToVendor(FoodVendor $vendor): void
{
$menuItems = [];
foreach (range(1, 10) as $i) {
$item = new MenuItem;
$item->setName("{$vendor->getName()} Item {$i}");
$item->setFoodVendor($vendor);
$this->manager->persist($item);
$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,6 +2,7 @@
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\FoodOrderRepository;
use DateInterval;
use DateTimeImmutable;
@ -14,6 +15,7 @@ use Symfony\Component\Uid\Ulid;
use function iterator_to_array;
#[ORM\Entity(repositoryClass: FoodOrderRepository::class)]
#[ApiResource]
class FoodOrder
{
#[ORM\Column(nullable: true)]
@ -39,6 +41,7 @@ class FoodOrder
#[ORM\Column(type: UlidType::NAME, unique: true)]
private Ulid|null $id = new Ulid
) {
$this->id ??= new Ulid;
$this->orderItems = new ArrayCollection;
$this->open();
}

View file

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

View file

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

View file

@ -2,6 +2,7 @@
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\OrderItemRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
@ -9,14 +10,9 @@ use Symfony\Bridge\Doctrine\Types\UlidType;
use Symfony\Component\Uid\Ulid;
#[ORM\Entity(repositoryClass: OrderItemRepository::class)]
#[ApiResource]
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)]
private string|null $name = null;
@ -36,6 +32,16 @@ class OrderItem
])]
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
{
return $this->id;
@ -85,6 +91,7 @@ class OrderItem
public function setMenuItem(MenuItem|null $menuItem): static
{
$this->menuItem = $menuItem;
$this->name = $menuItem->getName();
return $this;
}

View file

@ -1,4 +1,18 @@
{
"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": {
"version": "2.12",
"recipe": {
@ -38,6 +52,21 @@
"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": {
"version": "1.11",
"recipe": {
@ -135,6 +164,19 @@
"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": {
"version": "7.1",
"recipe": {

View file

@ -34,7 +34,8 @@
<a
href="https://git.hannover.ccc.de/lubiana/futtern/issues/new"
target="_blank"
>Create Issue</a>
>Create Issue</a> /
<a href="/api">API</a>
</nav>
</header>
<main>

View file

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

26
tests/DbApiTestCase.php Normal file
View file

@ -0,0 +1,26 @@
<?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

@ -0,0 +1,15 @@
<?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,5 +1,6 @@
<?php declare(strict_types=1);
use App\Tests\DbApiTestCase;
use App\Tests\DbWebTest;
/*
@ -15,6 +16,8 @@ use App\Tests\DbWebTest;
pest()
->extends(DbWebTest::class)->in('Feature/Controller/*.php');
pest()
->extends(DbApiTestCase::class)->in('Feature/Api/*.php');
/*
|--------------------------------------------------------------------------

View file

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