Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

As an adherent, I want to create my committee. #98

Merged
merged 1 commit into from Jan 23, 2017

Conversation

hhamon
Copy link
Contributor

@hhamon hhamon commented Jan 18, 2017

No description provided.

@hhamon hhamon added this to the sprint-2 milestone Jan 18, 2017
@hhamon hhamon self-assigned this Jan 18, 2017
@hhamon hhamon force-pushed the feat-create-committee branch 10 times, most recently from 5d764f9 to 8a8e7a3 Compare January 19, 2017 22:53
@hhamon hhamon changed the title [WIP] [AppBundle] create a committee. [AppBundle] create a committee. Jan 19, 2017
@hhamon hhamon requested review from HeahDude, a user and tgalopin January 19, 2017 22:55
@@ -28,6 +28,8 @@ common.conditions.not_accepted: Vous devez accepter la charte.

common.recaptcha.invalid_message: La réponse au contrôle anti-spamm est incorrecte.

common.twitter_nickname.invalid_format: Un identifiant Twitter ne peut contenir que des lettres, des chiffres et des underscores.
Copy link

@ghost ghost Jan 19, 2017

Choose a reason for hiding this comment

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

On utilise davantage le terme "caractère de soulignement" ou "tiret bas" en français.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ou « tiret du 6 » lol ? ^^
@tgalopin @HeahDude vous préférez quoi comme traduction FR ?

Copy link

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

L'underscore est un anglicisme aujourd'hui ça me paraît assez courant, après le tiret c'est juste un "tiret" :D

<form method="post" id="create-committee-form" class="form">
{{ form_errors(form) }}

<h3>Renseignez les informatins de votre comité local</h3>
Copy link

Choose a reason for hiding this comment

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

informations

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bien vu!

$this->assertSame(9, $crawler->filter('#create-committee-form .form__errors > li')->count());
$this->assertSame("Cette valeur n'est pas un identifiant valide de ville française.", $crawler->filter('#create-committee-form > .form__errors > li')->text());
$this->assertSame('Cette chaine est trop courte. Elle doit avoir au minimum 2 caractères.', $crawler->filter('#field-name > .form__errors > li')->text());
$this->assertSame('Cette chaine est trop courte. Elle doit avoir au minimum 5 caractères.', $crawler->filter('#field-description > .form__errors > li')->text());
Copy link

Choose a reason for hiding this comment

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

Bien qu'il s'agisse ici des tests, il conviendrait de corriger les 2 occurrences de "chaîne". Ou au moins de le noter dans les typos à corriger pour la prochaine fois ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah oui bien vu!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

@hhamon hhamon force-pushed the feat-create-committee branch 4 times, most recently from 6ca6b78 to fcf4579 Compare January 19, 2017 23:42

// Activate the user account
$activateAccountUrl = sprintf('/inscription/finaliser/%s/%s', $adherent->getUuid(), $activationToken->getValue());
$this->client->request(Request::METHOD_GET, $activateAccountUrl);

$this->assertResponseStatusCode(Response::HTTP_FOUND, $this->client->getResponse());
$this->assertCount(1, $this->emailRepository->findMessages(AdherentAccountConfirmationMessage::class, 'paul@dupont.tld'));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@HeahDude @romain-pierre @tgalopin voici la nouvelle bonne manière pour tester qu'un email a été envoyé via Mailjet et donc stocké en BDD.

On pourrait imaginer faire une assertion du genre:

$this->assertEmailWasSent(AdherentAccountConfirmationMessage::class, 'paul@dupont.tld');

Copy link
Contributor

Choose a reason for hiding this comment

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

Go for it!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pour une prochaine PR ;)

@hhamon hhamon changed the title [AppBundle] create a committee. As an adherent, I want to create my committee. Jan 19, 2017
@hhamon hhamon force-pushed the feat-create-committee branch 2 times, most recently from 6a34c8d to a349a63 Compare January 20, 2017 00:00
@@ -41,6 +43,15 @@ adherent.plain_password.min_length: Votre mot de passe doit comporter au moins 8
adherent.activity_position.invalid_choice: Le statut d'activité n'est pas valide.

