0

i am using redbeanPHP since two years. On my new project i wan´t to implement unit-tests from the beginning.

I installed phpUnit and without the database connection all works fine. I now wan´t to test my classes with database intigration. I know this is not a unit-test anymore. But i thing it will help me a lot to auto test the functionality from the implementation.

I call R::setup("mysql:host=localhost;dbname=ufm","root","root"); in my setup file which i declared as bootstrap file for phpUnit.

If i now run my tests i get:

PDOException: Could not connect to database (ufm). phar:///Applications/MAMP/htdocs/ufm/core/plugins/rb.phar/RedBeanPHP/Driver/RPDO.php:280 phar:///Applications/MAMP/htdocs/ufm/core/plugins/rb.phar/RedBeanPHP/Driver/RPDO.php:126 phar:///Applications/MAMP/htdocs/ufm/core/plugins/rb.phar/RedBeanPHP/Driver/RPDO.php:289 phar:///Applications/MAMP/htdocs/ufm/core/plugins/rb.phar/RedBeanPHP/Adapter/DBAdapter.php:79 phar:///Applications/MAMP/htdocs/ufm/core/plugins/rb.phar/RedBeanPHP/QueryWriter/AQueryWriter.php:576 phar:///Applications/MAMP/htdocs/ufm/core/plugins/rb.phar/RedBeanPHP/OODB.php:893 phar:///Applications/MAMP/htdocs/ufm/core/plugins/rb.phar/RedBeanPHP/Facade.php:463 /Applications/MAMP/htdocs/ufm/tests/TurnierTest.php:14

The strange thing is that i am using the same setup file in my normal application. There all works fine.

Has phpUnit or redbeanPHP any limitations for database connection in the bootstrap file? I searched for two days now but i can´t find any documentation about this. I only found a blogpost on google groups where some guy successfully makes the exact same thing.

Thanks for your help. Best regards,schw4ndi

schw4ndi
  • 231
  • 4
  • 18
  • A other solution would be to intigrate phpUnit database testing (http://phpunit.de/manual/3.7/en/database.html). But i can´t find a solution with redbeanPHP for it. Has anyone integrated redbeanPHP to phpUnit database testing? – schw4ndi May 30 '14 at 10:15

2 Answers2

0

Try this:

R::setup("mysql:host=localhost;dbname=ufm;port=3306","root","root");

I added port number there see if that helps.

If you need a working Test Unit + Redbean example, you can try skully framework here: http://github.com/triodigital/skully-project

Setting up

  1. Clone this project to your server.
  2. Copy config/config.unique.php.original to config/config.unique.php and update the database information there.
  3. Update baseUrl config in config/config.common.php.
  4. Copy .htaccess.original to .htaccess and update the first line of that file.
  5. Update the project by running './composer.phar install'.
jaycode
  • 2,926
  • 5
  • 35
  • 71
0

I stumbled accros the same error again. Just change the localhost to 127.0.0.1 and it works fine! Maybe it helps someone in the future.

R::setup("mysql:host=127.0.0.1;dbname=ufm","root","root");
schw4ndi
  • 231
  • 4
  • 18