@blueelvis opened this Issue on July 26th 2016 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 commented on July 31st 2016 Member

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 commented on August 1st 2016 Contributor

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 -

61) 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()
#1 C:\xampp\htdocs\PHPStorm\tests\PHPUnit\Framework\TestCase\SystemTestCase.php(76): Piwik\Tests\Framework\Fixture->performSetUp()
#2 C:\xampp\htdocs\PHPStorm\tests\PHPUnit\Framework\TestCase\IntegrationTestCase.php(61): Piwik\Tests\Framework\TestCase\SystemTestCase::setUpBeforeClass()
#3 [internal function]: Piwik\Tests\Framework\TestCase\IntegrationTestCase::setUpBeforeClass()
#4 C:\xampp\htdocs\PHPStorm\vendor\phpunit\phpunit\src\Framework\TestSuite.php(697): call_user_func(Array)
#5 C:\xampp\htdocs\PHPStorm\vendor\phpunit\phpunit\src\TextUI\TestRunner.php(440): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#6 C:\xampp\htdocs\PHPStorm\vendor\phpunit\phpunit\src\TextUI\Command.php(149): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array)
#7 C:\xampp\htdocs\PHPStorm\vendor\phpunit\phpunit\src\TextUI\Command.php(100): PHPUnit_TextUI_Command->run(Array, true)
#8 C:\xampp\htdocs\PHPStorm\vendor\phpunit\phpunit\phpunit(47): PHPUnit_TextUI_Command::main()
#9 {main}
#0 C:\xampp\htdocs\PHPStorm\tests\PHPUnit\Framework\Fixture.php(245): PHPUnit_Framework_Assert::fail('TEST INITIALIZA...')
#1 C:\xampp\htdocs\PHPStorm\tests\PHPUnit\Framework\TestCase\SystemTestCase.php(76): Piwik\Tests\Framework\Fixture->performSetUp()
#2 C:\xampp\htdocs\PHPStorm\tests\PHPUnit\Framework\TestCase\IntegrationTestCase.php(61): Piwik\Tests\Framework\TestCase\SystemTestCase::setUpBeforeClass()
#3 [internal function]: Piwik\Tests\Framework\TestCase\IntegrationTestCase::setUpBeforeClass()
#4 C:\xampp\htdocs\PHPStorm\vendor\phpunit\phpunit\src\Framework\TestSuite.php(697): call_user_func(Array)
#5 C:\xampp\htdocs\PHPStorm\vendor\phpunit\phpunit\src\TextUI\TestRunner.php(440): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#6 C:\xampp\htdocs\PHPStorm\vendor\phpunit\phpunit\src\TextUI\Command.php(149): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array)
#7 C:\xampp\htdocs\PHPStorm\vendor\phpunit\phpunit\src\TextUI\Command.php(100): PHPUnit_TextUI_Command->run(Array, true)
#8 C:\xampp\htdocs\PHPStorm\vendor\phpunit\phpunit\phpunit(47): PHPUnit_TextUI_Command::main()
#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 commented on August 1st 2016 Member

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

@blueelvis commented on August 3rd 2016 Contributor

@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 commented on October 21st 2016 Member

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:
<a href='/0'>#0</a> /home/matt/dev/piwik-2.x-dev/libs/Zend/Db/Statement/Pdo.php(228): PDOStatement->execute(Array)
<a href='/1'>#1</a> /home/matt/dev/piwik-2.x-dev/libs/Zend/Db/Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)
<a href='/2'>#2</a> /home/matt/dev/piwik-2.x-dev/libs/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
<a href='/3'>#3</a> /home/matt/dev/piwik-2.x-dev/libs/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('SELECT option_v...', Array)
<a href='/4'>#4</a> /home/matt/dev/piwik-2.x-dev/core/Db/Adapter/Pdo/Mysql.php(245): Zend_Db_Adapter_Pdo_Abstract->query('SELECT option_v...', Array)
<a href='/5'>#5</a> /home/matt/dev/piwik-2.x-dev/libs/Zend/Db/Adapter/Abstract.php(736): Piwik\Db\Adapter\Pdo\Mysql->query('SELECT option_v...', Array)
<a href='/6'>#6</a> /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 commented on October 21st 2016 Member

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

@johnhess commented on March 30th 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 '<a class='mention' href='https://github.com/USERNAME'>@USERNAME</a>@'@'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 <a class='mention' href='https://github.com/REQUEST_URI'>@REQUEST_URI</a>@ 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 commented on June 21st 2017 Member

Thanks for posting @johnhess - a patch to the developer docs would be appreciated :+1:

@johsin18 commented on July 18th 2018 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 commented on July 18th 2018 Member

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

@johsin18 commented on July 19th 2018 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

Powered by GitHub Issue Mirror