#
# Committee
#
committee.canonical_name.not_unique: Ce nom de comité est déjà choisi
Copy link
Contributor

Choose a reason for hiding this comment

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

missing dot?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep

'attr': {
'class': 'form--full',
'placeholder': 'Nom du comité',
'max-length': '50',
Copy link
Contributor

Choose a reason for hiding this comment

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

If you pass null instead of an explicit form type class in the type, the value will be guessed from the constraint, that avoid changing values in many places.

$command->setCommittee($this->factory->createFromCommitteeCreationCommand($command));

$adherent = $command->getAdherent();
$committee = $command->getCommittee();
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for $adherent var IMO, and you should initialize $committee thanks to the return from the factory.

{
$uuid = isset($data['uuid'])
? Uuid::fromString($data['uuid'])
: Committee::createUuid($data['name']);
Copy link
Contributor

Choose a reason for hiding this comment

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

How sure are we that the name key will exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's a requirement but yes I could throw an exception if it doesn't.

}

$committee->setSocialNetworks(
!empty($data['facebook_page_url']) ? $data['facebook_page_url'] : null,
Copy link
Contributor

Choose a reason for hiding this comment

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

$data['facebook_page_url'] ?? null

*
* @return CommitteeMembership
*/
public static function createWithAdherent(
Copy link
Contributor

Choose a reason for hiding this comment

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

createForAdherent?

*/
public static function createWithHostPrivilege(
UuidInterface $committeeUuid,
UuidInterface $adherentUuid,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be Committee and Adherent as type hints IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't because the method is used in the Committee class when I don't have access to the Adherent but only its UUID.

->getQuery()
;

return (int) $query->getSingleScalarResult() >= 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

return (bool) $query->getSingleScalarResult();?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope ! I want to cast the result of getSingleScalarResult() to int.

Copy link
Contributor

Choose a reason for hiding this comment

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

What for? You return a bool anyway...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want to compare two numbers together. By default, getSingleScalarResult() returns a string.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah a string sanding for a COUNT result so casting the call to a bool should work the same:

-return (int) $query->getSingleScalarResult() >= 1;
+return (bool) $query->getSingleScalarResult();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes you're right this is because PHP is shit with numbers vs bool vs strings. IMO, from a cognitive perspective, it requires less efforts to compare numbers together rather than casting to a boolean. Also it's safer!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mean it's explicit when you read the code!

->getQuery()
;

return 1 === (int) $query->getSingleScalarResult();
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope! Explanations is same as above. The cast applies on the returned value of $query->getSingleScalarResult();

Copy link
Contributor

Choose a reason for hiding this comment

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

But you're returning a bool! I don't get it :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well the two comparisons below are not equal:

1 === '1'

vs

1 === 1

The cast enforces the right operand to be a valid integer to compare with the left operand.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Back to basics

1 === ( (int) '1' )

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah but here we just need to know that it's not empty, so as above it should be the same:

-return 1 === (int) $query->getSingleScalarResult();
+return (bool) $query->getSingleScalarResult();

Am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What if the getSingleScalarResult() method returns '2'? Your condition is wrong! I strictly want to compare that we have only one row matching. No less no more!


// Activate the user account
$activateAccountUrl = sprintf('/inscription/finaliser/%s/%s', $adherent->getUuid(), $activationToken->getValue());
$this->client->request(Request::METHOD_GET, $activateAccountUrl);

$this->assertResponseStatusCode(Response::HTTP_FOUND, $this->client->getResponse());
$this->assertCount(1, $this->emailRepository->findMessages(AdherentAccountConfirmationMessage::class, 'paul@dupont.tld'));
Copy link
Contributor

Choose a reason for hiding this comment

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

Go for it!

@hhamon hhamon force-pushed the feat-create-committee branch 5 times, most recently from 748a88f to 70123cf Compare January 23, 2017 09:19
@hhamon hhamon merged commit 9aa4732 into master Jan 23, 2017
@hhamon hhamon deleted the feat-create-committee branch January 23, 2017 09:23
Haitaar added a commit that referenced this pull request Jan 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

3 participants