How are the tests in vendor modules executed ?

JungleBoy
JungleBoy Posts: 1 🧑🏻‍🚀 - Cadet
edited November 2023 in Spryker Dev Environment

I have some custom modules that I have created and I would like to use them throughout projects, by making them as composer packages.

I was wondering how to bundle the tests inside the composer package. For inspiration I took a look at how the Spryker vendor modules structure the tests. I used the same structure and I can make simple assertion tests work, but if I want to use database for example, by incudling TransactionHelper, then when I run the tests, I get an error:

Could not find config key "PROJECT_NAMESPACES" in "Spryker\Shared\Config\Config"

Curiously, when I try to run the tests in Spryker vendor modules, I get the same error.

I use the usual algorithm for testing:

  1. codecept build
  2. codecept run -c path-to-suite

I see for example that in Availability module there are tests that use product helpers to get a product:

https://github.com/spryker/availability/blob/master/tests/SprykerTest/Zed/Availability/Business/AvailabilityFacadeTest.php#L384

And the codeception.yml files do not have anything out of the ordinary, besides the fact that LocatorHelper has no projectNamespaces defined.

So can anyone explain how the vendor module tests are executed ?

Answers

  • filip.gojkovic955
    filip.gojkovic955 Spryker Solution Partner Posts: 19 ✨ - Novice

    This is troubling me as well. Does anyone know ?
    I also have issue with chromedriver. It just doesn't recognize it. And Tests for communication break with error.
    "[Spryker\Service\Container\Exception\NotFoundException] The requested service "kernel" was not found in the container!"

  • filip.gojkovic955
    filip.gojkovic955 Spryker Solution Partner Posts: 19 ✨ - Novice
    edited January 23

    Furthermore

    Using

    - \SprykerTest\Zed\Router\Helper\RouterHelper 
    

    from

    vendor/spryker/router/tests/SprykerTest/Zed/Router/_support/Helper/RouterHelper.php
    

    Always producest error

    [Symfony\Component\Finder\Exception\DirectoryNotFoundException] The "/data/vendor/spryker/Bundles//src/Spryker/Zed//Communication/Controller/" directory does not exist.
    

    $controllerDirectories = sprintf('%s/spryker/spryker/Bundles//src/Spryker/Zed//Communication/Controller/', APPLICATION_VENDOR_DIR);
    APPLICATION_VENDOR_DIR = /data/vendor

    $controllerDirectories path isn't valid path.
    I removed "spryker/Bundles/"

    $controllerDirectories = sprintf('%s/spryker/Bundles//src/Spryker/Zed//Communication/Controller/', APPLICATION_VENDOR_DIR);
    

    With that change i don't have error any more.

  • filip.gojkovic955
    filip.gojkovic955 Spryker Solution Partner Posts: 19 ✨ - Novice

    For issue in my previous comment. Solution is to add this in config_default.

    $config[RouterConstants::ZED_CACHE_PATH] = sprintf(
        '%s/src/Generated/Router/Backoffice/codeBucket%s/',
        APPLICATION_ROOT_DIR,
        APPLICATION_CODE_BUCKET,
    );
    

    Errror happens because when we trigger test from console it compares routes with depricated methods. Placing up above code snippet forces the depricated moethod to have same path as non depricated method.

    @JungleBoy I found the solution for triggering vendor tests.

    In file codeception.yml in root of the project add path to configuration file of that test under the "include" seciton.
    For example I want to trigger tests in "Discounts" module.

    namespace: PyzTest
    actor: Tester
    
    include:
        - tests/PyzTest/*/*
        - vendor/spryker/discount/tests/SprykerTest/*/*
    
    paths:
        tests: tests
        output: tests/_output
        data: tests/_data
        support: tests/_support
        envs: tests/_envs
    

    Hope it helps.