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

Fix documentation for properly setting and running of Piwik Tests #10348

Closed
blueelvis opened this issue Jul 26, 2016 · 12 comments · Fixed by matomo-org/developer-documentation#307
Labels
c: Tests & QA For issues related to automated tests or making it easier to QA & test issues.
Milestone

Comments

@blueelvis
Copy link
Contributor

I was trying to run the Tests to make sure that my code is working, but I got the following error on starting the tests -

$ ./console tests:run --testsuite unit
Executing command: cd C:\xampp\htdocs\PHPStorm/tests/PHPUnit && C:\xampp\htdocs\PHPStorm/vendor/bin/phpunit --testsuite UnitTests

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'piwik_tests.piwiktests_option' doesn't exist' in C:\xampp\htdocs\PHPStorm\libs\Zend\Db\Statement\Pdo.php:228
Stack trace:

0 C:\xampp\htdocs\PHPStorm\libs\Zend\Db\Statement\Pdo.php(228): PDOStatement->execute(Array)

1 C:\xampp\htdocs\PHPStorm\libs\Zend\Db\Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)

2 C:\xampp\htdocs\PHPStorm\libs\Zend\Db\Adapter\Abstract.php(479): Zend_Db_Statement->execute(Array)

3 C:\xampp\htdocs\PHPStorm\libs\Zend\Db\Adapter\Pdo\Abstract.php(238): Zend_Db_Adapter_Abstract->query('SELECT option_v...', Array)

4 C:\xampp\htdocs\PHPStorm\core\Db\Adapter\Pdo\Mysql.php(245): Zend_Db_Adapter_Pdo_Abstract->query('SELECT option_v...', Array)

5 C:\xampp\htdocs\PHPStorm\libs\Zend\Db\Adapter\Abstract.php(736): Piwik\Db\Adapter\Pdo\Mysql->query('SELECT option_v...', Array)

