Skip to content

Add behat testing support #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions .github/workflows/behat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
on:
pull_request:
workflow_dispatch:
push:
branches:
- master
- develop

name: Behat Test 👨‍🔧

jobs:
Behat-Test:
runs-on: ubuntu-latest
name: Behat Tests - PHP ${{ matrix.php }}
strategy:
fail-fast: false
matrix:
php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
steps:
- name: Check out source code
uses: actions/checkout@v4

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '${{ matrix.php }}'
coverage: none
tools: composer
extensions: pcntl, curl, sqlite3, zip, dom, mbstring, json, xml

- name: Get Composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Set up Composer caching
uses: actions/cache@v4
env:
cache-name: cache-composer-dependencies
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- name: Update docker
run: |
sudo apt remove --purge nginx nginx-common docker docker-engine docker.io docker-ce containerd runc
curl -fsSL https://get.docker.com/ | sudo bash
sudo systemctl restart docker.service

- name: Install docker-compose
run: |
rm -rf /usr/local/bin/docker-compose
VERSION=$(curl --silent "https://api.github.com/repos/docker/compose/releases/latest" |
grep '"tag_name":' |
sed -E 's/.*"([^"]+)".*/\1/'
)
sudo curl -L "https://github.com/docker/compose/releases/download/$VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

- name: Install dependencies
run: |
cd "$GITHUB_WORKSPACE/.."
git clone https://github.com/EasyEngine/easyengine.git easyengine --depth=1
cd easyengine
rm -rf features
cp -R $GITHUB_WORKSPACE/features .
sed -i 's/\(easyengine\/.*\):\ \".*\"/\1:\ \"dev-develop\"/' composer.json
composer update --prefer-dist --no-progress --no-interaction --no-dev
php -dphar.readonly=0 utils/make-phar.php easyengine.phar
sudo cp easyengine.phar /usr/local/bin/ee
composer update --prefer-dist --no-progress --no-interaction --no-plugins

- name: Test
shell: 'script -q -e -c "bash {0}"'
run: |
set -e
cd "$GITHUB_WORKSPACE/../easyengine"
sudo -E ./vendor/bin/behat
env:
COMPOSE_INTERACTIVE_NO_CLI: 1
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@
"config set",
"config get"
]
},
"require-dev": {
"behat/behat": "^3.14"
}
}
61 changes: 61 additions & 0 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;

class FeatureContext implements Context, SnippetAcceptingContext
{
private $command_output;

/**
* @When I run "ee config set test_key test_value"
*/
public function iRunSetTestKeyCommand()
{
$this->command_output = shell_exec('ee config set test_key test_value');
}

/**
* @Then STDOUT should not return anything
*/
public function stdoutShouldNotReturnAnything()
{
if (trim($this->command_output) !== '') {
throw new Exception("Expected no output, but got '$this->command_output'");
}
}

/**
* @When I run "ee config get test_key"
*/
public function iRunGetTestKeyCommand()
{
$this->command_output = shell_exec('ee config get test_key');
}

/**
* @Then STDOUT should return "test_value"
*/
public function stdoutShouldReturnTestValue()
{
if (trim($this->command_output) !== 'test_value') {
throw new Exception("Expected 'test_value', but got '$this->command_output'");
}
}

/**
* @Then the configuration file should contain "test_key: test_value"
*/
public function theConfigurationFileShouldContainTestKeyTestValue()
{
$config_file_path = '/opt/easyengine/config/config.yml';
if (!file_exists($config_file_path)) {
throw new Exception("Configuration file does not exist at $config_file_path");
}

$config_file_content = file_get_contents($config_file_path);
if (strpos($config_file_content, 'test_key: test_value') === false) {
throw new Exception("Configuration file does not contain 'test_key: test_value'");
}
}
}
8 changes: 8 additions & 0 deletions features/config.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Feature: EasyEngine Configuration

Scenario: Install EasyEngine and set/get configuration
When I run "ee config set test_key test_value"
Then STDOUT should not return anything
When I run "ee config get test_key"
Then STDOUT should return "test_value"
Then the configuration file should contain "test_key: test_value"