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

unit test fails SQLSTATE[42S02]: Base table or view not found: 1146 Table 'matomo_tests.option' doesn't exist #17078

Closed
RobMcA opened this issue Jan 12, 2021 · 4 comments
Labels
c: Platform For Matomo platform changes that aren't impacting any of our APIs but improve the core itself. duplicate For issues that already existed in our issue tracker and were reported previously.

Comments

@RobMcA
Copy link

RobMcA commented Jan 12, 2021

After following the development setup and testing instruction, when running ./console tests:run --testsuite unit I get an error. I have created the database matomo_tests as mentioned in the docs, but don't see anything in the documentation on how to get the required tables created.

./console tests:run --testsuite unit                                                                                          
Executing command: cd /Users/rmcarthu/Development/repos/rmcarthu/matomo/tests/PHPUnit &&  /Users/rmcarthu/Development/repos/rmcarthu/matomo/vendor/bin/phpunit   --testsuite UnitTests

Fatal error: Uncaught PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'matomo_tests.option' doesn't exist in /Users/rmcarthu/Development/repos/rmcarthu/matomo/libs/Zend/Db/Statement/Pdo.php:233
Stack trace:
#0 /Users/rmcarthu/Development/repos/rmcarthu/matomo/libs/Zend/Db/Statement/Pdo.php(233): PDOStatement->execute()
#1 /Users/rmcarthu/Development/repos/rmcarthu/matomo/libs/Zend/Db/Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)
#2 /Users/rmcarthu/Development/repos/rmcarthu/matomo/libs/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#3 /Users/rmcarthu/Development/repos/rmcarthu/matomo/libs/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('SELECT option_v...', Array)
#4 /Users/rmcarthu/Development/repos/rmcarthu/matomo/core/Db/Adapter/Pdo/Mysql.php(309): Zend_Db_Adapter_Pdo_Abstract->query('SELECT option_v...', Array)
#5 /Users/rmcarthu/Development/repos/rmcarthu/matomo/libs/Zend/Db/Adapter/Abstract.php(736): Piwik\Db\Adapter\Pdo\Mysql->query(' in /Users/rmcarthu/Development/repos/rmcarthu/matomo/libs/Zend/Db/Statement/Pdo.php on line 236
@tsteur
Copy link
Member

tsteur commented Jan 13, 2021

Hi @RobMcA thanks for creating this issue. I suppose you're using the latest 4.X version of Matomo from github?

In matomo-org/developer-documentation#385 it was mentioned that the MySQL user needs to have CREATE/DROP database & tables etc permission. Do you know if the MySQL user is maybe missing some permissions? Although I would assume in this case maybe the error message would be different.

The issue also mentions that somehow ./console tests:setup-fixture OmniFixture needs to be called once. Does it maybe work after executing that command?

@tsteur tsteur added c: Platform For Matomo platform changes that aren't impacting any of our APIs but improve the core itself. Waiting for user feedback Indicates the Matomo team is waiting for feedback from the author or other users. labels Jan 13, 2021
@RobMcA
Copy link
Author

RobMcA commented Jan 14, 2021

Thanks for the input. After setting request_uri = "" I ran ./console tests:setup-fixture OmniFixture and it loaded a number of fixtures before having a failure:

