mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-04-16 10:16:22 +02:00
Implemented draft for PureSourceCreateType Test and adapted classes to it
This commit is contained in:
parent
aafde4c0f9
commit
1bc85c994e
@ -4,6 +4,8 @@ namespace App\Attribut;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
|
*
|
||||||
|
* @see IdAttributInterface
|
||||||
*/
|
*/
|
||||||
trait IdAttribut
|
trait IdAttribut
|
||||||
{
|
{
|
||||||
@ -12,16 +14,25 @@ trait IdAttribut
|
|||||||
*/
|
*/
|
||||||
protected $id;
|
protected $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $id
|
||||||
|
*/
|
||||||
public function setId(int $id): void
|
public function setId(int $id): void
|
||||||
{
|
{
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getId(): int
|
/**
|
||||||
|
* @return int|null
|
||||||
|
*/
|
||||||
|
public function getId(): ?int
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public function hasId(): bool
|
public function hasId(): bool
|
||||||
{
|
{
|
||||||
return isset($this->id);
|
return isset($this->id);
|
||||||
|
@ -13,9 +13,14 @@ interface IdAttributInterface
|
|||||||
public function setId(int $id): void;
|
public function setId(int $id): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int
|
* Don't use this function to check if an id is set.
|
||||||
|
* Use instead:.
|
||||||
|
*
|
||||||
|
* @see self::hasId()
|
||||||
|
*
|
||||||
|
* @return int|null
|
||||||
*/
|
*/
|
||||||
public function getId(): int;
|
public function getId(): ?int;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool Checks if attribute is set
|
* @return bool Checks if attribute is set
|
||||||
|
@ -30,9 +30,9 @@ trait SlugAttribut
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getSlug(): string
|
public function getSlug(): ?string
|
||||||
{
|
{
|
||||||
return $this->slug;
|
return $this->slug;
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,14 @@ interface SlugAttributInterface
|
|||||||
public function setSlug(string $slug): void;
|
public function setSlug(string $slug): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* Don't use this function to check if a slug is set
|
||||||
|
* Use instead:.
|
||||||
|
*
|
||||||
|
* @see self::hasSlug()
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getSlug(): string;
|
public function getSlug(): ?string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool Checks if a slug is set
|
* @return bool Checks if a slug is set
|
||||||
|
@ -35,11 +35,16 @@ final class CreateSourceAction extends AbstractCreateAction
|
|||||||
$this->sourceClass = $request->get(SourceType::CLASS_PARAMETER_NAME, self::DEFAULT_CLASS);
|
$this->sourceClass = $request->get(SourceType::CLASS_PARAMETER_NAME, self::DEFAULT_CLASS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setFormClass(): void
|
private function setForm(): void
|
||||||
{
|
{
|
||||||
$this->form = $this->actionService->getCurrentFormBuilder()->getForm();
|
$this->form = $this->actionService->getCurrentFormBuilder()->getForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function setRequestedEntityClass(): void
|
||||||
|
{
|
||||||
|
$this->actionService->getRequestedAction()->getRequestedEntity()->setClass($this->sourceClass);
|
||||||
|
}
|
||||||
|
|
||||||
private function handleRequest(): void
|
private function handleRequest(): void
|
||||||
{
|
{
|
||||||
$this->form->handleRequest($this->actionService->getRequest());
|
$this->form->handleRequest($this->actionService->getRequest());
|
||||||
@ -53,7 +58,8 @@ final class CreateSourceAction extends AbstractCreateAction
|
|||||||
protected function prepare(): void
|
protected function prepare(): void
|
||||||
{
|
{
|
||||||
$this->setSourceClass();
|
$this->setSourceClass();
|
||||||
$this->setFormClass();
|
$this->setRequestedEntityClass();
|
||||||
|
$this->setForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,6 +69,11 @@ final class CreateSourceAction extends AbstractCreateAction
|
|||||||
*/
|
*/
|
||||||
protected function isValid(): bool
|
protected function isValid(): bool
|
||||||
{
|
{
|
||||||
|
//The following Exception just exists out of debuging reasons during the development process
|
||||||
|
if (!$this->form->isSubmitted()) {
|
||||||
|
throw new \Exception('The form is not submitted!');
|
||||||
|
}
|
||||||
|
|
||||||
return $this->form->isValid();
|
return $this->form->isValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,6 @@ final class PureSourceCreateType extends SourceType
|
|||||||
*/
|
*/
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
{
|
{
|
||||||
$builder->add('slug')->add('class');
|
$builder->add('slug');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,8 @@ use Symfony\Component\HttpFoundation\Request;
|
|||||||
use App\Domain\FormManagement\RequestedActionFormBuilderService;
|
use App\Domain\FormManagement\RequestedActionFormBuilderService;
|
||||||
use App\Domain\FormManagement\FormClassNameService;
|
use App\Domain\FormManagement\FormClassNameService;
|
||||||
use App\Domain\RequestManagement\Entity\RequestedEntityService;
|
use App\Domain\RequestManagement\Entity\RequestedEntityService;
|
||||||
|
use App\Entity\Source\PureSource;
|
||||||
|
use App\Attribut\ClassAttributInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @todo Implement test and logic!!!!!
|
* @todo Implement test and logic!!!!!
|
||||||
@ -77,6 +79,7 @@ class CreateSourceActionIntegrationTest extends KernelTestCase
|
|||||||
|
|
||||||
public function testCreateWithGuestUser(): void
|
public function testCreateWithGuestUser(): void
|
||||||
{
|
{
|
||||||
|
$this->request->attributes->set(ClassAttributInterface::CLASS_ATTRIBUT_NAME, PureSource::class);
|
||||||
$this->assertInstanceOf(PureSourceInterface::class, $this->createSourceAction->execute());
|
$this->assertInstanceOf(PureSourceInterface::class, $this->createSourceAction->execute());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,6 @@ class PureSourceIntegrationTest extends KernelTestCase
|
|||||||
$this->assertGreaterThan(0, $this->pureSource->getId());
|
$this->assertGreaterThan(0, $this->pureSource->getId());
|
||||||
$this->entityManager->remove($this->pureSource);
|
$this->entityManager->remove($this->pureSource);
|
||||||
$this->entityManager->flush();
|
$this->entityManager->flush();
|
||||||
$this->expectException(\TypeError::class);
|
$this->assertNull($this->pureSource->getId());
|
||||||
$this->pureSource->getId();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,7 @@ class IdAttributTest extends TestCase
|
|||||||
public function testConstruct(): void
|
public function testConstruct(): void
|
||||||
{
|
{
|
||||||
$this->assertFalse($this->id->hasId());
|
$this->assertFalse($this->id->hasId());
|
||||||
$this->expectException(\TypeError::class);
|
$this->assertNull($this->id->getId());
|
||||||
$this->id->getId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAccessors(): void
|
public function testAccessors(): void
|
||||||
|
@ -27,8 +27,7 @@ class SlugAttributTest extends TestCase
|
|||||||
public function testConstructor(): void
|
public function testConstructor(): void
|
||||||
{
|
{
|
||||||
$this->assertFalse($this->slugAttribut->hasSlug());
|
$this->assertFalse($this->slugAttribut->hasSlug());
|
||||||
$this->expectException(\TypeError::class);
|
$this->assertNull($this->slugAttribut->getSlug());
|
||||||
$this->slugAttribut->getSlug();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAccessors(): void
|
public function testAccessors(): void
|
||||||
|
@ -22,8 +22,7 @@ class AbstractEntityTest extends TestCase
|
|||||||
public function testConstructor(): void
|
public function testConstructor(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals(0, $this->entity->getVersion());
|
$this->assertEquals(0, $this->entity->getVersion());
|
||||||
$this->expectException(\TypeError::class);
|
$this->assertNull($this->entity->getId());
|
||||||
$this->entity->getId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testVersion(): void
|
public function testVersion(): void
|
||||||
|
@ -38,7 +38,6 @@ class AbstractSourceTest extends TestCase
|
|||||||
|
|
||||||
public function testSlugInit(): void
|
public function testSlugInit(): void
|
||||||
{
|
{
|
||||||
$this->expectException(\TypeError::class);
|
$this->assertNull($this->source->getSlug());
|
||||||
$this->source->getSlug();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace tests\Unit\Form\Source;
|
||||||
|
|
||||||
|
use Symfony\Component\Form\Test\TypeTestCase;
|
||||||
|
use App\Entity\Source\PureSource;
|
||||||
|
use App\Form\Source\PureSourceCreateType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author kevinfrantz
|
||||||
|
*
|
||||||
|
* @see https://symfony.com/doc/current/form/unit_testing.html
|
||||||
|
*/
|
||||||
|
class PureSourceCreateTypeTest extends TypeTestCase
|
||||||
|
{
|
||||||
|
const SLUG = 'ABCDE';
|
||||||
|
|
||||||
|
public function testAttributes(): void
|
||||||
|
{
|
||||||
|
$formData = ['slug' => self::SLUG];
|
||||||
|
$objectToCompare = new PureSource();
|
||||||
|
$form = $this->factory->create(PureSourceCreateType::class, $objectToCompare);
|
||||||
|
|
||||||
|
$object = new PureSource();
|
||||||
|
$object->setSlug(self::SLUG);
|
||||||
|
$object->setCreatorRelation($objectToCompare->getCreatorRelation());
|
||||||
|
|
||||||
|
// submit the data to the form directly
|
||||||
|
$form->submit($formData);
|
||||||
|
|
||||||
|
$this->assertTrue($form->isSynchronized());
|
||||||
|
// check that $objectToCompare was modified as expected when the form was submitted
|
||||||
|
//$this->assertEquals($object, $objectToCompare);
|
||||||
|
|
||||||
|
$view = $form->createView();
|
||||||
|
$children = $view->children;
|
||||||
|
|
||||||
|
foreach (array_keys($formData) as $key) {
|
||||||
|
$this->assertArrayHasKey($key, $children);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -52,8 +52,7 @@ class UserSourceRepositoryTest extends KernelTestCase
|
|||||||
$this->assertGreaterThan(0, $insertSource->getId());
|
$this->assertGreaterThan(0, $insertSource->getId());
|
||||||
$this->entityManager->remove($insertSource);
|
$this->entityManager->remove($insertSource);
|
||||||
$this->entityManager->flush();
|
$this->entityManager->flush();
|
||||||
$this->expectException(\TypeError::class);
|
$this->assertNull($insertSource->getId());
|
||||||
$insertSource->getId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreation(): void
|
public function testCreation(): void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user