6 C:\xampp\htdocs\PHPStorm\core\Db.php(211): Zend_Db_Adapter_Abstract->fetchAll('SELECT option_v...', Arr in C:\xampp\htdocs\PHPStorm\libs\Zend\Db\Statement\Pdo.php on line 234

Apparently, there is more to setting up the database before I can run the tests.

@tsteur
Copy link
Member

tsteur commented Jul 31, 2016

If tests are ran from an already installed Piwik, it should configure everything automatically and just work from what I remember. Can you check if you have a section [database_tests] in your config/config.ini.php as described here? https://github.com/piwik/piwik/tree/master/tests#phpunit-tests

Mine looks like this:

[database_tests]
host = "127.0.0.1"
username = "root"
password = "secure"
tables_prefix = ""

I don't think the empty tables_prefix entry is required but maybe it helps

@blueelvis
Copy link
Contributor Author

I tried running the tests using your way but I am not able to run the Integration tests. Unit Tests ran fine. Please note that I reinstalled Piwik from scratch as well. I am getting the below error log now -

  1. Piwik\Plugins\UsersManager\tests\Integration\UsersManagerTest
    Failed to setup fixture: TEST INITIALIZATION FAILED: Trying to drop original database 'workspace'. Something's wrong w/ the tests.
    #0 C:\xampp\htdocs\PHPStorm\tests\PHPUnit\Framework\Fixture.php(227): Piwik\Tests\Framework\Fixture->dropDatabase()
    adding support for windows phone 7 version 7.5 #1 C:\xampp\htdocs\PHPStorm\tests\PHPUnit\Framework\TestCase\SystemTestCase.php(76): Piwik\Tests\Framework\Fixture->performSetUp()
    Using alternate database. #2 C:\xampp\htdocs\PHPStorm\tests\PHPUnit\Framework\TestCase\IntegrationTestCase.php(61): Piwik\Tests\Framework\TestCase\SystemTestCase::setUpBeforeClass()
    Updates ? #3 [internal function]: Piwik\Tests\Framework\TestCase\IntegrationTestCase::setUpBeforeClass()
    SitesManager plugins: added group managment to admin UI #4 C:\xampp\htdocs\PHPStorm\vendor\phpunit\phpunit\src\Framework\TestSuite.php(697): call_user_func(Array)
    Collaboration via github #5 C:\xampp\htdocs\PHPStorm\vendor\phpunit\phpunit\src\TextUI\TestRunner.php(440): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
    [#3316] Add request parameter option to disable seriesPicker on jqplot #6 C:\xampp\htdocs\PHPStorm\vendor\phpunit\phpunit\src\TextUI\Command.php(149): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array)
    [#3341] Add possibility to pass custom plot properties in request eg. canvasLegend #7 C:\xampp\htdocs\PHPStorm\vendor\phpunit\phpunit\src\TextUI\Command.php(100): PHPUnit_TextUI_Command->run(Array, true)
    [#3317] export_as_image_icon setting has no effect on widget #8 C:\xampp\htdocs\PHPStorm\vendor\phpunit\phpunit\phpunit(47): PHPUnit_TextUI_Command::main()
    [#3327] Add show_related_reports request parameter #9 {main}
    #0 C:\xampp\htdocs\PHPStorm\tests\PHPUnit\Framework\Fixture.php(245): PHPUnit_Framework_Assert::fail('TEST INITIALIZA...')
    adding support for windows phone 7 version 7.5 #1 C:\xampp\htdocs\PHPStorm\tests\PHPUnit\Framework\TestCase\SystemTestCase.php(76): Piwik\Tests\Framework\Fixture->performSetUp()
    Using alternate database. #2 C:\xampp\htdocs\PHPStorm\tests\PHPUnit\Framework\TestCase\IntegrationTestCase.php(61): Piwik\Tests\Framework\TestCase\SystemTestCase::setUpBeforeClass()
    Updates ? #3 [internal function]: Piwik\Tests\Framework\TestCase\IntegrationTestCase::setUpBeforeClass()
    SitesManager plugins: added group managment to admin UI #4 C:\xampp\htdocs\PHPStorm\vendor\phpunit\phpunit\src\Framework\TestSuite.php(697): call_user_func(Array)
    Collaboration via github #5 C:\xampp\htdocs\PHPStorm\vendor\phpunit\phpunit\src\TextUI\TestRunner.php(440): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
    [#3316] Add request parameter option to disable seriesPicker on jqplot #6 C:\xampp\htdocs\PHPStorm\vendor\phpunit\phpunit\src\TextUI\Command.php(149): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array)
    [#3341] Add possibility to pass custom plot properties in request eg. canvasLegend #7 C:\xampp\htdocs\PHPStorm\vendor\phpunit\phpunit\src\TextUI\Command.php(100): PHPUnit_TextUI_Command->run(Array, true)
    [#3317] export_as_image_icon setting has no effect on widget #8 C:\xampp\htdocs\PHPStorm\vendor\phpunit\phpunit\phpunit(47): PHPUnit_TextUI_Command::main()
    [#3327] Add show_related_reports request parameter #9 {main}

C:\xampp\htdocs\PHPStorm\tests\PHPUnit\Framework\TestCase\SystemTestCase.php:78
C:\xampp\htdocs\PHPStorm\tests\PHPUnit\Framework\TestCase\IntegrationTestCase.php:61

FAILURES!
Tests: 3721, Assertions: 0, Errors: 61.

@tsteur
Copy link
Member

tsteur commented Aug 1, 2016

Does the MySQL user maybe not have enough permission eg to drop a database or so?

@blueelvis
Copy link
Contributor Author

@tsteur - I checked the permissions and everything is setup correctly. Since this is my personal dev machine, the database user has got every permission listed.

@mattab
Copy link
Member

mattab commented Oct 21, 2016

Today I have experienced the same problem! so there is something buggy (at least in 2.x-dev branch). Not found the solution so far.
my config.ini.php has:

[database_tests]
host = "127.0.0.1"
username = "root"
password = ""
dbname = piwik_tests
tables_prefix = piwiktests_

(changing tables_prefix does not help)

output:

$ ./console tests:run
Executing command: cd /home/matt/dev/piwik-2.x-dev/tests/PHPUnit && /home/matt/dev/piwik-2.x-dev/vendor/bin/phpunit   --testsuite UnitTests
PHP Fatal error:  Uncaught PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'piwik_tests.piwiktests_option' doesn't exist in /home/matt/dev/piwik-2.x-dev/libs/Zend/Db/Statement/Pdo.php:228
Stack trace:
#0 /home/matt/dev/piwik-2.x-dev/libs/Zend/Db/Statement/Pdo.php(228): PDOStatement->execute(Array)
#1 /home/matt/dev/piwik-2.x-dev/libs/Zend/Db/Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)
#2 /home/matt/dev/piwik-2.x-dev/libs/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#3 /home/matt/dev/piwik-2.x-dev/libs/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('SELECT option_v...', Array)
#4 /home/matt/dev/piwik-2.x-dev/core/Db/Adapter/Pdo/Mysql.php(245): Zend_Db_Adapter_Pdo_Abstract->query('SELECT option_v...', Array)
#5 /home/matt/dev/piwik-2.x-dev/libs/Zend/Db/Adapter/Abstract.php(736): Piwik\Db\Adapter\Pdo\Mysql->query('SELECT option_v...', Array)
#6 /home/matt/dev/piwik-2.x-dev/core/Db.php(217): Zend_Db_Adapter_Abstract->fetchAll('SELECT option_v... in /home/matt/dev/piwik-2.x-dev/libs/Zend/Db/Statement/Pdo.php on line 234

@mattab mattab added the c: Tests & QA For issues related to automated tests or making it easier to QA & test issues. label Oct 21, 2016
@mattab
Copy link
Member

mattab commented Oct 21, 2016

Found the solution for me, as my piwik is installed in a sub-directory (at localhost/piwik-2.x-dev), it's required to set:

[tests]
request_uri = "/piwik-2.x-dev/"

we need to improve this and document it better both on: https://developer.piwik.org/guides/getting-started-part-1 and in the console command output

@mattab mattab modified the milestones: 3.0.0-b3, 3.0.0 Oct 21, 2016
@mattab mattab added the Major Indicates the severity or impact or benefit of an issue is much higher than normal but not critical. label Oct 21, 2016
@johnhess
Copy link

johnhess commented Mar 30, 2017

I had the same trouble trying to set up tests at 3.0.2. In particular, I was getting a handful of errors which I'll reproduce below so folks googling can find them.

When following the instructions verbatim, I got this error trying to run unit tests

PHP Fatal error:  Uncaught PDOException: SQLSTATE[HY000] [1045] Access denied for user '@USERNAME@'@'localhost' (using password: YES) in /piwik/piwik/libs/Zend/Db/Adapter/Pdo/Abstract.php:128

When, in the course of experimenting, I tried changing user to username, I got a different error:

PHP Fatal error:  Uncaught PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'piwik_tests.piwiktests_option' doesn't exist in /media/sf_bkassembly-piwik/piwik/libs/Zend/Db/Statement/Pdo.php:228

To solve this, I copied a section from global.ini.php into config.ini.php and filled in appropriate values:


[database_tests]
host = localhost
username = "root"
password = "root"
dbname = piwik_tests
tables_prefix = piwiktests_
port = 3306
adapter = PDO\MYSQL
type = InnoDB
schema = Mysql
charset = utf8

[tests]
; needed in order to run tests.
; if Piwik is available at http://localhost/dev/piwik/ replace @REQUEST_URI@ with /dev/piwik/
; note: the REQUEST_URI should not contain "plugins" or "tests" in the PATH
http_host   = localhost
remote_addr = "127.0.0.1"
request_uri = "/"
port = 8777             # turned out to be very important

The tests now run fine

I'd be happy to submit a patch to the docs if someone can confirm that the result I have here is roughly what the docs ought to suggest.

@mattab
Copy link
Member

mattab commented Jun 21, 2017

Thanks for posting @johnhess - a patch to the developer docs would be appreciated 👍

@johsin18
Copy link
Contributor

With Matomo 3.5.1 (from archive)

./console tests:run

does not work anymore at all:

[InvalidArgumentException]                               
There are no commands defined in the "tests" namespace.  

But the docs here still propose to execute that:
https://developer.matomo.org/guides/tests-php

@sgiehl
Copy link
Member

sgiehl commented Jul 18, 2018

@johsin18 did you run ./console development:enable?

@johsin18
Copy link
Contributor

@sgiehl development:enable did not help, but what did help was to install Matomo from the git repo (not from the archive). This is mentioned clearly in tests/README.md, but not here:
https://developer.matomo.org/guides/tests
It is proposed here
https://developer.matomo.org/guides/getting-started-part-1
but sounds more like an optional thing there, and in fact most other stuff works with the archive version as well.
Could you maybe mention in this section at least?
https://developer.matomo.org/guides/getting-started-part-1#if-you-want-to-execute-the-automated-test-suite

@mattab mattab removed the Major Indicates the severity or impact or benefit of an issue is much higher than normal but not critical. label Nov 28, 2018
mattab added a commit to matomo-org/developer-documentation that referenced this issue Jun 24, 2019
experienced these while setting up a new dev environment earlier
Should fix matomo-org/matomo#10348
@mattab
Copy link
Member

mattab commented Jun 24, 2019

Created PR at matomo-org/developer-documentation#307

tsteur pushed a commit to matomo-org/developer-documentation that referenced this issue Jun 24, 2019
experienced these while setting up a new dev environment earlier
Should fix matomo-org/matomo#10348
@mattab mattab modified the milestones: 3.13.0, 3.11.0 Jul 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: Tests & QA For issues related to automated tests or making it easier to QA & test issues.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants