B
B
BonBon Slick2018-12-28 19:19:02
Software testing
BonBon Slick, 2018-12-28 19:19:02

Dependency of tests on tests from other cases in another namespace?

<testsuites>
        <testsuite name="Functional Test Suite">
            <directory>tests/Functional/UrlAvailability</directory> // check if all url available
            <directory>tests/Functional</directory> // after run other test which depends on test from above folder
        </testsuite>
    </testsuites>

We run each link and check if there is access to it, because if the link is not available, it makes no sense to call half a hundred other tests, for example, which check the form, translation, buttons, fields, data, validation, and so on.
namespace App\Tests\Functional\UrlAvailability;
final class PublicUrlAvailabilityTest extends FunctionalTestCase
{
    /**
     * Urls only for NOT logged users
     *
     * @test
     *
     * @dataProvider onlyForNotAuthenticatedUrls
     *
     * @param string $url
     */
    public function pagesAvailableForNotAuthenticatedUser(string $url): void
    {
        $client = self::createClient();
        $client->request(Request::METHOD_GET, $url);

        static::assertTrue($client->getResponse()->isSuccessful(), \sprintf('In %s for %s', __FUNCTION__, $url));
    }

    /**
     *
     * @return array
     */
    public function onlyForNotAuthenticatedUrls(): array
    {
        return [
            ['/login/'],
            ['/forgot-pass/'],
            ['/reset-pass/'],
        ];
    }

However, this test is called 3 times for 3 links, it is not clear how other tests can be tied into a dependency to this test.
This test is always skipped, even if all tests on pagesAvailableForNotAuthenticatedUser pass.
namespace App\Tests\Functional;
class LoginControllerTest extends FunctionalTestCase
{
    /**
     * Test if an inactive user can login.
     *
     * @depends \App\Tests\Functional\PublicUrlAvailabilityTest::pagesAvailableForNotAuthenticatedUser
     *
     * @test
     */
    public function inactiveUserCanLogin(): void
    {

So how to link test dependencies that lie in different namespaces?
And what if the first test is called with a dataProvider? After all, then it will be called many times for each record separately.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question