Skip to content

Commit

Permalink
Author-names(#81): unit tests setup
Browse files Browse the repository at this point in the history
Installed php-pecl-xcebug in vagrant chef recipe as it is needed by phpunit to calculate test coverage.
Set up the creation of a test database in gigadb chef recipe, so that unit tests can run without disrupting manual and automated user testing by wiping out the development database.
Created a db_test.json config for the test database.
Moidified Yii test config to use the test database.
Run the test coverage for the gigadb-website codebase and generate a comprehensive html report.
  • Loading branch information
Rija Menage committed Jan 15, 2018
1 parent 7244c51 commit de22995
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ nbproject/project.properties

# MacOSX
.DS_Store

# Test
protected/tests/reports/*
24 changes: 24 additions & 0 deletions chef/site-cookbooks/gigadb/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,30 @@
export PGPASSWORD='#{password}'; psql -U #{db_user} -h localhost gigadb < #{sql_script}
EOH
end

# creating the test database to run the unit tests
test_user = "test"
postgresql_user test_user do
password "test"
end

postgresql_database "gigadb_test" do
owner test_user
end

bash 'restore test database' do
db_user = "test"
password = "test"
sql_script = db[:sql_script]

code <<-EOH
# Might need to drop database first or foreign key constraints stop database restoration
export PGPASSWORD='#{password}'; psql -U #{db_user} -h localhost gigadb_test < "/vagrant/sql/gigadb_tables.sql"
EOH
end



end


Expand Down
2 changes: 1 addition & 1 deletion chef/site-cookbooks/vagrant/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

include_recipe "gigadb"

['vim', 'tree'].each do |pkg|
['vim', 'tree', 'php-pecl-xdebug'].each do |pkg|
package pkg
end

Expand Down
6 changes: 6 additions & 0 deletions protected/config/db_test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"database": "gigadb_test",
"host" : "localhost",
"user" : "test",
"password": "test"
}
9 changes: 6 additions & 3 deletions protected/config/test.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

// load database config
$dbConfig = json_decode(file_get_contents(dirname(__FILE__).'/db_test.json'), true);

// enable multibyte unicode aware string functions. Only needed for PHP < 5.6. Requires php-mbstring module.
ini_set('mbstring.internal_encoding','UTF-8');

Expand All @@ -10,11 +13,11 @@
'fixture'=>array(
'class'=>'system.test.CDbFixtureManager',
),
/* uncomment the following to provide test database connection
// uncomment the following to provide test database connection
'db'=>array(
'connectionString'=>'DSN for test database',
'connectionString'=>"pgsql:dbname={$dbConfig['database']};host={$dbConfig['host']}",
),
*/

),
)
);

0 comments on commit de22995

Please sign in to comment.