Explorar el Código

all tests working

master
Daniel hace 2 años
padre
commit
34d37ea9de
Se han modificado 13 ficheros con 40 adiciones y 30 borrados
  1. +2
    -2
      migrations/Version20240308161707.php
  2. +1
    -0
      src/ApiResource/PartnerApi.php
  3. +3
    -0
      src/ApiResource/UserApi.php
  4. +2
    -1
      src/Entity/User.php
  5. +6
    -11
      src/Mapper/UserApiToEntityMapper.php
  6. +1
    -0
      src/Mapper/UserEntityToApiMapper.php
  7. +1
    -1
      src/Serializer/MediaObjectNormalizer.php
  8. +0
    -1
      tests/Functional/CommentResourceTest.php
  9. +2
    -2
      tests/Functional/ContactResourceTest.php
  10. +19
    -9
      tests/Functional/MediaObjectResourceTest.php
  11. +2
    -2
      tests/Functional/PartnerResourceTest.php
  12. +1
    -1
      tests/Functional/ProductResourceTest.php
  13. BIN
      tests/fixtures/1176_upload.png

migrations/Version20240305164344.php → migrations/Version20240308161707.php Ver fichero

@@ -10,7 +10,7 @@ use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240305164344 extends AbstractMigration
final class Version20240308161707 extends AbstractMigration
{
public function getDescription(): string
{
@@ -36,7 +36,7 @@ final class Version20240305164344 extends AbstractMigration
$this->addSql('ALTER TABLE posting ADD CONSTRAINT FK_BD275D739393F8FE FOREIGN KEY (partner_id) REFERENCES partner (id)');
$this->addSql('ALTER TABLE posting ADD CONSTRAINT FK_BD275D73E7A1254A FOREIGN KEY (contact_id) REFERENCES contact (id)');
$this->addSql('ALTER TABLE product ADD CONSTRAINT FK_D34A04AD3DA5256D FOREIGN KEY (image_id) REFERENCES media_object (id) ON DELETE SET NULL');
$this->addSql('ALTER TABLE `user` ADD CONSTRAINT FK_8D93D6493DA5256D FOREIGN KEY (image_id) REFERENCES media_object (id)');
$this->addSql('ALTER TABLE `user` ADD CONSTRAINT FK_8D93D6493DA5256D FOREIGN KEY (image_id) REFERENCES media_object (id) ON DELETE SET NULL');
}

public function down(Schema $schema): void

+ 1
- 0
src/ApiResource/PartnerApi.php Ver fichero

@@ -79,6 +79,7 @@ class PartnerApi
#[ApiProperty(writable: false)]
public ?string $logoUrl = null;

#[ApiProperty(writable: false)]
public ?\DateTimeImmutable $createdAt = null;

/**


+ 3
- 0
src/ApiResource/UserApi.php Ver fichero

@@ -14,6 +14,7 @@ use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use App\Entity\MediaObject;
use App\Entity\User;
use App\State\EntityClassDtoStateProcessor;
use App\State\EntityToDtoStateProvider;
@@ -57,6 +58,8 @@ class UserApi
#[Assert\NotBlank]
public ?string $lastName = null;

public ?MediaObject $image = null;

/**
* The plaintext password when being set or changed.
*/


+ 2
- 1
src/Entity/User.php Ver fichero

@@ -27,7 +27,8 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
#[ORM\Column(length: 255)]
private ?string $lastName = null;

#[ORM\ManyToOne]
#[ORM\ManyToOne(targetEntity: MediaObject::class)]
#[ORM\JoinColumn(nullable: true, onDelete: "SET NULL")]
private ?MediaObject $image = null;

#[ORM\Column]


+ 6
- 11
src/Mapper/UserApiToEntityMapper.php Ver fichero

@@ -17,10 +17,10 @@ use Symfonycasts\MicroMapper\MicroMapperInterface;
class UserApiToEntityMapper implements MapperInterface
{
public function __construct(
private UserRepository $userRepository,
private UserRepository $repository,
private UserPasswordHasherInterface $userPasswordHasher,
private MicroMapperInterface $microMapper,
private PropertyAccessorInterface $propertyAccessor,
private MicroMapperInterface $microMapper,
private PropertyAccessorInterface $propertyAccessor,
)
{
}
@@ -30,12 +30,12 @@ class UserApiToEntityMapper implements MapperInterface
$dto = $from;
assert($dto instanceof UserApi);

$userEntity = $dto->id ? $this->userRepository->find($dto->id) : new User();
if (!$userEntity) {
$entity = $dto->id ? $this->repository->find($dto->id) : new User();
if (!$entity) {
throw new \Exception('User not found');
}

return $userEntity;
return $entity;
}

public function populate(object $from, object $to, array $context): object
@@ -53,11 +53,6 @@ class UserApiToEntityMapper implements MapperInterface
}

$userPostsEntities = new ArrayCollection();
foreach ($dto->posts as $userPostApi) {
$userPostsEntities[] = $this->microMapper->map($userPostApi, Posting::class, [
MicroMapperInterface::MAX_DEPTH => 1,
]);
}
$this->propertyAccessor->setValue($entity, 'postings', $userPostsEntities);

return $entity;


+ 1
- 0
src/Mapper/UserEntityToApiMapper.php Ver fichero

@@ -40,6 +40,7 @@ class UserEntityToApiMapper implements MapperInterface
$dto->email = $entity->getEmail();
$dto->firstName = $entity->getFirstName();
$dto->lastName = $entity->getLastName();
$dto->image = $entity->getImage();

return $dto;
}


