Skip to content

Conversation

@paolorabbito
Copy link
Collaborator

No description provided.

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE book CHANGE id id BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\'');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Attenzione con questa migrazione ⚠️
Se nella tabella sono già presenti dei dati, i valori non vengono automaticamente convertiti in uuid ma rimangono gli interi dei vecchi id.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ci piacerebbe approfondire l'argomento insieme quando avete tempo su quale il modo migliore di approcciare questa situazione.

$entity = $this->bookRepository->find(Uuid::fromString($id));

if (!$entity) {
throw new HttpException(404, 'Book not found');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se volete evitare di passare ogni volta il codice dell'eccezione esistono anche delle eccezioni specifiche come NotFoundHttpException, BadRequestHttpException, ecc.

Inoltre in questo caso esiste anche un metodo specifico dentro AbstractController per lanciare delle 404: $this->createNotFoundException('Book not found')

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ottimo suggerimento! Buono a sapersi! Sistemato

],
]);
self::assertNotFalse($body);
$this->client->xmlHttpRequest('POST', '/api/collections', [], [], $headers, $body);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perchè avete usato xmlHttpRequest piuttosto che request come già fatto per Book?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All'inizio avevamo utilizzato xmlHttpRequest poi siamo passati a request e ci siamo dimenticati di aggiornare tutto.
PS che differenza c'è tra i due metodi?

self::assertNotFalse($body);
$this->client->xmlHttpRequest('POST', '/api/collections', [], [], $headers, $body);
$res = $this->client->getResponse();
self::assertEquals(201, $res->getStatusCode());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In alternativa a queste due righe potreste usare anche $this->assertResponseStatusCodeSame(Response::HTTP_CREATED);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixato anche questo!

->expects($this->exactly(2))
->method('storeBook')
->withConsecutive([Book::newBookFrom($book1)], [Book::newBookFrom($book2)]);
->withAnyParameters();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perchè avete scelto di passare ad una condizione meno stringente?
Prima il controllo era esatto sul libro mentre adesso viene accettata qualunque cosa.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se non ricordo male era un workaround temporaneo che poi volevamo vedere insieme a voi (commento riga 31), perché se si utilizza la condizione precedente il test fallisce sul campo uid a causa del mock.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confermo che volevamo vederla con voi, abbiamo spostato il commento nella riga interessata.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants