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

failed to use testing environment file specified in suite config #20

Closed
krtorio opened this issue Aug 23, 2017 · 10 comments · Fixed by #46
Closed

failed to use testing environment file specified in suite config #20

krtorio opened this issue Aug 23, 2017 · 10 comments · Fixed by #46

Comments

@krtorio
Copy link

krtorio commented Aug 23, 2017

What are you trying to achieve?

run all tests after adding a new suite called 'api', forgot to point environment file to .env.testing (sqlite + test mongodb database) in the suite config api.suite.yml.

What do you get instead?

The unit and functional tests used local .env instead which uses my staging/demo mariadb and local mongodb database. Encountered errors due to trying to insert rows with duplicate ids. Mongodb local data wiped out because I use truncate in tearDown function. Mariadb data filled up with test seed data that I did not want to be put in the local database.

The unit and functional tests returned to using .env.testing settings only after removing all api suite files.

Provide console output if related. Use -vvv mode for more details.

# paste output here

Provide test source code if related

// paste test

Details

  • Codeception version:
    2.3.3
  • PHP Version:
    7.0.13, Laravel 5.4
  • Operating System:
    Windows 8
  • Installation type:
    Composer
  • List of installed packages (composer show)
    aws/aws-sdk-php 3.34.0 AWS SDK for PHP - Use Amazon...
    behat/gherkin v4.4.5 Gherkin DSL parser for PHP 5.3
    codeception/codeception 2.3.5 BDD-style testing framework
    dnoegel/php-xdg-base-dir 0.1 implementation of xdg base d...
    doctrine/inflector v1.2.0 Common String Manipulations ...
    doctrine/instantiator 1.0.5 A small, lightweight utility...
    erusev/parsedown 1.6.3 Parser for Markdown.
    facebook/webdriver 1.4.1 A PHP client for Selenium We...
    fzaninotto/faker v1.7.1 Faker is a PHP library that ...
    guzzlehttp/guzzle 6.3.0 Guzzle is a PHP HTTP client ...
    guzzlehttp/promises v1.3.1 Guzzle promises library
    guzzlehttp/psr7 1.4.2 PSR-7 message implementation...
    hamcrest/hamcrest-php v1.2.2 This is the PHP port of Hamc...
    jakub-onderka/php-console-color 0.1
    jakub-onderka/php-console-highlighter v0.3.2
    jenssegers/mongodb v3.2.2 A MongoDB based Eloquent mod...
    laravel/framework v5.4.33 The Laravel Framework.
    laravel/tinker v1.0.2 Powerful REPL for the Larave...
    league/flysystem 1.0.41 Filesystem abstraction: Many...
    league/flysystem-aws-s3-v3 1.0.18 Flysystem adapter for the AW...
    mockery/mockery 0.9.9 Mockery is a simple yet flex...
    mongodb/mongodb 1.1.2 MongoDB driver library
    monolog/monolog 1.23.0 Sends your logs to files, so...
    mtdowling/cron-expression v1.2.0 CRON for PHP: Calculate the ...
    mtdowling/jmespath.php 2.4.0 Declaratively specify how to...
    myclabs/deep-copy 1.6.1 Create deep copies (clones) ...
    nesbot/carbon 1.22.1 A simple API extension for D...
    nikic/php-parser v3.1.0 A PHP parser written in PHP
    paragonie/random_compat v2.0.10 PHP 5.x polyfill for random_...
    phpdocumentor/reflection-common 1.0 Common reflection classes us...
    phpdocumentor/reflection-docblock 3.2.2 With this component, a libra...
    phpdocumentor/type-resolver 0.3.0
    phpspec/prophecy v1.7.0 Highly opinionated mocking f...
    phpunit/php-code-coverage 4.0.8 Library that provides collec...
    phpunit/php-file-iterator 1.4.2 FilterIterator implementatio...
    phpunit/php-text-template 1.2.1 Simple template engine.
    phpunit/php-timer 1.0.9 Utility class for timing
    phpunit/php-token-stream 2.0.1 Wrapper around PHP's tokeniz...
    phpunit/phpunit 5.7.21 The PHP Unit Testing framework.
    phpunit/phpunit-mock-objects 3.4.4 Mock Object library for PHPUnit
    psr/http-message 1.0.1 Common interface for HTTP me...
    psr/log 1.0.2 Common interface for logging...
    psy/psysh v0.8.11 An interactive shell for mod...
    ramsey/uuid 3.7.0 Formerly rhumsaa/uuid. A PHP...
    sebastian/code-unit-reverse-lookup 1.0.1 Looks up which function or m...
    sebastian/comparator 1.2.4 Provides the functionality t...
    sebastian/diff 1.4.3 Diff implementation
    sebastian/environment 2.0.0 Provides functionality to ha...
    sebastian/exporter 2.0.0 Provides the functionality t...
    sebastian/global-state 1.1.1 Snapshotting of global state
    sebastian/object-enumerator 2.0.1 Traverses array structures a...
    sebastian/recursion-context 2.0.0 Provides functionality to re...
    sebastian/resource-operations 1.0.0 Provides a list of PHP built...
    sebastian/version 2.0.1 Library that helps with mana...
    stecman/symfony-console-completion 0.7.0 Automatic BASH completion fo...
    swiftmailer/swiftmailer v5.4.8 Swiftmailer, free feature-ri...
    symfony/browser-kit v3.3.6 Symfony BrowserKit Component
    symfony/console v3.3.6 Symfony Console Component
    symfony/css-selector v3.3.6 Symfony CssSelector Component
    symfony/debug v3.3.6 Symfony Debug Component
    symfony/dom-crawler v3.3.6 Symfony DomCrawler Component
    symfony/event-dispatcher v3.3.6 Symfony EventDispatcher Comp...
    symfony/finder v3.3.6 Symfony Finder Component
    symfony/http-foundation v3.3.6 Symfony HttpFoundation Compo...
    symfony/http-kernel v3.3.6 Symfony HttpKernel Component
    symfony/polyfill-mbstring v1.5.0 Symfony polyfill for the Mbs...
    symfony/process v3.3.6 Symfony Process Component
    symfony/routing v3.3.6 Symfony Routing Component
    symfony/translation v3.3.6 Symfony Translation Component
    symfony/var-dumper v3.3.6 Symfony mechanism for explor...
    symfony/yaml v3.3.6 Symfony Yaml Component
    tijsverkoyen/css-to-inline-styles 2.2.0 CssToInlineStyles is a class...
    vlucas/phpdotenv v2.4.0 Loads environment variables ...
    webmozart/assert 1.2.0 Assertions to validate metho...
  • Suite configuration:
