@brunowego opened this Pull Request on January 13th 2020

Remove value of attribute tables_prefix in database_tests to prevent confusion when running tests.

@sgiehl commented on January 13th 2020 Member

what kind of confusion did you have with the prefix? 🤔

@brunowego commented on January 13th 2020

@sgiehl thank you for your time. To try explain my point of vision, take a look below. First I create the db test:

mysql \
  -h 127.0.0.1 \
  -P 3306 \
  -u root \
  -p'root' \
  -v <<-\EOSQL
CREATE DATABASE IF NOT EXISTS `matomo_test`;
GRANT ALL PRIVILEGES ON `matomo_test`.* TO 'matomo'@'%';
FLUSH PRIVILEGES;
EOSQL

Second, I import data from db dev to my db test:

mysqldump \
  -h 127.0.0.1 \
  -P 3306 \
  -u matomo \
  -p'matomo' \
  matomo_dev | \
    sed 's/matomodev_/matomotests_/' | \
      mysql \
        -h 127.0.0.1 \
        -P 3306 \
        -u matomo \
        -p'matomo' \
        matomo_test

After that, need necessary configuration to db test:

./console development:enable

./console config:set \
  'database_tests.host="127.0.0.1"' \
  'database_tests.username="matomo"' \
  'database_tests.password="matomo"' \
  'database_tests.dbname="matomo_test"' \
  'database_tests.tables_prefix="matomotests_"'

./console config:set \
  'tests.http_host="127.0.0.1"' \
  'tests.request_uri="/"' \
  'tests.port="8080"'

When run the unit test, I will get failures because is not empty the db prefix table:

./console tests:run \
  --options='--stop-on-error' \
  --testsuite unit
[...]
15) Piwik\Tests\Unit\DataAccess\JoinGeneratorTest::test_generate_getJoinString_allTables
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'log_action AS log_action LEFT JOIN log_link_visit_action AS log_link_visit_action ON log_link_visit_action.idaction_url = log_action.idaction LEFT JOIN log_visit AS log_visit ON log_visit.idvisit = log_link_visit_action.idvisit LEFT JOIN log_conversion AS log_conversion ON log_conversion.idvisit = log_link_visit_action.idvisit LEFT JOIN log_conversion_item AS log_conversion_item ON log_conversion_item.idvisit = log_link_visit_action.idvisit AND `log_conversion_item`.deleted = 0'
+'matomotests_log_action AS log_action LEFT JOIN matomotests_log_link_visit_action AS log_link_visit_action ON log_link_visit_action.idaction_url = log_action.idaction LEFT JOIN matomotests_log_visit AS log_visit ON log_visit.idvisit = log_link_visit_action.idvisit LEFT JOIN matomotests_log_conversion AS log_conversion ON log_conversion.idvisit = log_link_visit_action.idvisit LEFT JOIN matomotests_log_conversion_item AS log_conversion_item ON log_conversion_item.idvisit = log_link_visit_action.idvisit AND `log_conversion_item`.deleted = 0'

/Users/brunowego/Workspace/github.com/matomo-org/matomo/tests/PHPUnit/Unit/DataAccess/LogQueryBuilder/JoinGeneratorTest.php:265

FAILURES!
Tests: 7007, Assertions: 11202, Failures: 15.
@brunowego commented on January 13th 2020

Another point, is a exception when tables_prefix is set up in database_tests:

gtime -v php \
  -d memory_limit=8G \
  ./console tests:run-ui --plugin Insights
[Exception]
  To generate OmniFixture for the UI tests, you must set an empty tables_prefix in [database_tests]
Powered by GitHub Issue Mirror