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

Enhancement: @depends rerun #2636

Closed
jausions opened this issue Apr 2, 2017 · 1 comment
Closed

Enhancement: @depends rerun #2636

jausions opened this issue Apr 2, 2017 · 1 comment
Labels
feature/test-dependencies Issues related to explicitly declared dependencies between tests type/enhancement A new idea that should be implemented

Comments

@jausions
Copy link

jausions commented Apr 2, 2017

Sometimes @depends clone is not what's needed. For instance when the value returned by the provider is tied to a database record that is generated during that depended-upon test. Tests that depend on the value returned by a successful @depends could be modifying that record. If a second test depends on the same @depends, the state of the database record could have already changed.

To better understand the case, consider that we don't interact directly with the database, but instead we interface with the application through its API or web UI:

  1. Step A -> Step B
  2. Step A -> Step C -> Step D

Using @depends to chain tests would be a great alternative to embedding all the steps in the individual tests.

I suggest a @depends rerun annotation.

Pseudo code:

<?php
class StatusesTest extends TestCase
{
    public function testDataSaved()
    {
        $browser = new WebBrowser();    // Pseudo web browser (Mink, Selenium, whatever...)
        $data = ['status' => 'pending', 'id' => someUniqueRandomId()];
        $this->assertEquals($browser->sendToCreateForm($data)->getResponseCode(), 200);
        return $data;
    }

    /**
     * Tests that pending things can be approved
     * 
     * We force the rerun of the @depends test to be sure to have the 'status' value
     * we expect. However, if a previous call to the provider had failed, we don't
     * rerun that provider test (assuming it will fail again.)
     * 
     * @depends rerun testDataSaved
     */
    public function testSettingFromPendingToApprovedStatus(array $data)
    {
        $browser = new WebBrowser();
        $data['status'] = 'approved';
        $this->assertTrue($browser->sendToChangeStatusForm($data)->getResponseCode(), 200);
        return $data;
    }

    /**
     * Tests that approved things cannot be rejected
     * 
     * For this test case, we don't use "@depend rerun" because no other tests
     * depends on this one in this test suite.
     * 
     * @depends testSettingFromPendingToApprovedStatus
     */
    public function testSettingFromApprovedToRejectedStatus(array $data)
    {
        $browser = new WebBrowser();
        $data['status'] = 'rejected';
        $this->assertFalse($browser->sendToChangeStatusForm($data)->getResponseCode(), 200);
    }

    /**
     * Tests that pending things can be rejected
     * 
     * Rerunning the @depends test would produce a different 'id' value
     * for $data.
     * 
     * @depends rerun testDataSaved
     */
    public function testSettingFromPendingToRejectedStatus(array $data)
    {
        $browser = new WebBrowser();
        $data['status'] = 'rejected';
        $this->assertTrue($browser->sendToChangeStatusForm($data)->getResponseCode(), 200);
    }
}
?>
@sebastianbergmann sebastianbergmann added the type/enhancement A new idea that should be implemented label Apr 2, 2017
@sebastianbergmann
Copy link
Owner

I would accept a pull request that implements this. Could be, though, that this is blocked by #10.

@sebastianbergmann sebastianbergmann added the feature/test-dependencies Issues related to explicitly declared dependencies between tests label Feb 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/test-dependencies Issues related to explicitly declared dependencies between tests type/enhancement A new idea that should be implemented
Projects
None yet
Development

No branches or pull requests

2 participants