Skip to content

Commit

Permalink
Merge pull request #1042 from jonocodes/test-env-vars
Browse files Browse the repository at this point in the history
Automate running local tests
  • Loading branch information
jonocodes authored Oct 1, 2024
2 parents c528ea2 + c0751e1 commit a4af806
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
6 changes: 6 additions & 0 deletions tests/phpunit/data/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

CREATE TABLE IF NOT EXISTS hm_user (username varchar(255), hash varchar(255), primary key (username));

CREATE TABLE IF NOT EXISTS hm_user_session (hm_id varchar(255), data longblob, date timestamp, primary key (hm_id));

CREATE TABLE IF NOT EXISTS hm_user_settings(username varchar(255), settings longblob, primary key (username));
6 changes: 6 additions & 0 deletions tests/phpunit/data/seed.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

INSERT OR REPLACE INTO hm_user values('unittestuser', 'sha512:86000:xfEgf7NIUQ2XkeU5tnIcA+HsN8pUllMVdzpJxCSwmbsZAE8Hze3Zs+MeIqepwocYteJ92vhq7pjOfrVThg/p1voELkDdPenU8i2PgG9UTI0IJTGhMN7rsUILgT6XlMAKLp/u2OD13sukUFcQNTdZNFqMsuTVTYw/Me2tAnFwgO4=:rfyUhYsWBCknx6EmbeswN0fy0hAC0N3puXzwWyDRquA=');

INSERT OR REPLACE INTO hm_user values('testuser', '\$argon2id\$v=19\$m=65536,t=2,p=1\$dw4pTU24zRKHCEkLcloU/A\$9NJm6ALQhVpB2HTHmVHjOai912VhURUDAPsut5lrEa0');

INSERT OR REPLACE INTO hm_user_settings values('testuser', 'sFpVPU/hPvmfeiEKUBs4w1EizmbW/Ze2BALZf6kdJrIU3KVZrsqIhKaWTNNFRm3p51ssRAH2mpbxBMhsdpOAqIZMXFHjLttRu9t5WZWOkN7qwEh2LRq6imbkMkfqXg//K294QDLyWjE0Lsc/HSGqnguBF0YUVLVmWmdeqq7/OrXUo4HNbU88i4s2gkukKobJA2hjcOEq/rLOXr3t4LnLlcISnUbt4ptalSbeRrOnx4ehZV8hweQf1E+ID7s/a+8HHx1Qo713JDzReoLEKUsxRQ==');
14 changes: 7 additions & 7 deletions tests/phpunit/mocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,13 @@ public static function stream_socket_enable_crypto($socket, $type) {
}
}
function setup_db($config) {
$config->set('db_connection_type', 'host');
$config->set('db_socket', '/tmp/test.db');
$config->set('db_driver', 'mysql');
$config->set('db_host', '127.0.0.1');
$config->set('db_name', 'cypht_test');
$config->set('db_user', 'cypht_test');
$config->set('db_pass', 'cypht_test');
$config->set('db_connection_type', env('DB_CONNECTION_TYPE', 'host'));
$config->set('db_socket', env('DB_SOCKET', '/tmp/test.db'));
$config->set('db_driver', env('DB_DRIVER', 'mysql'));
$config->set('db_host', env('DB_HOST', '127.0.0.1'));
$config->set('db_name', env('DB_NAME', 'cypht_test'));
$config->set('db_user', env('DB_USER', 'cypht_test'));
$config->set('db_pass', env('DB_PASS', 'cypht_test'));
}
function flatten($str) {
return mb_strtolower(str_replace(array("\n", "\t", "\r", " "), '', $str));
Expand Down
35 changes: 35 additions & 0 deletions tests/phpunit/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

# example run: ./run.sh --filter=Hm_Test_Core_Message_Functions

set -e

SCRIPT_DIR=$(dirname $(realpath "$0"))

DB="${DB:-sqlite}"

echo "SETTING UP DB $DB"

export DB_DRIVER=$DB
export DB_NAME=cypht_test

if [ "$DB" = "sqlite" ]; then

FILE=/tmp/test.db

export DB_CONNECTION_TYPE=socket
export DB_SOCKET=${FILE}

cat ${SCRIPT_DIR}/data/schema.sql | sqlite3 ${FILE}
cat ${SCRIPT_DIR}/data/seed.sql | sqlite3 ${FILE}

# elif [ "$DB" = "mysql" ]; then # TODO

# elif [ "$DB" = "pgsql" ]; then # TODO

else
echo "Database not supported in test: ${DB}"
exit 1
fi

phpunit --configuration ${SCRIPT_DIR}/phpunit.xml $@

0 comments on commit a4af806

Please sign in to comment.