0

Is there a way to point the DB module for Functional tests in codeception to your MAMP MySQL server rather than the built in server?

class_name: TestGuy
    modules:
        enabled: [Db, Filesystem, TestHelper]
        config:
          Db:
             dsn: 'mysql:host=localhost;dbname=testdb'
             user: 'root'
             password: 'root'
             dump: 'tests/_data/dump.sql'
             populate: true
             cleanup: false
Ashley Banks
  • 528
  • 5
  • 16

5 Answers5

2

Codeception uses PDO to connect to the database. It will pass the "dsn" string straight into the PDO constructor. Thus, according to http://www.php.net//manual/en/ref.pdo-mysql.connection.php, your configuration should be the following in order to connect to the MAMP MySQL Server running on port 8889:

class_name: TestGuy
    modules:
        enabled: [Db, Filesystem, TestHelper]
        config:
          Db:
             dsn: 'mysql:host=localhost;port=8889;dbname=testdb'
             user: 'root'
             password: 'root'
             dump: 'tests/_data/dump.sql'
             populate: true
             cleanup: false
Motin
  • 4,853
  • 4
  • 44
  • 51
0

This is what fixed the issue for me. In MAMP I ticket the box "Allow network access to MySQL" enter image description here

My dsn setting in codeception.yml is: dsn: 'mysql:host=127.0.0.1;port=3306;dbname=la51'

Rbijker.com
  • 2,894
  • 3
  • 21
  • 26
-1

Have you tried this at all - might work for you too..

class_name: TestGuy
modules:
enabled: [Filesystem, TestHelper, WebHelper, PhpBrowser]
config:
    PhpBrowser:
        url: 'http://localhost/yourapp/'
        curl:
             CURL_RETURNTRANSFER: true

Let me know how that works for you :)

http://codeception.com/docs/modules/PhpBrowser

Zabs
  • 13,852
  • 45
  • 173
  • 297
  • But how does that point to the MySQL server - the issue is that the tests try and access my built in server so I can't test my databases on MAMP – Ashley Banks Aug 16 '13 at 13:15
-1

I'd double check your mysql table within the dump

Once setup just add something like this to your tests

$I->seeInDatabase('users', array('name' => 'Davert', 'email' => 'davert@mail.com'));

Thiss will check the 'users' table and look for the row with the name & email as supplied in the array - works for me.

Zabs
  • 13,852
  • 45
  • 173
  • 297
  • Yeah I know how to test that data is going in - I just don't know how to point it to my MAMP database rather than the built in MYSQL server – Ashley Banks Sep 05 '13 at 13:16
  • I'd maybe look at Google Groups.. may be some CodeCeption groups that could assist you there – Zabs Sep 11 '13 at 11:05
-1

Two things—I believe—would fix this your problem

  1. Make sure the module for which you are setting the database parameters is the same. DB is different from Db
  2. MAMP runs its MySQL on port 8889. If you only specify localhost in the dsn string, Codeception will try to connect to a MySQL instance running on port 3306—which is MySQL's default port. Change localhost to localhost:8889

I just fixed this problem myself. Comment for further clarifications if need be.

Cheers

EDIT

Recently, I revisited the project which I used Codeception. This solution did not work for me. I ran into two issues

  1. Timezone Exception You can fix this by...
    • Making sure the timezone is set correctly in your php.ini file, which is usually in /Applications/MAMP/bin/php/php5.x/conf/
    • AND/OR aliasing php to use MAMP's by doing alias phpm="/Applications/MAMP/bin/php5.x/bin/php"
  2. [Codeception\Exception\Module] (Exception in Db) This is primarily because of the configuration of the module. I removed the port number from my configuration and everything seems to work fine.
Igbanam
  • 5,904
  • 5
  • 44
  • 68
  • Thanks, seems plausible will give it a whirl and let you know – Ashley Banks Sep 17 '13 at 16:48
  • This always returns a "Unknown MySQL server host 'localhost:8889'" – Ashley Banks Sep 26 '13 at 12:58
  • @AshleyBanks `8889` is the port on which my MAMP's MySQL server is running. If yours is not running on port 8889, this error will suffice. Check your MAMP ports in `Preferences -> Ports` and set the port accordingly. Cheers – Igbanam Sep 27 '13 at 21:50
  • Ironically, this stopped working for me. Did you find a fix, @AshleyBanks? – Igbanam Feb 09 '14 at 03:13