Im using behat for testing in my symfony2 aplication. Right now I need to have two databases. First (which is working right now), for normal use, like user doing something on site. Second database (which exists and behat work on it), for tests purpose.
What I got now is two working databases, and behat. Behat use second database, but problem is that while tests flow, site doesnt use it.
My config.yml:
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
My config_test.yml:
doctrine:
dbal:
dbname: "%database_name%_test"
My 'behat.yml':
default:
suites:
default:
paths:
features: '%paths.base%/features'
bootstrap: '%paths.base%/features/bootstrap'
contexts:
- FeatureContext: ~
- EwidencjaContext:
userManager: '#fos_user.user_manager'
em: '#doctrine.orm.entity_manager'
packageManager: '#em.package_manager'
extensions:
Behat\Symfony2Extension: ~
Behat\MinkExtension:
base_url: http://my_nginx/app_test.php
goutte: ~
selenium2:
browser: "chrome"
wd_host: http://selenium_chrome:4444/wd/hub
capabilities: { "browserName": "chrome", "browser": "chrome"}
Bex\Behat\ScreenshotExtension:
image_drivers:
local:
screenshot_directory: tests/features/images/
clear_screenshot_directory: true
What can I do to change database for time tests are in progress?
This uses SQLite for Behat (test) environment but you can use MySQL if you want to.
config_test.yml
doctrine:
dbal:
connections:
default:
driver: pdo_sqlite
path: %kernel.cache_dir%/default.db
charset: UTF8
app_test.php
The relevant line should be: $kernel = new AppKernel('test', true);
AppKernel.php
The relevant line should be: if (in_array($this->getEnvironment(), ['dev', 'test'])) {
behat.yml
Pay attention to app_test.php.
default:
extensions:
Behat\Symfony2Extension: ~
Behat\MinkExtension:
base_url: http://your_app_domain.dev/app_test.php
...
...
...
Virtual hosts settings:
<VirtualHost *:80>
ServerName your_app_domain.dev
DocumentRoot "/path/to/your/app/web"
<Directory "/path/to/your/app/web">
Options Indexes FollowSymlinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/your_app_domain.dev.error.log
CustomLog ${APACHE_LOG_DIR}/your_app_domain.dev.access.log combined
</VirtualHost>
Some information:
Setting up isolated environments as a symfony application base
Behat blog posts
Outcome:
If you call http://your_app_domain.dev/app_dev.php it will use default DB settings in config but if you call http://your_app_domain.dev/app_test.php then it will use config_test settings.
Related
I'm using mamp the latest php7.4.12 and Apache, i don't understand what is it, i search for this error : "An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432?"
In my .env
DATABASE_URL="mysql://root:#db_docker_symfony:3306/test_docker?serverVersion=5.7"
and doctrine.yaml
dbal:
url: '%env(resolve:DATABASE_URL)%'
# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '13'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
I had the same problem and basically you might have the postgresql uncommented... this port 5432 is related to the postgresql connection, so you just need to comment this line out using "#" ... as you can see below,
#DATABASE_URL="postgresql://db_user:db_password#127.0.0.1:5432/db_name?serverVersion=13&charset=utf8"
leave only you mysql connection uncommented and boom! Happy days hey \o/...
I reackon .env comes with postgresql as a default connection.
Hopefully works for you as well.
Using the rancher GUI, I'm trying to set up Nextcloud with MySQL database workloads on my AKS cluster. In the environment variables, I already have defined the admin user and password so why do I get this error on the create admin page?
Error while trying to create admin user: Failed to connect to the
database: An exception occurred in driver: SQLSTATE[HY000] [2054] The
server requested authentication method unknown to the client
I entered the Username and password correctly multiple times.
Below are my configurations for the database and nextcloud so far.
database workload:
Name: nextdb
Docker image: mysql
port: not set
I have the following variables:
MYSQL_ROOT_PASSWORD=rootpassX
MYSQL_DATABASE=nextDB
MYSQL_USER=nextcloud
MYSQL_PASSWORD=passX
volumes configuration:
Volume Type: Bind-Mount
Volume Name: nextdb
Path on the Node : /nextdb
The Path on the Node must be: a directory or create
Mount Point: /var/lib/mysql
nextcloud workload:
Name: nextcloud
Docker Image: nextcloud
Port Mapping:
Port Name : nextcloud80
Publish the container port: 80
Protocol: TCP
As a: Layer-4 load balancer
On listening port: 80
Environment variables:
MYSQL_DATABASE=nextDB
MYSQL_USER=nextcloud
MYSQL_PASSWORD=passX
MYSQL_HOST=nextdb
NEXTCLOUD_ADMIN_USER=admin
NEXTCLOUD_ADMIN_PASSWORD=adminPass
NEXTCLOUD_DATA_DIR=/var/www/html/nextcloud
Volumes:
Volume 1:
name: nextcloud
Volume Type: Bind-Mount
Path on the Node: /nextcloud
The Path on the Node must be: a directory or create.
Mount Point: /var/www/html
Volume 2
name: nextdb
Volume Type: Bind-Mount
Path on the Node: /nextdatabase
The Path on the Node must be: a directory or create.
Mount Point: /var/lib/mysql
What are the problems with my configurations?
Starting with version 8.02, MySQL updated the default authentication method for client connections. To revert to the older authentication method you need to explicitly specify the default authentication method.
If you are able to update your DB service in Rancher to pass the container argument --default-authentication-plugin=mysql_native_password that should revert MySQL to the older auth method.
Alternatively, depending on the MySQL image you are using, you can create a new Docker image from that base which replaces /etc/mysql/my.cnf inside the container. You should inspect /etc/mysql/my.cnf before you replace it, if there are any !includedir directives in the config file, you can place your supplemental configuration into an included folder using whatever filename you choose.
The supplemental configuration should look like this:
[mysqld]
default_authentication_plugin=mysql_native_password
i had this error when i want to create a new database with wamp server.how can i solve
$ app/console doctrine:database:create Could not create database
"symfony" for connection named default An exception occured in driver:
SQLSTATE[HY000] [14] unable to open database file
parameters.yml:
database_driver: pdo_sqlite
database_host: 127.0.0.1
database_port: null
database_name: symfony
database_user: root
database_password: null
database_path: '%kernel.root_dir%/data/blog.sqlite'
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
locale: en
secret: secret_value_for_symfony_demo_application
parameters.yml.dist:
# This file defines the canonical configuration parameters of the application.
# Symfony uses this file as a template to generate the real app/config/parameters.yml
# used by the application.
# See
http://symfony.com/doc/current/best_practices/configuration.html#canonical-parameters
parameters:
# this demo application uses an embedded SQLite database to simplify setup.
# in a real Symfony application you probably will use a MySQL or PostgreSQL database
database_driver: pdo_sqlite
database_host: 127.0.0.1
database_port: ~
database_name: symfony
database_user: root
database_password: ~
# the 'database_path' is only used for SQLite type databases
database_path: %kernel.root_dir%/data/blog.sqlite
# Uncomment these lines to use a MySQL database instead of SQLite:
#
# database_driver: pdo_mysql
# database_host: 127.0.0.1
# database_port: null
# database_name: symfony_demo
# database_user: root
# database_password: null
#
# You can even create the database and load the sample data from the command line:
#
# $ cd your-symfony-project/
# $ php app/console doctrine:database:create
# $ php app/console doctrine:schema:create
# $ php app/console doctrine:fixtures:load
# If you don't use a real mail server, you can send emails via your Gmail account.
# see http://symfony.com/doc/current/cookbook/email/gmail.html
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: ~
mailer_password: ~
# The code of the default language used by the application ('en' = English)
locale: en
# The 'secret' value is a random string of characters, numbers and symbols
# used internally by Symfony in several places (CSRF tokens, URI signing,
# 'Remember Me' functionality, etc.)
# see: http://symfony.com/doc/current/reference/configuration/framework.html#secret
secret: 'secret_value_for_symfony_demo_application'
One reason why this message occurs, is when the user can't create a file in the %kernel.root_dir%/data/ folder. Check if you can create a file inside this folder.
i had this in config.yml #Markus
doctrine:
dbal:
# instead of configuring the database access options in this file, we pull
# them from the app/config/parameters.yml file. The reason is that config.yml
# stores options that change the application behavior and parameters.yml
# stores options that change from one server to another
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver, add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
I am trying to run our company product source code on a local host. I have tried placing
config.action_mailer.default_url_options = { host: "localhost:3000" }
in all development.rb, test.rb and production.rb.
But when I run
rake db:seed
I still keep getting
ActionView::Template::Error: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true.
I am adding my config/database.yml file as suggested in the edit
config/database.yml
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password: ******
socket: /var/run/mysqld/mysqld.sock
development:
<<: *default
database: company_development
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: coompany_test
# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
# DATABASE_URL="mysql2://myuser:mypass#localhost/somedatabase"
#
# You can use this database configuration with:
#
# production:
# url: <%= ENV['DATABASE_URL'] %>
#
production:
<<: *default
database: company_production
username: company
password: <%= ****** %>
Any help would be much appreciated. Thank You.
I guess you are trying to populate the development environment with seed, if that was the case then try this
rake db:seed RAILS_ENV=development
I got it. I forgot to answer it sorry. The solution might vary for this particular error for everyone. But for me I had to do the following changes in the following files.
In application.yml I added
SMTP_HOST: 'localhost:3000'
And in development.rb I added
config.action_mailer.raise_delivery_errors = false
Seeding done.
My deployment is running fine until the migration .. which fails
rake aborted!
DEBUG [874287b0] ActiveRecord::AdapterNotSpecified: database configuration does not specify adapter
DEBUG [874287b0] /home/kadoudal/rails/swim-tech.eu/site/swimtech/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.3/lib/active_record/connection_adapters/connection_specification.rb:52:in `resolve_hash_connection'
I run : cap staging deploy:check:linked_files, whic is successful , database.yml is symlinked correctly and contains :
# encoding: utf-8
defaults: &defaults
adapter: mysql2
host: localhost
timeout: 60000
encoding: utf8
production:
<<: *defaults
database: mydb_production
username: xxxxxxxxxxx
password: xxxxxxxxxxxxxx
why the Adapter is not found ?
forgot I was running a cap staging.... and there is no staging db in the database.yml
I created a staging server by cloning the production server on Rackspace. In this scenario, I want the staging server to still use the 'production' rails environment and the production db (on the staging server), so I set this in the config/deploy/staging.rb file:
set :stage, :production
and it works great.