Compare commits
No commits in common. "f93a2e5e19c889c448af67e25a2859f0486efabd" and "cc213bfb15d4d2b68e136ef972cce144c6775396" have entirely different histories.
f93a2e5e19
...
cc213bfb15
6 changed files with 12 additions and 134 deletions
|
|
@ -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 Version20260602224032 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 subject ADD created_by_id INT DEFAULT NULL');
|
|
||||||
$this->addSql('ALTER TABLE subject ADD CONSTRAINT FK_FBCE3E7AB03A8386 FOREIGN KEY (created_by_id) REFERENCES "user" (id) NOT DEFERRABLE');
|
|
||||||
$this->addSql('CREATE INDEX IDX_FBCE3E7AB03A8386 ON subject (created_by_id)');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function down(Schema $schema): void
|
|
||||||
{
|
|
||||||
// this down() migration is auto-generated, please modify it to your needs
|
|
||||||
$this->addSql('ALTER TABLE subject DROP CONSTRAINT FK_FBCE3E7AB03A8386');
|
|
||||||
$this->addSql('DROP INDEX IDX_FBCE3E7AB03A8386');
|
|
||||||
$this->addSql('ALTER TABLE subject DROP created_by_id');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -32,7 +32,6 @@ class SubjectController extends AbstractController
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
$subject->setCreatedBy($this->getUser());
|
|
||||||
$em->persist($subject);
|
$em->persist($subject);
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,6 @@ class Subject
|
||||||
#[ORM\Column(length: 255)]
|
#[ORM\Column(length: 255)]
|
||||||
private ?string $name = null;
|
private ?string $name = null;
|
||||||
|
|
||||||
#[ORM\ManyToOne]
|
|
||||||
#[ORM\JoinColumn(nullable: true)]
|
|
||||||
private ?User $createdBy = null;
|
|
||||||
|
|
||||||
public function getId(): ?int
|
public function getId(): ?int
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
|
|
@ -40,16 +36,4 @@ class Subject
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCreatedBy(): ?User
|
|
||||||
{
|
|
||||||
return $this->createdBy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setCreatedBy(?User $createdBy): static
|
|
||||||
{
|
|
||||||
$this->createdBy = $createdBy;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,55 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Factory;
|
|
||||||
|
|
||||||
use App\Entity\User;
|
|
||||||
use App\Repository\UserRepository;
|
|
||||||
use Doctrine\ORM\EntityRepository;
|
|
||||||
use Zenstruck\Foundry\Persistence\PersistentObjectFactory;
|
|
||||||
use Zenstruck\Foundry\Persistence\Proxy;
|
|
||||||
use Zenstruck\Foundry\Persistence\ProxyRepositoryDecorator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @extends PersistentObjectFactory<User>
|
|
||||||
*/
|
|
||||||
final class UserFactory extends PersistentObjectFactory
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services
|
|
||||||
*
|
|
||||||
* @todo inject services if required
|
|
||||||
*/
|
|
||||||
public function __construct() {}
|
|
||||||
|
|
||||||
#[\Override]
|
|
||||||
public static function class(): string
|
|
||||||
{
|
|
||||||
return User::class;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories
|
|
||||||
*
|
|
||||||
* @todo add your default values here
|
|
||||||
*/
|
|
||||||
#[\Override]
|
|
||||||
protected function defaults(): array|callable
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'email' => self::faker()->text(180),
|
|
||||||
'password' => self::faker()->text(),
|
|
||||||
'roles' => [],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization
|
|
||||||
*/
|
|
||||||
#[\Override]
|
|
||||||
protected function initialize(): static
|
|
||||||
{
|
|
||||||
return $this
|
|
||||||
// ->afterInstantiate(function(User $user): void {})
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -3,21 +3,28 @@
|
||||||
namespace App\Tests\Integration\Subject;
|
namespace App\Tests\Integration\Subject;
|
||||||
|
|
||||||
use App\Entity\Restaurant;
|
use App\Entity\Restaurant;
|
||||||
use App\Factory\UserFactory;
|
use App\Factory\RestaurantFactory;
|
||||||
use App\Repository\SubjectRepository;
|
use App\Repository\SubjectRepository;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
|
|
||||||
class AddSubjectTest extends WebTestCase
|
class AddSubjectTest extends WebTestCase
|
||||||
{
|
{
|
||||||
public function testAddingNewSubject(): void
|
public function testSubjectList(): void
|
||||||
{
|
{
|
||||||
$client = static::createClient();
|
$client = static::createClient();
|
||||||
|
|
||||||
$user = UserFactory::createOne();
|
$subject = RestaurantFactory::createOne();
|
||||||
|
|
||||||
$client->loginUser($user);
|
|
||||||
|
|
||||||
$client->request('GET', '/');
|
$client->request('GET', '/');
|
||||||
|
|
||||||
|
$this->assertSelectorTextContains('ul li', $subject->getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAddingNewSubject(): void
|
||||||
|
{
|
||||||
|
$client = static::createClient();
|
||||||
|
$crawler = $client->request('GET', '/');
|
||||||
|
|
||||||
$client->submitForm('form_save', ['form[name]' => 'Riviera']);
|
$client->submitForm('form_save', ['form[name]' => 'Riviera']);
|
||||||
|
|
||||||
$this->assertResponseRedirects();
|
$this->assertResponseRedirects();
|
||||||
|
|
@ -30,8 +37,6 @@ class AddSubjectTest extends WebTestCase
|
||||||
|
|
||||||
$this->assertNotNull($subject);
|
$this->assertNotNull($subject);
|
||||||
$this->assertInstanceOf(Restaurant::class, $subject);
|
$this->assertInstanceOf(Restaurant::class, $subject);
|
||||||
$this->assertNotNull($subject->getCreatedBy());
|
|
||||||
$this->assertSame($user->getId(), $subject->getCreatedBy()->getId());
|
|
||||||
|
|
||||||
$this->assertSelectorTextContains('ul li', 'Riviera');
|
$this->assertSelectorTextContains('ul li', 'Riviera');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Tests\Integration\Subject;
|
|
||||||
|
|
||||||
use App\Factory\RestaurantFactory;
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|
||||||
|
|
||||||
class ListSubjectsTest extends WebTestCase
|
|
||||||
{
|
|
||||||
public function testSubjectList(): void
|
|
||||||
{
|
|
||||||
$client = static::createClient();
|
|
||||||
|
|
||||||
$subject = RestaurantFactory::createOne();
|
|
||||||
|
|
||||||
$client->request('GET', '/');
|
|
||||||
|
|
||||||
$this->assertSelectorTextContains('ul li', $subject->getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in a new issue