+ 1
- 1
src/Serializer/MediaObjectNormalizer.php Ver fichero

@@ -44,7 +44,7 @@ final class MediaObjectNormalizer implements NormalizerInterface, SerializerAwar
if (isset($context[self::ALREADY_CALLED])) {
//return false;
}
// return $data instanceof MediaObject;
return $this->normalizer->supportsNormalization($data, $format, $context);
}



+ 0
- 1
tests/Functional/CommentResourceTest.php Ver fichero

@@ -82,7 +82,6 @@ class CommentResourceTest extends KernelTestCase
],
])
->assertSuccessful()
->dd()
;
}
}

+ 2
- 2
tests/Functional/ContactResourceTest.php Ver fichero

@@ -56,7 +56,7 @@ class ContactResourceTest extends KernelTestCase
'lastName' => 'Test',
'partner' => '/api/partners/' . $partner->getId(),
'birthday' => '1984-02-10',
'image' => '/api/media/' . $mediaObject->getId(),
'image' => '/api/medias/' . $mediaObject->getId(),
'position' => 'CEO',
'phone' => '123456789',
'email' => 'peter@test2.de',
@@ -80,7 +80,7 @@ class ContactResourceTest extends KernelTestCase
;

$this->browser()
->delete('/api/media/' . $mediaObject->getId(), [
->delete('/api/medias/' . $mediaObject->getId(), [
'headers' => [
'Authorization' => 'Bearer ' . $token,
],


+ 19
- 9
tests/Functional/MediaObjectResourceTest.php Ver fichero

@@ -53,7 +53,16 @@ class MediaObjectResourceTest extends KernelTestCase
$token = $this->JWTManager->create($user->object());

$this->browser()
->post('/api/media', [
->get('/api/medias', [
'headers' => [
'Authorization' => 'Bearer ' . $token,
],
])
->assertSuccessful()
;

$this->browser()
->post('/api/medias', [
'headers' => [
'Authorization' => 'Bearer ' . $token,
'Content-Type' => 'multipart/form-data'
@@ -67,22 +76,24 @@ class MediaObjectResourceTest extends KernelTestCase

$partner = PartnerFactory::createOne();
$this->browser()
->patch('/api/partner/' . $partner->getId(), [
->patch('/api/partners/' . $partner->getId(),
[
'json' => [
'logo' => '/api/medias/1'
],
'headers' => [
'Authorization' => 'Bearer ' . $token,
'Content-Type' => 'application/merge-patch+json'
],
'json' => [
'logo' => '/api/media/1'
]
])
->assertSuccessful()
;

$this->browser()
->delete('/api/media/1', [
->delete('/api/medias/1',
[
'headers' => [
'Authorization' => 'Bearer ' . $token,
'Content-Type' => 'multipart/form-data'
],
])
->assertSuccessful()
@@ -102,10 +113,9 @@ class MediaObjectResourceTest extends KernelTestCase
);
$token = $this->JWTManager->create($user->object());
$this->browser()
->delete('/api/media/' . $mediaObject->getId(), [
->delete('/api/medias/' . $mediaObject->getId(), [
'headers' => [
'Authorization' => 'Bearer ' . $token,
'Content-Type' => 'multipart/form-data'
],
])
->assertSuccessful()


+ 2
- 2
tests/Functional/PartnerResourceTest.php Ver fichero

@@ -55,7 +55,7 @@ class PartnerResourceTest extends KernelTestCase
'city' => 'test city',
'country' => 'test country',
'website' => 'wwe.test.de',
'logo' => '/api/media/' . $mediaObject->getId(),
'logo' => '/api/medias/' . $mediaObject->getId(),
],
'headers' => [
'Authorization' => 'Bearer ' . $token,
@@ -79,7 +79,7 @@ class PartnerResourceTest extends KernelTestCase
;

$this->browser()
->delete('/api/media/' . $mediaObject->getId(), [
->delete('/api/medias/' . $mediaObject->getId(), [
'headers' => [
'Authorization' => 'Bearer ' . $token,
],


+ 1
- 1
tests/Functional/ProductResourceTest.php Ver fichero

@@ -54,7 +54,7 @@ class ProductResourceTest extends KernelTestCase
'json' => [
'name' => 'Test',
'description' => 'more test',
'image' => '/api/media/' . $mediaObject->getId(),
'image' => '/api/medias/' . $mediaObject->getId(),
],
'headers' => [
'Authorization' => 'Bearer ' . $token,


BIN
tests/fixtures/1176_upload.png Ver fichero

Antes Después
Anchura: 256  |  Altura: 256  |  Tamaño: 3.9 KiB

Cargando…
Cancelar
Guardar