Giter Site home page Giter Site logo

Seperate test database about apitestcase HOT 5 CLOSED

lchrusciel avatar lchrusciel commented on August 16, 2024
Seperate test database

from apitestcase.

Comments (5)

lchrusciel avatar lchrusciel commented on August 16, 2024

Hello Max, thanks for kind words.

What you expect is the default behavior of the Symfony application and has nothing in common with this library. If it is affecting dev database it means, depending on Symfony version, that either you didn't have test database configured in config files or DATABASE_URL env has been configured in dev mode.

I hope this will help you ;)

from apitestcase.

chucky2305 avatar chucky2305 commented on August 16, 2024

You put me to the right point. I have a local ENV Variable that was pointing to my dev database.
But after removing this env var it does not work either.

When i run the tests now, the database connection params are all filled with default values

In ApiTestCase.php on Line 106:
var_dump($this->entityManager->getConnection());

gives me this:

...
private $_params =>
  array(11) {
    'driver' =>
    string(9) "pdo_mysql"
    'charset' =>
    string(7) "utf8mb4"
    'url' =>
    string(0) ""
    'host' =>
    string(9) "localhost"
    'port' =>
    NULL
    'user' =>
    string(4) "root"
    'password' =>
    NULL
    'driverOptions' =>
    array(0) {
    }
    'serverVersion' =>
    string(3) "5.7"
    'defaultTableOptions' =>
    array(2) {
      'charset' =>
      string(7) "utf8mb4"
      'collate' =>
      string(18) "utf8mb4_unicode_ci"
    }
    'dbname' =>
    string(0) ""
  }

...

although i have defined this in my test/doctrine.yaml

doctrine:
    dbal:
        url: 'mysql://project_user:project_pass@mariadb:3306/project_int'

and this is my phpunit.xml.dist

under <php>

<ini name="error_reporting" value="-1" />
<env name="KERNEL_CLASS" value="App\Kernel" />
<env name="APP_ENV" value="test" />
<env name="APP_DEBUG" value="1" />
<env name="APP_SECRET" value="s$cretf0rt3st" />
<env name="SHELL_VERBOSITY" value="-1" />
<env name="SYMFONY_PHPUNIT_VERSION" value="7.4.3" />
<!--<env name="DATABASE_URL" value="mysql://premium_user:premium_pass@mariadb:3306/premium_int" />-->
<server name="FIXTURES_DIR" value="../tests/fixtures" />
<server name="IS_DOCTRINE_ORM_SUPPORTED" value="true" />

I can only run my tests with valid database settings, when i remove the comments from DATABASE_URL in phpunit.xml.dist

Any ideas , why the doctrine.yaml in my test folder is ignored?

from apitestcase.

lchrusciel avatar lchrusciel commented on August 16, 2024

You may be right, that <!--<env name="DATABASE_URL" value="mysql://premium_user:premium_pass@mariadb:3306/premium_int" />--> may override config. Should be documented.

from apitestcase.

chucky2305 avatar chucky2305 commented on August 16, 2024

I found out that APP_ENV in phpunit.xml.dist is not interpreted in all cases. Especially when you run you code on docker it can happen, that env variables that are stored in the php-container cannot be overwritten by code.

So setting DATABASE_URL in phpunit.xml.dist is one way to go.
Another is documented here:
symfony/flex#251 (comment)

from apitestcase.

lchrusciel avatar lchrusciel commented on August 16, 2024

So I would consider it as solved

from apitestcase.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.