Codeception - pointing DB to MAMP MySQL server - php

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

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

This is what fixed the issue for me.
In MAMP I ticket the box "Allow network access to MySQL"
My dsn setting in codeception.yml is:
dsn: 'mysql:host=127.0.0.1;port=3306;dbname=la51'

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

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.

Two things—I believe—would fix this your problem
Make sure the module for which you are setting the database parameters is the same. DB is different from Db
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
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"
[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.

Related

Expected int, but got string for redis port

I have this configuration for docker:
# docker-compose.yml
environment:
REDIS_SERVER: redis
REDIS_PORT: 6379
And then in symfony I use this to configure parameters:
# parameters.yml
redis_port: %env(REDIS_PORT)%
And then I use the parameter to configure Picmore's cache:
```yaml
# pimcore.yml
cache:
pools:
redis:
enabled: true
connection:
port: '%redis_port%'
But I get the error
Invalid type for path "pimcore.cache.pools.redis.connection.port". Expected int, but got string.
The error is clear but I can't solve it, I tried different options:
redis_port: '%env(REDIS_PORT)%'
redis_port: '%env(int:REDIS_PORT)%'
But I get the same error. How can I fix this?
You are using Symfony 3.3, but the int environment variable preprocessor was not added until Symfony 3.4, according to this.
I don't think you'll be able to use env vars to configure this value, since environment variables are strings by default.
Your options are to either use different parameters files for different environment, as things used to be done back then (which I understand can be inconvenient when using containers); or upgrade to a more recent version of Symfony.

How to use mysql instead of mariadb in symfony 5

i think this might be a stupid question for some, but i swear that i can't find the answer by myself actually.
I'm still learning Symfony so please be nice.
Actually i have set up the access to my database in the .env file :
[...]
DATABASE_URL=mysql://root:db_password#127.0.0.1:3308/db_name
[...]
And then i have define the environnement variable in the config/doctrine.yaml :
doctrine:
dbal:
default_connection: default
connections:
default:
dbname: Symfony
user: root
password: null
host: localhost
server_version: '8.0'
driver: pdo_mysql
charset: UTF8
So i run the following command :
> php bin/console doctrine:database:create
But the 'Symfony' database have been created under mariadb.
:( I don't understand why because i have define precisely that i use a 8.0 version and this version is not a mariadb version.
I've also try this :
# .symfony/services.yaml
mydatabase:
# supported versions: 5.7, 8.0
type: oracle-mysql:8.0
disk: 1024
As the symfony documentation saying to do, but it still not working at all.
I have got the following error message as mydatabase is not a symfony services :
C:\Users\vincp\Symfony\charming_tuto>php bin/console doctrine:database:create
In FileLoader.php line 173:
There is no extension able to load the configuration for "mydatabase" (in "C:\Users\vincp\Symfony\charming_tuto\con
fig/services.yaml"). Looked for namespace "mydatabase", found ""framework", "sensio_framework_extra", "twig", "twig
_extra", "web_profiler", "monolog", "debug", "webpack_encore", "doctrine", "doctrine_migrations", "maker"" in C:\Us
ers\vincp\Symfony\charming_tuto\config/services.yaml (which is being imported from "C:\Users\vincp\Symfony\charming
_tuto\src\Kernel.php").
I wanna use mysql because this is the DBMS that i use usually.
(If you think that i should use mariadb instead of mysql i'm open to that, but give me some arguments. I'd be really interseted in)
Maybe it is a server issue. So first, make sure that MySQL is running on your server besides MariaDB (how to do it depends on the type of server you are using).
If yes, it might be a port setting issue: I see that you set the database port to 3308. That is probably the port on which MariaDB is listenning. Try to determine if there is another db running on your server listening to another port (for example 3306 is very often the default MySQL port). To do so, on a Linux server you could try the following command :
netstat -tlnp | grep mysql
If you find only x x.x.x.x:3308 address or so, I bet that MySQL is not running on your server and you only run a MariaDB instance. But if you find addresses on other ports (for example x x.x.x.x:3306) chances are that a MySQL instance is running and listens that other port. If that's the case, you should consequently change the DATABASE_URL in your .env file.

Cant create migration phinx

When I try create migration I get this exception, but I have not got curly braces in my migration path
[Exception]
You probably used curly braces to define the migration path in your Phinx configuration file, but no directories have been matched using this pattern. You need to create a migration directory manually.
My config:
paths:
migrations: %%PHINX_CONFIG_DIR%%/db/migrations
seeds: %%PHINX_CONFIG_DIR%%/db/seeds
environments:
default_migration_table: phinxlog
default_database: development
production:
adapter: mysql
host: localhost
name: production_db
user: root
pass: ''
port: 3306
charset: utf8
development:
adapter: mysql
host: localhost
name: development_db
user: root
pass: ''
port: 3306
charset: utf8
testing:
adapter: mysql
host: localhost
name: testing_db
user: root
pass: ''
port: 3306
charset: utf8
version_order: creation
Just came across this same error when trying to setup CakePHP & Phinx.
Was caused by missing out the directory when running the Phinx command.
Docs say to init the system type :
phinx init .
(If Phinx was installed via composer use : vendor/bin/phinx init . )
If you miss out the '.' you get the error you have described. It looks like Phinx doesn't have a default setting of using the currently working directory.
http://docs.phinx.org/en/latest/commands.html#the-init-command.
You can fix the issue by ether re-running the Phinx command or by manually creating the folders :
mkdir -p db/migrations db/seeds
Hope this helps anyone searching in the future.
Not sure if you ever found your answer, but I fixed this error by manually creating the db/migrations directory in the root. You might have to do the same with db/seeds.
Probably you are running "php vendor/bin/phinx " from inside the migration directory. Try this from root directory. I was getting same error and fixed from root folder.
If you are using CakePHP 3.0 or 4.0 your paths might need updating..
'paths' => [
'migrations' => '%%PHINX_CONFIG_DIR%%/config/Migrations',
'seeds' => '%%PHINX_CONFIG_DIR%%/config/Seeds'
],
Worked for me.

Symfony with MSSQL (sqlsrv) results in timeout

I am trying to connect Symfony 2.8 to Microsoft SQL Server 2012 by using sqlsrv extension (no pdo sqlsrv, because for php7 - which I am using - there is currently only non pdo).
Trying to run cache clear or access the site in browser results in
"PDO::__construct(): MySQL server has gone away".
When I run the doctrine schema update command, everything works fine and the tables are being generated. Does anyone know how to fix the error? (I don't even know why it says Mysql server gone away when I try to connect on microsoft sql..)
Config:
# Doctrine Configuration
doctrine:
dbal:
default_connection: default
connections:
default:
driver: sqlsrv
host: testhost
dbname: testdb
user: testuser
password: testpw
mapping_types:
timestamp: string
I am looking for a solution since Friday but was not able to find one. I tried to select some entries from a seperate (non symfony) php skript, and there I got the results and no timeout. Why is Symfony / Doctrine giving me this strange error?
you can try to launch this command for doctrine :
php app/console doctrine:cache:clear-metadata
php app/console doctrine:cache:clear-query
php app/console doctrine:cache:clear-result
Also perhaps upgrade and downgrade your doctrine bundle for restore a correct and initial version of bundle for your project.

Php - phinx migration

I am using phinx for migrations in my web app.
my phinx.yml:
paths:
migrations: %%PHINX_CONFIG_DIR%%/migrations
environments:
default_migration_table: app_migrations
default_database: app_database
development:
adapter: mysql
host: localhost:8888
name: app_database
user: ''
pass: ''
port:8889
I have mamp with ports apache:8888 and mysql:8889 running.
The database app_database does exist.
The table app_migrations does not exist(it will be created while migrating right?)
I already created some migrations and now i try to run them:
php vendor/bin/phinx migrate -e development
output in console:
Phinx by Rob Morgan - https://phinx.org. version 0.5.1
using config file ./phinx.yml
using config parser yaml
using migration path /path/to/directory/migrations
using environment development
using adapter mysql
using database app_database
Then it stops and nothing happens...
Anybody could help me with this issue?
Thanskj and Greetings!
Maybe there is some config-hickup. I know this phenomenon from conneting to a mysql-database that is not reachable via a specific host / port. This always leads to timeouts but only after eg. 60 seconds.
You wrote this in your config:
host: localhost:8888
[...]
port: 8889
First remove the port from the hostname:
host: localhost
port: 8889
and as second verify the mysql-server is really listening on localhost / port 8889.
You'll find more on in the "Configuration"-chapter of phinx-documentation: http://docs.phinx.org/en/latest/configuration.html
Regards
If you're using the default settings for MAMP, the username for the database would be root. Try changing the value of user in phinx.yml to root.

Categories