From 0d4b925239b0c03ef4e4ea26286d159428486e9c Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Wed, 29 May 2019 17:11:51 +0200 Subject: [PATCH 01/27] initial circle ci config --- .circleci/config.yml | 59 ++++++++++++++++++++++++++++++++++++++++++++ .travis.yml | 7 +++--- 2 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..47015b6 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,59 @@ +version: 2 + +jobs: + backend: + docker: + - image: circleci/php:7-apache + environment: + ag44jc7aqs2rsup2bb6cx7utc: localhost + hp7wz20wu4qfbfcmqywfai1j4: tempfiles + mom8c5hrbn8c1r5lro1imfyax: thisisonlyusedfortestinganyways + qb1yi60nrz3tjjjqqb7l2yqra: tempfiles + rb421p9wniz81ttj7bdgrg0ub: tempfiles + - image: circleci/mariadb:10-bionic-ram + environment: + MYSQL_DATABASE: tempfiles + MYSQL_USER: tempfiles + MYSQL_PASSWORD: thisisonlyusedfortestinganyways + steps: + - checkout + + - restore_cache: + key: composer-cache-{{ checksum "backend/composer.lock" }} + + - run: + name: Composer install + command: "cd server && composer install" + + - save_cache: + paths: + - backend/vendor + key: composer-cache-{{ checksum "backend/composer.lock" }} + + - run: + name: Install MySQL Client + command: apt update && apt install mysql-client + + - run: + name: Waiting for Mariadb to be ready + command: | + for i in `seq 1 10`; + do + nc -z localhost 3306 && echo Success && exit 0 + echo -n . + sleep 1 + done + echo Failed waiting for Mariadb && exit 1 + + - run: + name: Create database table + command: mysql -u $hp7wz20wu4qfbfcmqywfai1j4 -p $qb1yi60nrz3tjjjqqb7l2yqra < resources/install_mysql.sql + + + - run: + name: "Run PHP Unit Tests" + command: "cd backend && ./vendor/phpunit/phpunit/phpunit" + + - run: + name: "Tests with db" + command: "exit 0" diff --git a/.travis.yml b/.travis.yml index 8381541..236b66d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,8 @@ matrix: include: - language: php php: - - 7.2 - - 7.3 + - "7.2" + - "7.3" before_install: - cd backend install: @@ -20,7 +20,8 @@ matrix: - 2.4.1 cache: bundler: true - directories: $TRAVIS_BUILD_DIR/tmp/.htmlproofer + directories: + - $TRAVIS_BUILD_DIR/tmp/.htmlproofer before_install: - cd frontend script: From ea70fdc4afab2e24fa951ac46120c489538ea4ef Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Wed, 29 May 2019 17:14:13 +0200 Subject: [PATCH 02/27] added workflow --- .circleci/config.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 47015b6..7340132 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -57,3 +57,9 @@ jobs: - run: name: "Tests with db" command: "exit 0" + +workflows: + version: 2 + test: + jobs: + - backend From d810dbd489fc783c1f80654b713b763f2903ce72 Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Wed, 29 May 2019 17:16:05 +0200 Subject: [PATCH 03/27] change server to backend --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7340132..86786cd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -23,7 +23,7 @@ jobs: - run: name: Composer install - command: "cd server && composer install" + command: "cd backend && composer install" - save_cache: paths: From c0d31c632cd739b1ea74b0fa6459795b06b4282e Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Wed, 29 May 2019 17:18:20 +0200 Subject: [PATCH 04/27] use sudo for when installing with apt --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 86786cd..1d8abad 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -32,7 +32,7 @@ jobs: - run: name: Install MySQL Client - command: apt update && apt install mysql-client + command: sudo apt update && sudo apt install mysql-client - run: name: Waiting for Mariadb to be ready From ead2da32c5bebfd06e944f596b2a57dcd4090351 Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Wed, 29 May 2019 17:23:44 +0200 Subject: [PATCH 05/27] change image to php:7 and fix mysql connect syntax --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1d8abad..551fad1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ version: 2 jobs: backend: docker: - - image: circleci/php:7-apache + - image: circleci/php:7 environment: ag44jc7aqs2rsup2bb6cx7utc: localhost hp7wz20wu4qfbfcmqywfai1j4: tempfiles @@ -47,7 +47,7 @@ jobs: - run: name: Create database table - command: mysql -u $hp7wz20wu4qfbfcmqywfai1j4 -p $qb1yi60nrz3tjjjqqb7l2yqra < resources/install_mysql.sql + command: mysql -u$hp7wz20wu4qfbfcmqywfai1j4 -p$mom8c5hrbn8c1r5lro1imfyax < resources/install_mysql.sql - run: From 2bd5ab73074b649a6fc7095a6faa2142a59e0296 Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Wed, 29 May 2019 17:26:42 +0200 Subject: [PATCH 06/27] specify host and port --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 551fad1..860f173 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -47,7 +47,7 @@ jobs: - run: name: Create database table - command: mysql -u$hp7wz20wu4qfbfcmqywfai1j4 -p$mom8c5hrbn8c1r5lro1imfyax < resources/install_mysql.sql + command: mysql --host=localhost --user=$hp7wz20wu4qfbfcmqywfai1j4 --password=$mom8c5hrbn8c1r5lro1imfyax < resources/install_mysql.sql - run: From 7093907f69498b9928abc57846ea11164c9c4938 Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Wed, 29 May 2019 17:26:50 +0200 Subject: [PATCH 07/27] specify host and port --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 860f173..6817d1a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -47,7 +47,7 @@ jobs: - run: name: Create database table - command: mysql --host=localhost --user=$hp7wz20wu4qfbfcmqywfai1j4 --password=$mom8c5hrbn8c1r5lro1imfyax < resources/install_mysql.sql + command: mysql --host=localhost --port=3306 --user=$hp7wz20wu4qfbfcmqywfai1j4 --password=$mom8c5hrbn8c1r5lro1imfyax < resources/install_mysql.sql - run: From 2f2c3a63a6c56fa3ec758764fc7201dfa3e9c575 Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Wed, 29 May 2019 17:34:17 +0200 Subject: [PATCH 08/27] specify protocol --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6817d1a..1ff329c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -47,7 +47,7 @@ jobs: - run: name: Create database table - command: mysql --host=localhost --port=3306 --user=$hp7wz20wu4qfbfcmqywfai1j4 --password=$mom8c5hrbn8c1r5lro1imfyax < resources/install_mysql.sql + command: mysql --protocol=tcp --host=localhost --port=3306 --user=$hp7wz20wu4qfbfcmqywfai1j4 --password=$mom8c5hrbn8c1r5lro1imfyax < resources/install_mysql.sql - run: From 4891cb6e881436a71353d40c4ead5ae2e8603c67 Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Wed, 29 May 2019 17:37:25 +0200 Subject: [PATCH 09/27] rebuild? --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1ff329c..477856a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -56,7 +56,7 @@ jobs: - run: name: "Tests with db" - command: "exit 0" + command: "echo hello && exit 0" workflows: version: 2 From 18fc46588987ca7b6e243351d82af2eca839dc6c Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Wed, 29 May 2019 17:44:01 +0200 Subject: [PATCH 10/27] reformat --- backend/src/com/carlgo11/tempfiles/config.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/src/com/carlgo11/tempfiles/config.php b/backend/src/com/carlgo11/tempfiles/config.php index 4dafc07..fbc12f1 100644 --- a/backend/src/com/carlgo11/tempfiles/config.php +++ b/backend/src/com/carlgo11/tempfiles/config.php @@ -9,15 +9,15 @@ return array( # Allowed formats MB, GB, TB, PB. 'max-file-size' => '12MB', - #'mysql-url' => 'localhost', + # 'mysql-url' => 'localhost', 'mysql-url' => getenv('ag44jc7aqs2rsup2bb6cx7utc'), - #'mysql-user => 'tempfiles', + # 'mysql-user' => 'tempfiles', 'mysql-user' => getenv('hp7wz20wu4qfbfcmqywfai1j4'), - #'mysql-password' => 'password', + # 'mysql-password' => 'password', 'mysql-password' => getenv('mom8c5hrbn8c1r5lro1imfyax'), - #'mysql-db' => 'tempfiles', + # 'mysql-db' => 'tempfiles', 'mysql-db' => getenv('qb1yi60nrz3tjjjqqb7l2yqra'), - #'mysql-table' => 'files', + # 'mysql-table' => 'files', 'mysql-table' => getenv('rb421p9wniz81ttj7bdgrg0ub'), # Encryption algorithm to use for encrypting uploads. 'Encryption-Method' => 'aes-256-gcm' From a06870e90d570f8b06a1104b9df98d0de2493fc2 Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Wed, 29 May 2019 17:44:59 +0200 Subject: [PATCH 11/27] install php-mysql, describe env vars --- .circleci/config.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 477856a..0f0a018 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,11 +5,11 @@ jobs: docker: - image: circleci/php:7 environment: - ag44jc7aqs2rsup2bb6cx7utc: localhost - hp7wz20wu4qfbfcmqywfai1j4: tempfiles - mom8c5hrbn8c1r5lro1imfyax: thisisonlyusedfortestinganyways - qb1yi60nrz3tjjjqqb7l2yqra: tempfiles - rb421p9wniz81ttj7bdgrg0ub: tempfiles + ag44jc7aqs2rsup2bb6cx7utc: localhost # 'mysql-url' + hp7wz20wu4qfbfcmqywfai1j4: tempfiles # 'mysql-user' + mom8c5hrbn8c1r5lro1imfyax: thisisonlyusedfortestinganyways # 'mysql-password' + qb1yi60nrz3tjjjqqb7l2yqra: tempfiles # 'mysql-db' + rb421p9wniz81ttj7bdgrg0ub: tempfiles # 'mysql-table' - image: circleci/mariadb:10-bionic-ram environment: MYSQL_DATABASE: tempfiles @@ -32,7 +32,7 @@ jobs: - run: name: Install MySQL Client - command: sudo apt update && sudo apt install mysql-client + command: sudo apt update && sudo apt install mysql-client php-mysql - run: name: Waiting for Mariadb to be ready @@ -46,7 +46,7 @@ jobs: echo Failed waiting for Mariadb && exit 1 - run: - name: Create database table + name: Create database & table command: mysql --protocol=tcp --host=localhost --port=3306 --user=$hp7wz20wu4qfbfcmqywfai1j4 --password=$mom8c5hrbn8c1r5lro1imfyax < resources/install_mysql.sql From 643c45efc81b2a4cd82cd10536d0ec39f7f069be Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Wed, 29 May 2019 18:56:33 +0200 Subject: [PATCH 12/27] specify php version --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0f0a018..caca733 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ version: 2 jobs: backend: docker: - - image: circleci/php:7 + - image: circleci/php:7.2 environment: ag44jc7aqs2rsup2bb6cx7utc: localhost # 'mysql-url' hp7wz20wu4qfbfcmqywfai1j4: tempfiles # 'mysql-user' @@ -32,7 +32,7 @@ jobs: - run: name: Install MySQL Client - command: sudo apt update && sudo apt install mysql-client php-mysql + command: sudo apt update && sudo apt install mysql-client php7.2-mysql - run: name: Waiting for Mariadb to be ready From a5afa6abf1cab11ac1841e3c5eb301787c1686e6 Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Wed, 29 May 2019 18:57:54 +0200 Subject: [PATCH 13/27] specify php version --- .circleci/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index caca733..de4c234 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ version: 2 jobs: backend: docker: - - image: circleci/php:7.2 + - image: circleci/php:7 environment: ag44jc7aqs2rsup2bb6cx7utc: localhost # 'mysql-url' hp7wz20wu4qfbfcmqywfai1j4: tempfiles # 'mysql-user' @@ -31,8 +31,8 @@ jobs: key: composer-cache-{{ checksum "backend/composer.lock" }} - run: - name: Install MySQL Client - command: sudo apt update && sudo apt install mysql-client php7.2-mysql + name: Install MySQL Client & php7-mysql + command: sudo apt update && sudo apt install mysql-client php7-mysql - run: name: Waiting for Mariadb to be ready From 9a0bd6953d0f85376777ed63a1745596c72acbc2 Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Wed, 29 May 2019 20:28:19 +0200 Subject: [PATCH 14/27] db test test --- .circleci/config.yml | 14 ++++++++---- .../src/com/carlgo11/tempfiles/Autoload.php | 10 +++++---- .../com/carlgo11/tempfiles/DataStorage.php | 22 +++++++++++++++++++ .../carlgo11/tempfiles/DataStorageTest.php | 15 +++++++++++++ 4 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 backend/tests/com/carlgo11/tempfiles/DataStorageTest.php diff --git a/.circleci/config.yml b/.circleci/config.yml index de4c234..8bedf96 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,9 +3,9 @@ version: 2 jobs: backend: docker: - - image: circleci/php:7 + - image: circleci/php:7.2-apache-stretch environment: - ag44jc7aqs2rsup2bb6cx7utc: localhost # 'mysql-url' + ag44jc7aqs2rsup2bb6cx7utc: '127.0.0.1' # 'mysql-url' hp7wz20wu4qfbfcmqywfai1j4: tempfiles # 'mysql-user' mom8c5hrbn8c1r5lro1imfyax: thisisonlyusedfortestinganyways # 'mysql-password' qb1yi60nrz3tjjjqqb7l2yqra: tempfiles # 'mysql-db' @@ -31,8 +31,14 @@ jobs: key: composer-cache-{{ checksum "backend/composer.lock" }} - run: - name: Install MySQL Client & php7-mysql - command: sudo apt update && sudo apt install mysql-client php7-mysql + name: Install PHP extensions + command: sudo docker-php-ext-install -j$(nproc) mysqli + + - run: + name: Install MySQL Client + command: | + sudo apt update + sudo apt install -y mysql-client - run: name: Waiting for Mariadb to be ready diff --git a/backend/src/com/carlgo11/tempfiles/Autoload.php b/backend/src/com/carlgo11/tempfiles/Autoload.php index 0ce6bb0..922d547 100644 --- a/backend/src/com/carlgo11/tempfiles/Autoload.php +++ b/backend/src/com/carlgo11/tempfiles/Autoload.php @@ -10,9 +10,10 @@ checkFile(__DIR__ . '/API.php'); // Load MySQL connection unless the script is run by PHPUnit. -if (!isset($_ENV['phpunit'])) - $mysql_connection = mysqli_connect($conf['mysql-url'], $conf['mysql-user'], $conf['mysql-password'], $conf['mysql-db']) - or mySQLError($mysql_connection); +// if (!isset($_ENV['phpunit'])) +$mysql_connection = mysqli_connect($conf['mysql-url'], $conf['mysql-user'], $conf['mysql-password'], $conf['mysql-db']) +// $mysql_connection = mysqli_connect('127.0.0.1', $conf['mysql-user'], $conf['mysql-password'], $conf['mysql-db']) +or mySQLError($mysql_connection); /** @@ -23,7 +24,8 @@ function mySQLError($mysql_connection) { error_log('MySQL connection failed: ' . htmlspecialchars($mysql_connection->error)); http_response_code(500); - die("Connection to our database failed."); + die('Connection to our database failed.'); + throw new Exeption('Connection to our database failed.'); } /** diff --git a/backend/src/com/carlgo11/tempfiles/DataStorage.php b/backend/src/com/carlgo11/tempfiles/DataStorage.php index 0072b1d..754890f 100644 --- a/backend/src/com/carlgo11/tempfiles/DataStorage.php +++ b/backend/src/com/carlgo11/tempfiles/DataStorage.php @@ -174,4 +174,26 @@ public static function uploadFile(File $file, string $password) { } } + public static function getMariaDBVersion() { + global $mysql_connection; + + try { + + $query = $mysql_connection->prepare('SELECT VERSION()'); + + $query->execute(); + $query->store_result(); + $query->bind_result($version); + $query->fetch(); + $query->close(); + + return $version; + + } catch (Exception $e) { + error_log($e); + return FALSE; + } + + } + } diff --git a/backend/tests/com/carlgo11/tempfiles/DataStorageTest.php b/backend/tests/com/carlgo11/tempfiles/DataStorageTest.php new file mode 100644 index 0000000..3487c03 --- /dev/null +++ b/backend/tests/com/carlgo11/tempfiles/DataStorageTest.php @@ -0,0 +1,15 @@ +assertIsString(DataStorage::getMariaDBVersion()); + } + +} From 053e16e29968d2fbb1bd9e96afdccd0a0836b051 Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Wed, 29 May 2019 20:30:37 +0200 Subject: [PATCH 15/27] change use path --- backend/tests/com/carlgo11/tempfiles/DataStorageTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/tests/com/carlgo11/tempfiles/DataStorageTest.php b/backend/tests/com/carlgo11/tempfiles/DataStorageTest.php index 3487c03..9de0387 100644 --- a/backend/tests/com/carlgo11/tempfiles/DataStorageTest.php +++ b/backend/tests/com/carlgo11/tempfiles/DataStorageTest.php @@ -2,7 +2,7 @@ namespace com\carlgo11\tempfiles; -use com\carlgo11\tempfiles\api\DataStorage; +use com\carlgo11\tempfiles; use PHPUnit\Framework\TestCase; class DataStorageTest extends TestCase From c3f234ca467163fd04f5a412cfb1528a2b49ea6b Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Wed, 29 May 2019 20:32:57 +0200 Subject: [PATCH 16/27] log for testing --- backend/tests/com/carlgo11/tempfiles/DataStorageTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/tests/com/carlgo11/tempfiles/DataStorageTest.php b/backend/tests/com/carlgo11/tempfiles/DataStorageTest.php index 9de0387..852ec1a 100644 --- a/backend/tests/com/carlgo11/tempfiles/DataStorageTest.php +++ b/backend/tests/com/carlgo11/tempfiles/DataStorageTest.php @@ -9,7 +9,9 @@ class DataStorageTest extends TestCase { public function testGetMariaDBVersion() { - $this->assertIsString(DataStorage::getMariaDBVersion()); + $v = DataStorage::getMariaDBVersion(); + error_log($v); + $this->assertIsString($v); } } From 67821dbe836ef80dacb4fa253483fa3d4f13e3cb Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Wed, 29 May 2019 20:34:38 +0200 Subject: [PATCH 17/27] remove error_log --- backend/tests/com/carlgo11/tempfiles/DataStorageTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/backend/tests/com/carlgo11/tempfiles/DataStorageTest.php b/backend/tests/com/carlgo11/tempfiles/DataStorageTest.php index 852ec1a..9de0387 100644 --- a/backend/tests/com/carlgo11/tempfiles/DataStorageTest.php +++ b/backend/tests/com/carlgo11/tempfiles/DataStorageTest.php @@ -9,9 +9,7 @@ class DataStorageTest extends TestCase { public function testGetMariaDBVersion() { - $v = DataStorage::getMariaDBVersion(); - error_log($v); - $this->assertIsString($v); + $this->assertIsString(DataStorage::getMariaDBVersion()); } } From 1fb1a5416fb74d9a95577578c90021a8d2084baa Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Wed, 29 May 2019 20:37:49 +0200 Subject: [PATCH 18/27] removed unnecessary test step --- .circleci/config.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8bedf96..d44855f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -60,10 +60,6 @@ jobs: name: "Run PHP Unit Tests" command: "cd backend && ./vendor/phpunit/phpunit/phpunit" - - run: - name: "Tests with db" - command: "echo hello && exit 0" - workflows: version: 2 test: From 843c4f216119f633954a930e964b97e5aa37c47f Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Wed, 29 May 2019 20:42:57 +0200 Subject: [PATCH 19/27] don't include apache --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d44855f..4842218 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ version: 2 jobs: backend: docker: - - image: circleci/php:7.2-apache-stretch + - image: circleci/php:7.2-stretch environment: ag44jc7aqs2rsup2bb6cx7utc: '127.0.0.1' # 'mysql-url' hp7wz20wu4qfbfcmqywfai1j4: tempfiles # 'mysql-user' From 941fca9d47cada714f48b088a9c88b77c6776532 Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Wed, 29 May 2019 20:43:07 +0200 Subject: [PATCH 20/27] added comments --- backend/src/com/carlgo11/tempfiles/DataStorage.php | 1 + backend/tests/com/carlgo11/tempfiles/DataStorageTest.php | 1 + 2 files changed, 2 insertions(+) diff --git a/backend/src/com/carlgo11/tempfiles/DataStorage.php b/backend/src/com/carlgo11/tempfiles/DataStorage.php index 754890f..1dc7fc2 100644 --- a/backend/src/com/carlgo11/tempfiles/DataStorage.php +++ b/backend/src/com/carlgo11/tempfiles/DataStorage.php @@ -174,6 +174,7 @@ public static function uploadFile(File $file, string $password) { } } + // TODO: Remove. Just an example. public static function getMariaDBVersion() { global $mysql_connection; diff --git a/backend/tests/com/carlgo11/tempfiles/DataStorageTest.php b/backend/tests/com/carlgo11/tempfiles/DataStorageTest.php index 9de0387..6724811 100644 --- a/backend/tests/com/carlgo11/tempfiles/DataStorageTest.php +++ b/backend/tests/com/carlgo11/tempfiles/DataStorageTest.php @@ -8,6 +8,7 @@ class DataStorageTest extends TestCase { + // TODO: Remove. Just an example. public function testGetMariaDBVersion() { $this->assertIsString(DataStorage::getMariaDBVersion()); } From 4d7f7440aeff583dfbda5b7998bef78f9f9c87e3 Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Wed, 29 May 2019 21:04:14 +0200 Subject: [PATCH 21/27] added front end build --- .circleci/config.yml | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4842218..f2a7dc7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -60,8 +60,49 @@ jobs: name: "Run PHP Unit Tests" command: "cd backend && ./vendor/phpunit/phpunit/phpunit" + frontend: + docker: + - image: circleci/ruby:2 + steps: + - checkout + + - restore_cache: + keys: + - gem-cache-{{ checksum "frontend/Gemfile.lock" }} + + - run: + name: Bundle install + command: cd frontend && bundle install --path vendor/bundle + + - save_cache: + paths: + - frontend/vendor/bundle + key: gem-cache-{{ checksum "frontend/Gemfile.lock" }} + + - run: + name: Build frontend + command: bundle exec rake proof build + + # deploy: + # machine: + # enabled: true + # steps: + # - run: + # name: Trigger Webhook + # command: # curl? + + + workflows: version: 2 test: jobs: - backend + - frontend + # - deploy: + # requires: + # - backend + # - frontend + # filters: + # branches: + # only: master From efb3bfe375d27db41dfe84a99750f0090e2d6df6 Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Wed, 29 May 2019 21:05:15 +0200 Subject: [PATCH 22/27] fix syntax --- .circleci/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f2a7dc7..1f32137 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -75,9 +75,9 @@ jobs: command: cd frontend && bundle install --path vendor/bundle - save_cache: - paths: - - frontend/vendor/bundle - key: gem-cache-{{ checksum "frontend/Gemfile.lock" }} + paths: + - frontend/vendor/bundle + key: gem-cache-{{ checksum "frontend/Gemfile.lock" }} - run: name: Build frontend From 163648e5d006e62ead3289fcaa2f974bf2377b09 Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Wed, 29 May 2019 21:09:14 +0200 Subject: [PATCH 23/27] cd to frontend --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1f32137..7b356b8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -81,7 +81,7 @@ jobs: - run: name: Build frontend - command: bundle exec rake proof build + command: cd frontend && bundle exec rake proof build # deploy: # machine: From a25d7deae4850b8f930a793122737614478854dd Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Wed, 29 May 2019 21:13:20 +0200 Subject: [PATCH 24/27] removed comments --- backend/src/com/carlgo11/tempfiles/Autoload.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/backend/src/com/carlgo11/tempfiles/Autoload.php b/backend/src/com/carlgo11/tempfiles/Autoload.php index 922d547..6c92f62 100644 --- a/backend/src/com/carlgo11/tempfiles/Autoload.php +++ b/backend/src/com/carlgo11/tempfiles/Autoload.php @@ -10,9 +10,7 @@ checkFile(__DIR__ . '/API.php'); // Load MySQL connection unless the script is run by PHPUnit. -// if (!isset($_ENV['phpunit'])) $mysql_connection = mysqli_connect($conf['mysql-url'], $conf['mysql-user'], $conf['mysql-password'], $conf['mysql-db']) -// $mysql_connection = mysqli_connect('127.0.0.1', $conf['mysql-user'], $conf['mysql-password'], $conf['mysql-db']) or mySQLError($mysql_connection); From c33475d8efd79c55d9b58bd32c0303dd9fa6660d Mon Sep 17 00:00:00 2001 From: Edwin Date: Wed, 29 May 2019 21:24:20 +0200 Subject: [PATCH 25/27] Update backend/src/com/carlgo11/tempfiles/Autoload.php --- backend/src/com/carlgo11/tempfiles/Autoload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/com/carlgo11/tempfiles/Autoload.php b/backend/src/com/carlgo11/tempfiles/Autoload.php index 6c92f62..48741f8 100644 --- a/backend/src/com/carlgo11/tempfiles/Autoload.php +++ b/backend/src/com/carlgo11/tempfiles/Autoload.php @@ -9,7 +9,7 @@ checkFile(__DIR__ . '/File.php'); checkFile(__DIR__ . '/API.php'); -// Load MySQL connection unless the script is run by PHPUnit. +// Connect to the database $mysql_connection = mysqli_connect($conf['mysql-url'], $conf['mysql-user'], $conf['mysql-password'], $conf['mysql-db']) or mySQLError($mysql_connection); From d2c66384845a0c0c8a5d2f71acc090e1dece7b4d Mon Sep 17 00:00:00 2001 From: Carlgo11 Date: Thu, 6 Jun 2019 18:55:10 +0200 Subject: [PATCH 26/27] Allow for non MySQL phpunit tests --- .circleci/config.yml | 3 +-- backend/composer.json | 3 +++ backend/phpunit.xml | 3 --- backend/src/com/carlgo11/tempfiles/Autoload.php | 8 +++----- backend/src/com/carlgo11/tempfiles/config.php | 5 ++--- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7b356b8..fc80d11 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -55,10 +55,9 @@ jobs: name: Create database & table command: mysql --protocol=tcp --host=localhost --port=3306 --user=$hp7wz20wu4qfbfcmqywfai1j4 --password=$mom8c5hrbn8c1r5lro1imfyax < resources/install_mysql.sql - - run: name: "Run PHP Unit Tests" - command: "cd backend && ./vendor/phpunit/phpunit/phpunit" + command: "./backend/vendor/phpunit/phpunit/phpunit --configuration ./backend/phpunit.xml --teamcity" frontend: docker: diff --git a/backend/composer.json b/backend/composer.json index 70372cf..7ae5d22 100644 --- a/backend/composer.json +++ b/backend/composer.json @@ -2,5 +2,8 @@ "require-dev": { "phpunit/phpunit": "^8.1", "phpunit/php-code-coverage": "^7.0" + }, + "require": { + "ext-mysqli": "*" } } diff --git a/backend/phpunit.xml b/backend/phpunit.xml index a98efdc..dafe449 100644 --- a/backend/phpunit.xml +++ b/backend/phpunit.xml @@ -4,9 +4,6 @@ tests - - - src diff --git a/backend/src/com/carlgo11/tempfiles/Autoload.php b/backend/src/com/carlgo11/tempfiles/Autoload.php index 48741f8..e205290 100644 --- a/backend/src/com/carlgo11/tempfiles/Autoload.php +++ b/backend/src/com/carlgo11/tempfiles/Autoload.php @@ -1,7 +1,6 @@ MB, GB, TB, PB. 'max-file-size' => '12MB', # 'mysql-url' => 'localhost', @@ -21,4 +20,4 @@ 'mysql-table' => getenv('rb421p9wniz81ttj7bdgrg0ub'), # Encryption algorithm to use for encrypting uploads. 'Encryption-Method' => 'aes-256-gcm' -); +]; From 98bdcbb0b96360473a8fd9a16161a58789e00a16 Mon Sep 17 00:00:00 2001 From: Carlgo11 Date: Thu, 6 Jun 2019 19:09:54 +0200 Subject: [PATCH 27/27] Make PHPUnit non MySQL the default config --- .circleci/config.yml | 2 +- .circleci/phpunit.xml | 12 ++++++++++++ backend/phpunit.xml | 6 +++++- 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 .circleci/phpunit.xml diff --git a/.circleci/config.yml b/.circleci/config.yml index fc80d11..0fc42c6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -57,7 +57,7 @@ jobs: - run: name: "Run PHP Unit Tests" - command: "./backend/vendor/phpunit/phpunit/phpunit --configuration ./backend/phpunit.xml --teamcity" + command: "./backend/vendor/phpunit/phpunit/phpunit --configuration ./circleci/phpunit.xml --teamcity" frontend: docker: diff --git a/.circleci/phpunit.xml b/.circleci/phpunit.xml new file mode 100644 index 0000000..276b776 --- /dev/null +++ b/.circleci/phpunit.xml @@ -0,0 +1,12 @@ + + + + ./backend/tests + + + + + ./backend/src + + + \ No newline at end of file diff --git a/backend/phpunit.xml b/backend/phpunit.xml index dafe449..508dd84 100644 --- a/backend/phpunit.xml +++ b/backend/phpunit.xml @@ -1,9 +1,13 @@ - + tests + tests/com/carlgo11/tempfiles/DataStorageTest.php + + + src