Dropping database 'matomo_tests'...
Setting up Piwik\Tests\Fixtures\ManySitesImportedLogsWithXssAttempts...
Setting up Piwik\Plugins\Contents\tests\Fixtures\TwoVisitsWithContents...
Setting up Piwik\Tests\Fixtures\FewVisitsWithSetVisitorId...
Setting up Piwik\Tests\Fixtures\InvalidVisits...
Setting up Piwik\Tests\Fixtures\ManySitesImportedLogs...
Setting up Piwik\Tests\Fixtures\ManyVisitsWithGeoIP...
Setting up Piwik\Tests\Fixtures\ManyVisitsWithGeoIPAndEcommerce...
Setting up Piwik\Tests\Fixtures\ManyVisitsWithMockLocationProvider...
Setting up Piwik\Tests\Fixtures\ManyVisitsWithSubDirReferrersAndCustomVars...
Setting up Piwik\Tests\Fixtures\OneVisitSeveralPageViews...
Setting up Piwik\Tests\Fixtures\OneVisitWithAbnormalPageviewUrls...



  [PHPUnit\Framework\ExpectationFailedException]
  Expected GIF beacon, got: <br/>
  'GIF89a' . "\0" . '' . "\0" . '?' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0"
  . '' . "\0" . '!?' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . ',' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" .
  '' . "\0" . '' . "\0" . '' . "\0" . 'D' . "\0" . ';This resource is part of Matomo. Keep full control of your
  data with the leading free and open source <a href=\'https://matomo.org\' target=\'_blank\' rel=\'noopener noreferr
  er nofollow\'>web analytics & conversion optimisation platform</a>.<br>
  This file is the endpoint for the Matomo tracking API. If you want to access the Matomo UI or use the Reporting API
  , please use <a href=\'index.php\'>index.php</a> instead.'
   If you are stuck, you can enable [Tracker] debug=1; in config.ini.php to get more debug info.
   Also, please try to restart your webserver, and run the test again, this may help!R0lGODlhAQABAIAAAAAAAAAAACH5BAEA
  AAAALAAAAAABAAEAAAICRAEAO1RoaXMgcmVzb3VyY2UgaXMgcGFydCBvZiBNYXRvbW8uIEtlZXAgZnVsbCBjb250cm9sIG9mIHlvdXIgZGF0YSB3aXR
  oIHRoZSBsZWFkaW5nIGZyZWUgYW5kIG9wZW4gc291cmNlIDxhIGhyZWY9J2h0dHBzOi8vbWF0b21vLm9yZycgdGFyZ2V0PSdfYmxhbmsnIHJlbD0nbm
  9vcGVuZXIgbm9yZWZlcnJlciBub2ZvbGxvdyc+d2ViIGFuYWx5dGljcyAmIGNvbnZlcnNpb24gb3B0aW1pc2F0aW9uIHBsYXRmb3JtPC9hPi48YnI+C
  lRoaXMgZmlsZSBpcyB0aGUgZW5kcG9pbnQgZm9yIHRoZSBNYXRvbW8gdHJhY2tpbmcgQVBJLiBJZiB5b3Ugd2FudCB0byBhY2Nlc3MgdGhlIE1hdG9t
  byBVSSBvciB1c2UgdGhlIFJlcG9ydGluZyBBUEksIHBsZWFzZSB1c2UgPGEgaHJlZj0naW5kZXgucGhwJz5pbmRleC5waHA8L2E+IGluc3RlYWQu
   ===========================
   URL was: http://localhost:8000/tests/PHPUnit/proxy/matomo.php?idsite=1&rec=1&apiv=1&r=878744&cip=156.5.3.2&cdt=201
  2-01-11+12%3A04%3A33&_idts=1610633601&fla=1&java=1&qt=0&realp=0&pdf=0&wma=0&ag=0&h=12&m=34&s=6&res=1024x768&cookie=
  1&_id=a898c00b8e1d9f0c&url=http%3A%2F%2Fwww.my.url%2F%EA%9F%BD%EF%A4%BB%E3%92%A7%E4%8A%B6%E4%BA%84%EF%B6%86%E2%85%8
  5%E0%B8%82%CE%BA%E3%82%82%E1%8A%B8%E1%BD%B9%CF%83%E0%A4%B6%CE%BC%CE%B5%DE%96%E0%A5%83&urlref=http%3A%2F%2Fwww.googl
  e.com%2Fsearch%3Fq%3Dpiwik&pv_id=60e3f6&action_name=Valid+URL%2C+although+strange+looking
  Failed asserting that two strings are equal.

Looking in the web log I see the following error:

[Thu Jan 14 09:13:23 2021] 127.0.0.1:60321 [200]: /tests/PHPUnit/proxy/matomo.php?idsite=1&rec=1&apiv=1&r=201934&cip=156.5.3.2&cdt=2012-01-11+11%3A52%3A33&_idts=1610633601&fla=1&java=1&qt=0&realp=0&pdf=0&wma=0&ag=0&h=12&m=34&s=6&res=1024x768&cookie=1&_id=a898c00b8e1d9f0c&url=http%3A%2F%2Fwww.example.org%2Ffoo%2Fbar3.html&urlref=http%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3Dpiwik&pv_id=480d82&action_name=incredible.title%2F
[Thu Jan 14 09:13:23 2021] Error in Matomo (tracker): Error query: SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xEA_\xBD\xEF\xA4\xBB...' for column 'name' at row 1 In query: INSERT INTO log_action (name, hash, type, url_prefix) VALUES (?,CRC32(?),?,?) Parameters: array (   0 => 'my.url/�_�碌�_��_��_�_�__�_κ�__�_�ό�_शμε�_�_',   1 => 'my.url/�_�碌�_��_��_�_�__�_κ�__�_�ό�_शμε�_�_',   2 =>,   3 => 1, )

My mysql database is running utf8mbf3. Any suggestions?

I tried /.console tests:run and it complained

Executing command: cd /Users/rmcarthu/Development/repos/rmcarthu/matomo/tests/PHPUnit &&  /Users/rmcarthu/Development/repos/rmcarthu/matomo/vendor/bin/phpunit   --testsuite UnitTests
WARNING: for tests to pass, you must first:
1) Install webserver on localhost, eg. apache
2) Make these Piwik files available on the webserver, at eg. http://localhost/dev/piwik/
3) Install Piwik by going through the installation process
4) Configure tests section if needed in config/config.ini.php:
[tests]
http_host   = "localhost"
request_uri = "@REQUEST_URI@"
remote_addr = "127.0.0.1"

Try again.

Changing request_uri = "@REQUEST_URI@" then allowed tests to run. So it seems there is inconsistency as to what the request_uri` value should be.

@RobMcA
Copy link
Author

RobMcA commented Jan 14, 2021

Strangely, resetting everything from scratch and running it all again resulted in the unit tests running fine with no change needed to request_uri.

@tsteur
Copy link
Member

tsteur commented Jan 14, 2021

Thanks @RobMcA I'll close this issue for now as a duplicate of matomo-org/developer-documentation#385 where we need to adjust the docs as I understand it works now for you. Thanks for trying all this and sorry for running into that trouble. Did you initially set the request_uri in the config?

@tsteur tsteur closed this as completed Jan 14, 2021
@tsteur tsteur added duplicate For issues that already existed in our issue tracker and were reported previously. and removed Waiting for user feedback Indicates the Matomo team is waiting for feedback from the author or other users. labels Jan 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: Platform For Matomo platform changes that aren't impacting any of our APIs but improve the core itself. duplicate For issues that already existed in our issue tracker and were reported previously.
Projects
None yet
Development

No branches or pull requests

2 participants