Compare commits

..

2 commits

Author SHA1 Message Date
André Lubian
0c1cf45137 fix style 2024-10-21 18:55:01 +02:00
André Lubian
1537b157b5 addapi 2024-10-21 18:45:21 +02:00
26 changed files with 2979 additions and 752 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

@ -3,7 +3,7 @@ jobs:
ls:
runs-on: docker
container:
image: git.php.fail/lubiana/container/php:8.4.1-ci
image: git.php.fail/lubiana/container/php:ci
steps:
- name: Manually checkout
env:

View file

@ -6,7 +6,7 @@ jobs:
ls:
runs-on: docker
container:
image: git.php.fail/lubiana/container/php:8.4.1-ci
image: git.php.fail/lubiana/container/php:ci
steps:
- name: Manually checkout
env:

View file

@ -4,7 +4,7 @@ jobs:
ls:
runs-on: docker
container:
image: git.php.fail/lubiana/container/php:8.4.1-ci
image: git.php.fail/lubiana/container/php:ci
steps:
- name: Manually checkout
env:

View file

@ -7,18 +7,29 @@
"php": ">=8.3",
"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.4",
"phpstan/phpdoc-parser": "^1.30",
"psr/clock": "^1.0",
"symfony/asset": "7.1.*",
"symfony/console": "7.1.*",
"symfony/dotenv": "7.1.*",
"symfony/expression-language": "7.1.*",
"symfony/flex": "^2.4.6",
"symfony/form": "7.1.*",
"symfony/framework-bundle": "7.1.*",
"symfony/property-access": "7.1.*",
"symfony/property-info": "7.1.*",
"symfony/runtime": "7.1.*",
"symfony/security-bundle": "7.1.*",
"symfony/security-csrf": "7.1.*",
"symfony/serializer": "7.1.*",
"symfony/twig-bundle": "7.1.*",
"symfony/uid": "7.1.*",
"symfony/validator": "7.1.*",

3393
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,9 +1,12 @@
<?php declare(strict_types=1);
use ApiPlatform\Symfony\Bundle\ApiPlatformBundle;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle;
use Nelmio\CorsBundle\NelmioCorsBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\MakerBundle\MakerBundle;
use Symfony\Bundle\SecurityBundle\SecurityBundle;
use Symfony\Bundle\TwigBundle\TwigBundle;
return [
@ -22,4 +25,13 @@ return [
TwigBundle::class => [
'all' => true,
],
SecurityBundle::class => [
'all' => true,
],
NelmioCorsBundle::class => [
'all' => true,
],
ApiPlatformBundle::class => [
'all' => true,
],
];

View file

@ -0,0 +1,20 @@
<?php declare(strict_types=1);
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->extension('api_platform', [
'title' => 'Hello API Platform',
'version' => '1.0.0',
'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

@ -14,7 +14,9 @@
"@default": true,
"global-ignore": [
"App\\Service\\Favicon::__toString",
"ORM\\Column.*"
],
"global-ignoreSourceCodeByRegex": [
"#\\[ORM\\\\Column.*"
]
}
}

View file

@ -1,35 +0,0 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20241218235101 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE food_vendor ADD COLUMN phone VARCHAR(50) DEFAULT \'\'');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TEMPORARY TABLE __temp__food_vendor AS SELECT name, menu_link, id FROM food_vendor');
$this->addSql('DROP TABLE food_vendor');
$this->addSql('CREATE TABLE food_vendor (name VARCHAR(50) NOT NULL, menu_link VARCHAR(255) DEFAULT NULL, id BLOB NOT NULL, PRIMARY KEY(id))');
$this->addSql('INSERT INTO food_vendor (name, menu_link, id) SELECT name, menu_link, id FROM __temp__food_vendor');
$this->addSql('DROP TABLE __temp__food_vendor');
}
}

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

View file

