Add Sequence per suite generation #2766

Merged
merged 1 commit into from Feb 4, 2016

Conversation

Projects
None yet
4 participants
@johnatannvmd
Contributor

johnatannvmd commented Feb 3, 2016

This feature is usefull for huge suites with multiple depend steps within.

+ return $sequence;
+ }
+
+}

This comment has been minimized.

@Nitpick-CI

Nitpick-CI Feb 3, 2016

Expected 1 newline at end of file; 0 found

@Nitpick-CI

Nitpick-CI Feb 3, 2016

Expected 1 newline at end of file; 0 found

@DavertMik

This comment has been minimized.

Show comment
Hide comment
@DavertMik

DavertMik Feb 3, 2016

Member

Can you provide more detailed description? What problem are you solving with it
Thanks

Member

DavertMik commented Feb 3, 2016

Can you provide more detailed description? What problem are you solving with it
Thanks

@johnatannvmd

This comment has been minimized.

Show comment
Hide comment
@johnatannvmd

johnatannvmd Feb 4, 2016

Contributor

Simply, it generates sequence which values are the same during all Cest suite tests.

For example: I test email server: I generate unique emails and send it to the server. Then I just check is the email on the server in different ways.

<?php
class EmailTest
{
    public function sendEmail(AcceptanceTester $I)
    {
        // Takes about 5 sec, depends on connection
        $I->sendEmail('email' . sqs('user') . '@mailserver.com', sqs('subject'), sqs('body'));
    }

    /**
     * @depends sendEmail
    */
    public function checkEmail(AcceptanceTester $I)
    {
        $I->seeInSubjectTo('email' . sqs('user') . '@mailserver.com', sqs('subject'));
        $I->seeInBodyTo('email' . sqs('user') . '@mailserver.com', sqs('body'));
    }

    /**
     * @depends sendEmail
    */
    public function removeEmail(AcceptanceTester $I)
    {
        $I->removeEmail('email' . sqs('user') . '@mailserver.com');
        $I->dontSeeEmailTo('email' . sqs('user') . '@mailserver.com');
    }
}
?>

or I test site's backoffice via WebDriver: I login as admin, create user, change his profile. And if I create a user on every step and remove him it would take too much time rather than I create a user at the very first step and then doing some actions with him before deleting in the end.

If Cest Classes support _beforeSuite and _afterSuite, then sqs function will become unneeded.

Contributor

johnatannvmd commented Feb 4, 2016

Simply, it generates sequence which values are the same during all Cest suite tests.

For example: I test email server: I generate unique emails and send it to the server. Then I just check is the email on the server in different ways.

<?php
class EmailTest
{
    public function sendEmail(AcceptanceTester $I)
    {
        // Takes about 5 sec, depends on connection
        $I->sendEmail('email' . sqs('user') . '@mailserver.com', sqs('subject'), sqs('body'));
    }

    /**
     * @depends sendEmail
    */
    public function checkEmail(AcceptanceTester $I)
    {
        $I->seeInSubjectTo('email' . sqs('user') . '@mailserver.com', sqs('subject'));
        $I->seeInBodyTo('email' . sqs('user') . '@mailserver.com', sqs('body'));
    }

    /**
     * @depends sendEmail
    */
    public function removeEmail(AcceptanceTester $I)
    {
        $I->removeEmail('email' . sqs('user') . '@mailserver.com');
        $I->dontSeeEmailTo('email' . sqs('user') . '@mailserver.com');
    }
}
?>

or I test site's backoffice via WebDriver: I login as admin, create user, change his profile. And if I create a user on every step and remove him it would take too much time rather than I create a user at the very first step and then doing some actions with him before deleting in the end.

If Cest Classes support _beforeSuite and _afterSuite, then sqs function will become unneeded.

@Naktibalda

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Feb 4, 2016

Member

I didn't know that we have a Sequence module, but I had a use case for a sequence.

In my tests I needed to generate 2 globally unique ids per test.
So I ended up doing this:

Test1Cept.php

$paymentId1 = '10' . substr(time(), 2);
$paymentId2 = $paymentId1 + 1;

Test2Cept.php

$paymentId1 = '11' . substr(time(), 2);
$paymentId2 = $paymentId1 + 1;

Test3Cept.php

$paymentId = '12' . substr(time(), 2);

What I actually needed was a global counter (but using globals is bad, so I didn't even consider it).

Why is this module called Sequence if it is actually a unique id generator?

I could have made use of it if it had a setting which accepted a callback to set an initial value of the sequence, and a setting to use ++ instead of unique_id or a setting to set a generator function.

Member

Naktibalda commented Feb 4, 2016

I didn't know that we have a Sequence module, but I had a use case for a sequence.

In my tests I needed to generate 2 globally unique ids per test.
So I ended up doing this:

Test1Cept.php

$paymentId1 = '10' . substr(time(), 2);
$paymentId2 = $paymentId1 + 1;

Test2Cept.php

$paymentId1 = '11' . substr(time(), 2);
$paymentId2 = $paymentId1 + 1;

Test3Cept.php

$paymentId = '12' . substr(time(), 2);

What I actually needed was a global counter (but using globals is bad, so I didn't even consider it).

Why is this module called Sequence if it is actually a unique id generator?

I could have made use of it if it had a setting which accepted a callback to set an initial value of the sequence, and a setting to use ++ instead of unique_id or a setting to set a generator function.

@DavertMik

This comment has been minimized.

Show comment
Hide comment
@DavertMik

DavertMik Feb 4, 2016

Member

Why is this module called Sequence if it is actually a unique id generator?

good question :) Probably I was inspired by this https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#sequences

Member

DavertMik commented Feb 4, 2016

Why is this module called Sequence if it is actually a unique id generator?

good question :) Probably I was inspired by this https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#sequences

@DavertMik

This comment has been minimized.

Show comment
Hide comment
@DavertMik

DavertMik Feb 4, 2016

Member

If Cest Classes support _beforeSuite and _afterSuite, then sqs function will become unneeded.

from the architectural point of view this is a bad idea. One Cest should not affect others by doing something before and after the whole suite. So yes, Helpers and Modules should be used for such cases. In other way you won't get a clue where does those preparations happen.

Member

DavertMik commented Feb 4, 2016

If Cest Classes support _beforeSuite and _afterSuite, then sqs function will become unneeded.

from the architectural point of view this is a bad idea. One Cest should not affect others by doing something before and after the whole suite. So yes, Helpers and Modules should be used for such cases. In other way you won't get a clue where does those preparations happen.

@DavertMik

This comment has been minimized.

Show comment
Hide comment
@DavertMik

DavertMik Feb 4, 2016

Member

Looks good to merge

Member

DavertMik commented Feb 4, 2016

Looks good to merge

DavertMik added a commit that referenced this pull request Feb 4, 2016

Merge pull request #2766 from johnatannvmd/suite-sequence
Add Sequence per suite generation

@DavertMik DavertMik merged commit 8c671ce into Codeception:2.1 Feb 4, 2016

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
semaphoreci The build passed on Semaphore.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment