diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..0fc42c6 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,107 @@ +version: 2 + +jobs: + backend: + docker: + - image: circleci/php:7.2-stretch + environment: + ag44jc7aqs2rsup2bb6cx7utc: '127.0.0.1' # '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 + MYSQL_USER: tempfiles + MYSQL_PASSWORD: thisisonlyusedfortestinganyways + steps: + - checkout + + - restore_cache: + key: composer-cache-{{ checksum "backend/composer.lock" }} + + - run: + name: Composer install + command: "cd backend && composer install" + + - save_cache: + paths: + - backend/vendor + key: composer-cache-{{ checksum "backend/composer.lock" }} + + - run: + 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 + 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 --protocol=tcp --host=localhost --port=3306 --user=$hp7wz20wu4qfbfcmqywfai1j4 --password=$mom8c5hrbn8c1r5lro1imfyax < resources/install_mysql.sql + + - run: + name: "Run PHP Unit Tests" + command: "./backend/vendor/phpunit/phpunit/phpunit --configuration ./circleci/phpunit.xml --teamcity" + + 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: cd frontend && 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 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/.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: 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..508dd84 100644 --- a/backend/phpunit.xml +++ b/backend/phpunit.xml @@ -1,11 +1,12 @@ - + tests + tests/com/carlgo11/tempfiles/DataStorageTest.php - + diff --git a/backend/src/com/carlgo11/tempfiles/Autoload.php b/backend/src/com/carlgo11/tempfiles/Autoload.php index 0ce6bb0..e205290 100644 --- a/backend/src/com/carlgo11/tempfiles/Autoload.php +++ b/backend/src/com/carlgo11/tempfiles/Autoload.php @@ -1,7 +1,6 @@ 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..1dc7fc2 100644 --- a/backend/src/com/carlgo11/tempfiles/DataStorage.php +++ b/backend/src/com/carlgo11/tempfiles/DataStorage.php @@ -174,4 +174,27 @@ public static function uploadFile(File $file, string $password) { } } + // TODO: Remove. Just an example. + 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/src/com/carlgo11/tempfiles/config.php b/backend/src/com/carlgo11/tempfiles/config.php index 4dafc07..f153803 100644 --- a/backend/src/com/carlgo11/tempfiles/config.php +++ b/backend/src/com/carlgo11/tempfiles/config.php @@ -5,20 +5,19 @@ * If you'd prefer to just store the credentials in this document then, * replace my variables definitions with the ones I've commented. */ - -return array( +return [ # 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' -); +]; diff --git a/backend/tests/com/carlgo11/tempfiles/DataStorageTest.php b/backend/tests/com/carlgo11/tempfiles/DataStorageTest.php new file mode 100644 index 0000000..6724811 --- /dev/null +++ b/backend/tests/com/carlgo11/tempfiles/DataStorageTest.php @@ -0,0 +1,16 @@ +assertIsString(DataStorage::getMariaDBVersion()); + } + +}