@ -23,10 +23,8 @@ final class FoodVendorController extends AbstractController
}
#[Route('/new', name: 'app_food_vendor_new', methods: ['GET', 'POST'])]
public function new(
Request $request,
EntityManagerInterface $entityManager
): Response {
public function new(Request $request, EntityManagerInterface $entityManager): Response
{
$foodVendor = new FoodVendor;
$form = $this->createForm(FoodVendorType::class, $foodVendor);
$form->handleRequest($request);
@ -65,6 +63,7 @@ final class FoodVendorController extends AbstractController
}
return $this->render('food_vendor/edit.html.twig', [
'food_vendor' => $foodVendor,
'form' => $form,
]);
}

View file

@ -2,6 +2,7 @@
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\FoodOrderRepository;
use DateInterval;
use DateTimeImmutable;
@ -14,6 +15,8 @@ use Symfony\Component\Uid\Ulid;
use function iterator_to_array;
#[ORM\Entity(repositoryClass: FoodOrderRepository::class)]
#[ApiResource(
)]
class FoodOrder
{
#[ORM\Column(nullable: true)]

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;
@ -9,18 +10,17 @@ use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Symfony\Bridge\Doctrine\Types\UlidType;
use Symfony\Component\Uid\Ulid;
use Symfony\Component\Validator\Constraints\NotBlank;
#[ORM\Entity(repositoryClass: FoodVendorRepository::class)]
#[ApiResource(
)]
class FoodVendor
{
#[ORM\Column(length: 50)]
#[NotBlank]
private string|null $name = null;
#[ORM\Column(length: 50, nullable: true, options: [
'default' => '',
])]
private string|null $phone = null;
/**
* @var Collection<int, FoodOrder>
*/
@ -36,13 +36,17 @@ class FoodVendor
#[ORM\Column(length: 255, nullable: true)]
private string|null $menuLink = null;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\Column(type: UlidType::NAME, unique: true)]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
private Ulid|null $id = null;
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
) {
if (! $this->id instanceof Ulid) {
$this->id = new Ulid;
}
$this->foodOrders = new ArrayCollection;
$this->menuItems = new ArrayCollection;
}
@ -136,15 +140,4 @@ class FoodVendor
return $this;
}
public function getPhone(): string|null
{
return $this->phone;
}
public function setPhone(string|null $phone): static
{
$this->phone = $phone;
return $this;
}
}

View file

