Skip to content

Commit

Permalink
Add tests via bats and Github Actions (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
mstrelan authored Sep 8, 2022
1 parent 7600f54 commit 65486c0
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 2 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: tests
on: [push]

defaults:
run:
shell: bash

jobs:
tests:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
drupal_version: ['9.3', '9.4', '9.5', '10.0', '10.1']

steps:
- name: Create project
run: |
composer create-project --ignore-platform-reqs mstrelan/drupal-contrib:dev-${{ github.ref_name }}
- name: Initialise environment
run: |
cd drupal-contrib
make ${{ matrix.drupal_version }}
- name: Setup bats
run: |
brew tap kaos/shell
brew install bats-support bats-assert bats-file
- name: Run tests
env:
DRUPAL_VERSION: ${{ matrix.drupal_version }}
run: |
cd drupal-contrib
bats tests
5 changes: 3 additions & 2 deletions src/ComposerScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ public static function configureEnvironment(Event $event): void {
'UID=1000',
'GID=1000',
], [
sprintf('UID=%d', posix_getuid()),
sprintf('GID=%d', posix_getgid()),
sprintf('UID=%d', posix_geteuid()),
sprintf('GID=%d', posix_getegid()),
], $dist));
$io->write(file_get_contents('.env'));
}

/**
Expand Down
26 changes: 26 additions & 0 deletions tests/composer.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
setup_file() {
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
cd "$DIR/../" || exit
run make composer
}

setup() {
BREW_PREFIX="$(brew --prefix)"
load "${BREW_PREFIX}/lib/bats-assert/load.bash"
load "${BREW_PREFIX}/lib/bats-file/load.bash"
}

dce() {
docker-compose exec -T php-cli "$@"
}

@test "Composer packages are installed" {
run dce composer show --direct -N
assert_output --partial "drupal/core"
}

@test "Composer files are scaffolded" {
assert_file_exist 'app/vendor/autoload.php'
assert_file_exist 'app/sites/default/settings.php'
assert_file_exist 'app/.git/info/exclude'
}
40 changes: 40 additions & 0 deletions tests/drush.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
DRUPAL_VERSION="${DRUPAL_VERSION:-9.4}"

setup() {
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
cd "$DIR/../" || exit
BREW_PREFIX="$(brew --prefix)"
load "${BREW_PREFIX}/lib/bats-assert/load.bash"
}

dce() {
docker-compose exec -T php-cli "$@"
}

drush() {
dce drush "$@"
}

@test "Drupal version is $DRUPAL_VERSION" {
run drush status --fields=drupal-version --format=string
assert_output --partial "$DRUPAL_VERSION."
}

@test "Drupal bootstrap is successful" {
run drush status --fields=bootstrap --format=string
assert_output "Successful"
}

@test "Install minimal profile" {
run make minimal
assert_output --partial "[success] Installation complete."
run drush pm:list --type=profile --field=name
assert_output minimal
}

@test "Install standard profile" {
run make standard
assert_output --partial "[success] Installation complete."
run drush pm:list --type=profile --field=name
assert_output standard
}

0 comments on commit 65486c0

Please sign in to comment.