# paste suite config here
actor: UnitTester
modules:
    enabled:
        - Laravel5:
            environment_file: .env.testing
            part: ORM
        - Db:
            dsn: 'sqlite:storage/testing.sqlite'
            user: ''
            password: ''
        - Asserts
        - \Helper\Unit

actor: FunctionalTester
modules:
    enabled:
        - Laravel5:
            environment_file: .env.testing
            run_database_migrations: true
            cleanup: true
        - REST:
           depends: PhpBrowser
           url: 'http://127.0.0.1:8000'
        - \Helper\Functional

actor: ApiTester
modules:
    enabled:
        - \Helper\Api
        - REST:
            url: 'http://127.0.0.1:8000/api/'
            depends: Laravel5
        
@Naktibalda
Copy link
Member

Naktibalda commented Aug 23, 2017

.env is a default value of environment_file setting so what you described is an expected behaviour.

https://github.com/Codeception/Codeception/blob/2.3.5/src/Codeception/Module/Laravel5.php#L122

@krtorio
Copy link
Author

krtorio commented Aug 23, 2017

If you look at my unit and functional suite configs you can see they are using .env.testing
Does this mean all suites go back to using default if one suite uses .env?

@Naktibalda
Copy link
Member

Ok, it makes sense now. I will take a look at it, unless @DavertMik gets it first.

@DavertMik
Copy link
Member

DavertMik commented Aug 24, 2017

Laravel5 module is recreated for each suite. Class is instantiated and configs do not overlap. Could you add codecept_debug($this->config) to trace the configuration changes?

@krtorio
Copy link
Author

krtorio commented Aug 29, 2017

Hi,

Where am I supposed to put this? In one of the tests?
It gives me an undefined property error exception when I do that

[ErrorException] Undefined property: ProductListCest::$config

@Naktibalda
Copy link
Member

In Laravel5.php file

@krtorio
Copy link
Author

krtorio commented Aug 30, 2017

codecept_debug($this->config) shows nothing.

I used var_dump instead, showed that suite config uses .env.testing as indicated in the yml file.
Also I could not recreate the issue, maybe because I upgraded to 2.3.5?

@besingamkb
Copy link

i got the same issue on fresh laravel 7.X.. it works properly until I add an environment_file on unit.suite.yml or codeception.yml
please see below

// unit.suite.yml
actor: UnitTester
modules:
    enabled:
        - Asserts
        - \Helper\Unit
        - Laravel5:
            environment_file: .env.testing
//codeception.yml
paths:
    tests: tests
    output: tests/_output
    data: tests/_data
    support: tests/_support
    envs: tests/_envs
actor_suffix: Tester
extensions:
    enabled:
        - Codeception\Extension\RunFailed
modules:
    enabled:
        - Laravel5
            environment_file: .env.testing

Screenshot_3

@Naktibalda Naktibalda transferred this issue from Codeception/Codeception Jan 9, 2021
@barmax
Copy link

barmax commented Nov 3, 2022

I have the same problem with API tests. I have loaded .env.testing into the suite, but the Laravel does not use it.
Api suite:

- REST:
    url: /
    depends: Laravel
- Laravel:
    environment_file: .env.testing

Laravel version is 7.18
Codeception version is 4.2.2

@barmax
Copy link

barmax commented Nov 4, 2022

I have found the problem source.
The Laravel creates an immutable environment repository instance \Dotenv\Repository\RepositoryInterface. The instance is RepositoryBuilder from the package vlucas/phpdotenv.
When the Laravel tries change ENV-values to the .env-file from the Codeception, the immutable RepositoryBuilder does not.

The RepositoryBuilder has removed since version 5.0.

My stack:

  • Laravel version is 7.18
  • Codeception version is 4.2.2
  • vlucas/phpdotenv version is 4.1.7

I have prepared the pull request - #46

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants