Skip to content

Adding dontSeeInSession() #64

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

Merged
merged 3 commits into from
Dec 9, 2020
Merged

Conversation

ThomasLandauer
Copy link
Member

seeInSession() was already there, but the opposite was missing.

I omitted the $value parameter for this reason: If $attribute is not in the session, it doesn't make much sense to do an additional check about its (inexistent) value. Or does it?

Tests are missing, but I don't know how to do that :-(

`seeInSession()` was already there, but the opposite was missing.

I omitted the `$value` parameter for this reason: If `$attribute` is *not* in the session, it doesn't make much sense to do an additional check about its (inexistent) value. Or does it?

Tests are missing, but I don't know how to do that :-(
@TavoNiievez
Copy link
Member

Hey @ThomasLandauer

Thanks!

it doesn't make much sense to do an additional check about its (inexistent) value. Or does it?

Clic to see answer.

Regarding this, i do think that it would make sense.

This function actually does two things in its affirmative version: check attributes and check values.

Perhaps what i want to assert is that there is no specific value in a session attribute. What is the same, it does not matter to me if the attribute exists or not, but if it does exist i want the test to fail if it contains the value that i specify as the second parameter in 'dontSeeInSession'.

Tests are missing, but I don't know how to do that :-(

Clic to see answer.

This should be fixed.

My idea when re-writing the module's test project and adding tests is that from the moment that that can be released, anyone who wants to include new functions (including me) should also contribute the corresponding tests.
So personally i find it convenient to create an CONTRIBUTING.md file with the contribution guidelines and an explanation of how to test the code in the module's test project.

Following that order of ideas, the process for adding tests would include fork the test project, patching the composer.json so that your module fork is downloaded instead of the official version of the module, and modifying the SymfonyModuleCest.php file by adding the corresponding test.
Is there anything else you would like to see in that contribution file if it is created?

@ThomasLandauer
Copy link
Member Author

  1. $value: If I wanted to assert that, I'd grab the value and use assertNotEquals(). But there is no grabFromSession()! So the more important question I'm seeing is: Should there be a grabFromSession()? Or should we tell people to just use grabService('session'); and go with that? Which leads to the more general question: If the framework offers a convenient way for something, should Codeception duplicate it with its own function? I raised this question before about grabEntityFromRepository() at https://github.com/Codeception/Codeception/issues/5439#issuecomment-557905843

  2. CONTRIBUTING.md: I haven't found a decent workflow for GitHub PR's for myself yet, that's why I'm always doing it on the website ;-) So if you could come up with a step-by-step instruction, I'd be happy to be its first user :-)

@TavoNiievez
Copy link
Member

@ThomasLandauer

  1. As i see it, - getting the service, - then getting the attribute and, - finally asserting you do 3 instructions, while with seeInSession / dontSeeInSession you do it all in one line, it's just syntax sugar, the point of having these functions is that anyone can read the test without having to know the implementation details of the framework.
    Following your logic, there would not be many 'really necessary' methods in this module. Because most just get a service, do (or don't) do a couple of validations, and assert. Anyone can write that. But Codeception makes it easier to read and write.
    Specifically, in this case, seeInSession exists because there are other modules that have it, and Codeception is supposed to be a framework agnostic tool. So...

Should there be a grabFromSession()?

Nop.

  1. Of course! I'll add it to my to-do list :-)

Adding `$value`
@ThomasLandauer
Copy link
Member Author

Well, you (sort of) convinced me in this case - I added the $value ;-)

However, I just suggested to deprecate grabEntityFromRepository(): Codeception/module-doctrine2#22

@TavoNiievez TavoNiievez added this to the 1.5.0 milestone Dec 2, 2020
Copy link
Member Author

@ThomasLandauer ThomasLandauer left a comment

Choose a reason for hiding this comment

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

I clicked "Start a review" - which probably wasn't the right thing to do in this case...

@ThomasLandauer
Copy link
Member Author

Didn't you leave a second line comment?? It's gone now... :-(

@TavoNiievez
Copy link
Member

@ThomasLandauer don't worry and thanks you.
I tested it locally and it works quite well.
I will write the test when this gets merged and while i work on creating the contribution guidelines.

@TavoNiievez TavoNiievez merged commit 70ae730 into Codeception:master Dec 9, 2020
@ThomasLandauer ThomasLandauer deleted the patch-2 branch December 10, 2020 13:18
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.

2 participants