@ -2,6 +2,7 @@
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\MenuItemRepository;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
@ -10,6 +11,8 @@ use Symfony\Bridge\Doctrine\Types\UlidType;
use Symfony\Component\Uid\Ulid;
#[ORM\Entity(repositoryClass: MenuItemRepository::class)]
#[ApiResource(
)]
class MenuItem
{
#[ORM\Column(length: 255)]

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,6 +10,8 @@ use Symfony\Bridge\Doctrine\Types\UlidType;
use Symfony\Component\Uid\Ulid;
#[ORM\Entity(repositoryClass: OrderItemRepository::class)]
#[ApiResource(
)]
class OrderItem
{
#[ORM\Id]

View file

@ -16,7 +16,6 @@ final class FoodVendorType extends AbstractType
$builder
->add('name')
->add('menuLink')
->add('phone')
;
}

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": {
@ -26,6 +40,18 @@
"migrations/.gitignore"
]
},
"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": {
@ -138,6 +164,19 @@
"config/routes.yaml"
]
},
"symfony/security-bundle": {
"version": "7.1",
"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

@ -11,10 +11,6 @@
<th>Vendor</th>
<td>{{ food_order.foodVendor.name }}</td>
</tr>
<tr>
<th>Vendorphone</th>
<td>{{ food_order.foodVendor.phone }}</td>
</tr>
<tr>
<th>Created By</th>
<td>{{ food_order.createdBy }}</td>

View file

@ -8,13 +8,10 @@ use App\Entity\MenuItem;
use App\Entity\OrderItem;
use App\Tests\DbWebTest;
use Override;
use Symfony\Component\BrowserKit\Cookie;
use Symfony\Component\DomCrawler\Crawler;
use function assert;
use function range;
use function sprintf;
use function str_ends_with;
final class FoodOrderControllerTest extends DbWebTest
{
@ -140,10 +137,10 @@ final class FoodOrderControllerTest extends DbWebTest
}
/**
* @testWith [1, 0, 2]
* [2, 1, 3]
* [3, 2, 4]
* [4, 3, 0, 5]
* @testWith [1, 0, 1]
* [2, 1, 1]
* [3, 1, 1]
* [4, 1, 0, 5]
*/
public function testPaginatedFirstPage(int $page, int $prevPage, int $nextPage, int $items = 10): void
{
@ -157,27 +154,22 @@ final class FoodOrderControllerTest extends DbWebTest
$items,
'nobody'
);
if ($prevPage > 0) {
$prevPage = $prevPage === 1 ? '' : "/{$prevPage}";
$node = $crawler->filter('a')
->reduce(static fn(Crawler $node, $i): bool => $node->text() === 'previous page')
->first();
$target = $node->attr('href');
$this->assertTrue(str_ends_with((string) $target, $prevPage));
}
if ($prevPage > 3) {
$node = $crawler->filter('a')
->reduce(static fn(Crawler $node, $i): bool => $node->text() === 'next page')
->first();
$target = $node->attr('href');
$this->assertTrue(str_ends_with((string) $target, "/{$nextPage}"));
}
$this->assertElementContainsCount(
$crawler,
'a',
$nextPage,
'next page'
);
$this->assertElementContainsCount(
$crawler,
'a',
$prevPage,
'previous page'
);
}
public function testNew(): void
{
$this->client->getCookieJar()
->set(new Cookie('username', 'Testing-1'));
$this->client->request('GET', sprintf('%snew', $this->path));
self::assertResponseStatusCodeSame(200);
@ -188,10 +180,6 @@ final class FoodOrderControllerTest extends DbWebTest
self::assertResponseRedirects("{$this->path}list");
self::assertSame(1, $this->repository->count([]));
$order = $this->repository->findOneBy([
'createdBy' => 'Testing-1',
]);
assert($order instanceof FoodOrder);
}
public function testOpen(): void

View file

@ -114,8 +114,6 @@ final class FoodVendorControllerTest extends DbWebTest
{
$fixture = new FoodVendor;
$fixture->setName('Value');
$fixture->setMenuLink('Value');
$fixture->setPhone('Value');
$this->manager->persist($fixture);
$this->manager->flush();
@ -127,23 +125,10 @@ final class FoodVendorControllerTest extends DbWebTest
->attr('value', ''),
'Value'
);
$this->assertSame(
$crawler->filter('#food_vendor_menuLink')
->last()
->attr('value', ''),
'Value'
);
$this->assertSame(
$crawler->filter('#food_vendor_phone')
->last()
->attr('value', ''),
'Value'
);
$this->client->submitForm('Update', [
'food_vendor[name]' => 'Something New',
'food_vendor[menuLink]' => 'https://example.com/',
'food_vendor[phone]' => '1234567890',
]);
self::assertResponseRedirects('/food/vendor/');
@ -152,7 +137,6 @@ final class FoodVendorControllerTest extends DbWebTest
self::assertSame('Something New', $fixture[0]->getName());
self::assertSame('https://example.com/', $fixture[0]->getMenuLink());
self::assertSame('1234567890', $fixture[0]->getPhone());
}
#[Override]

View file

@ -16,9 +16,6 @@ final class FoodVendorTest extends TestCase
$vendor->setName('Test');
$this->assertEquals('Test', $vendor->getName());
$this->assertInstanceOf(Ulid::class, $vendor->getId());
$this->assertEmpty($vendor->getPhone());
$vendor->setPhone('1234567890');
$this->assertEquals('1234567890', $vendor->getPhone());
$this->assertCount(0, $vendor->getFoodOrders());
$order1 = new FoodOrder;