Fix unit test :)

pull/1/head
Hecht 3 months ago
parent 9d8f35045e
commit 8e2afe640d

12
composer.lock generated

@ -8593,16 +8593,16 @@
},
{
"name": "symfony/phpunit-bridge",
"version": "v7.0.2",
"version": "v7.0.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/phpunit-bridge.git",
"reference": "92df075808c9437beca9540e25ae0c40eea1c061"
"reference": "0a2eeb0d9e68bf01660e3e903f8113508bb46132"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/phpunit-bridge/zipball/92df075808c9437beca9540e25ae0c40eea1c061",
"reference": "92df075808c9437beca9540e25ae0c40eea1c061",
"url": "https://api.github.com/repos/symfony/phpunit-bridge/zipball/0a2eeb0d9e68bf01660e3e903f8113508bb46132",
"reference": "0a2eeb0d9e68bf01660e3e903f8113508bb46132",
"shasum": ""
},
"require": {
@ -8654,7 +8654,7 @@
"description": "Provides utilities for PHPUnit, especially user deprecation notices management",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/phpunit-bridge/tree/v7.0.2"
"source": "https://github.com/symfony/phpunit-bridge/tree/v7.0.3"
},
"funding": [
{
@ -8670,7 +8670,7 @@
"type": "tidelift"
}
],
"time": "2023-12-19T11:23:03+00:00"
"time": "2024-01-23T15:02:46+00:00"
},
{
"name": "symfony/process",

@ -4,9 +4,10 @@ doctrine:
# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '15'
server_version: '%env(resolve:DATABASE_VERSION)%'
profiling_collect_backtrace: '%kernel.debug%'
use_savepoints: true
orm:
auto_generate_proxy_classes: true
enable_lazy_ghost_objects: true

@ -0,0 +1,31 @@
<?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 Version20240129212818 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
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE SCHEMA public');
}
}

@ -4,14 +4,14 @@ namespace App\Entity;
use ApiPlatform\Metadata\ApiProperty;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\OneToOne;
#[ORM\Entity]
#[Entity]
class Dojo extends Thing
{
@ -29,7 +29,9 @@ class Dojo extends Thing
#[JoinColumn(onDelete: 'cascade', nullable: true)]
public ?Village $village;
#[OneToOne(inversedBy: 'dojo')]
#[OneToOne(inversedBy: 'dojo', cascade: [
'persist'
])]
#[JoinColumn(onDelete: 'cascade', nullable: false)]
public User $owner;
@ -59,6 +61,7 @@ class Dojo extends Thing
}
/**
*
* @return Collection<int, Character>
*/
public function getMembers(): Collection
@ -68,7 +71,7 @@ class Dojo extends Thing
public function addMember(Character $member): static
{
if (!$this->members->contains($member)) {
if (! $this->members->contains($member)) {
$this->members->add($member);
$member->setDojo($this);
}

@ -28,6 +28,12 @@ class User extends Thing implements UserInterface
#[Column(type: 'json')]
public mixed $properties;
public function __construct(string $authName)
{
$this->authName = $authName;
$this->properties = [];
}
public function getProperties(): array
{
return $this->properties;

@ -1,6 +1,7 @@
<?php
namespace App\Security;
use App\Entity\User;
use App\Repository\UserRepository;
use Psr\Log\LoggerInterface;
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
@ -43,8 +44,16 @@ class AccessTokenHandler implements AccessTokenHandlerInterface
}
$auth_name = $arr[0];
$this->logger->critical("Nearly there! $auth_name");
return new UserBadge($auth_name, fn (string $id) => $this->userRepository->findByAuthName($id));
return new UserBadge($auth_name, fn (string $id) => $this->getOrCreateUser($id));
}
private function getOrCreateUser(string $authName): User
{
$user = $this->userRepository->findOneByAuthName($authName);
if (NULL === $user) {
$user = new User($authName);
}
return $user;
}
}

@ -0,0 +1,3 @@
#!/bin/bash
podman run --rm --name ag-dojo-postgres -e POSTGRES_USER=foo -e POSTGRES_PASSWORD=bar -e POSTGRES_HOST_AUTH_METHOD=trust -p "5432:5432" docker.io/library/postgres:14.5

@ -3,7 +3,6 @@ namespace App\Tests;
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
use ApiPlatform\Symfony\Bundle\Test\Response;
use App\Factory\UserFactory;
use App\Repository\UserRepository;
use Zenstruck\Foundry\Test\Factories;
use Zenstruck\Foundry\Test\ResetDatabase;
@ -28,13 +27,6 @@ class DojoTest extends ApiTestCase
public function testCreateDojo(): void
{
UserFactory::createOne([
'authName' => "blablabla"
]);
$userRepository = $this->getContainer()->get(UserRepository::class);
$this->assertCount(1, $userRepository->findAll());
/**
*
* @var Response $response
@ -51,6 +43,9 @@ class DojoTest extends ApiTestCase
]);
$this->assertResponseStatusCodeSame(201);
$userRepository = $this->getContainer()->get(UserRepository::class);
$this->assertCount(1, $userRepository->findAll());
}
}

Loading…
Cancel
Save