From 5c04045b6db99626791fb0a4e5faadaf634041ea Mon Sep 17 00:00:00 2001 From: Immanuel Raj Date: Fri, 31 May 2024 11:36:04 +0000 Subject: [PATCH 1/4] composet: Add behat dev dependency Signed-off-by: Immanuel Raj --- composer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/composer.json b/composer.json index 9a10379..ec70319 100644 --- a/composer.json +++ b/composer.json @@ -23,5 +23,8 @@ "config set", "config get" ] + }, + "require-dev": { + "behat/behat": "^3.14" } } From 44cd01bade894e320271fb6afd924b1e13658845 Mon Sep 17 00:00:00 2001 From: Immanuel Raj Date: Mon, 3 Jun 2024 09:03:47 +0000 Subject: [PATCH 2/4] Add Behat Testing Signed-off-by: Immanuel Raj --- features/bootstrap/FeatureContext.php | 75 +++++++++++++++++++++++++++ features/config.feature | 9 ++++ 2 files changed, 84 insertions(+) create mode 100644 features/bootstrap/FeatureContext.php create mode 100644 features/config.feature diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php new file mode 100644 index 0000000..e64bc04 --- /dev/null +++ b/features/bootstrap/FeatureContext.php @@ -0,0 +1,75 @@ +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'"); + } + } +} \ No newline at end of file diff --git a/features/config.feature b/features/config.feature new file mode 100644 index 0000000..ee762f3 --- /dev/null +++ b/features/config.feature @@ -0,0 +1,9 @@ +Feature: EasyEngine Configuration + + Scenario: Install EasyEngine and set/get configuration + Given I have installed EasyEngine if not install it + 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" \ No newline at end of file From 0fe47e607f6d6c9581ce166520f81bcb63075400 Mon Sep 17 00:00:00 2001 From: Immanuel Raj Date: Thu, 6 Jun 2024 15:54:55 +0530 Subject: [PATCH 3/4] Add action for behat testing Signed-off-by: Immanuel Raj --- .github/workflows/behat.yml | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/behat.yml diff --git a/.github/workflows/behat.yml b/.github/workflows/behat.yml new file mode 100644 index 0000000..f42b1f0 --- /dev/null +++ b/.github/workflows/behat.yml @@ -0,0 +1,37 @@ +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: Install dependencies + run: | + composer install --prefer-dist --no-progress --no-interaction + + - name: Test + run: | + sudo -E ./vendor/bin/behat \ No newline at end of file From 86ef5c7dfe5792e2cff5398cb031cba72ce7507b Mon Sep 17 00:00:00 2001 From: Immanuel Raj Date: Mon, 10 Jun 2024 18:42:03 +0530 Subject: [PATCH 4/4] Behat: Install EasyEngine by default - Let's not do it in the behat test - Install Latest ee (Develop Branch) and test changes against it. - Use latest docker and docker compose - Use composer chache in github actions - Remove unnecessary packages Signed-off-by: Immanuel Raj --- .github/workflows/behat.yml | 47 +++++++++++++++++++++++++-- features/bootstrap/FeatureContext.php | 14 -------- features/config.feature | 1 - 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/.github/workflows/behat.yml b/.github/workflows/behat.yml index f42b1f0..e8ead4c 100644 --- a/.github/workflows/behat.yml +++ b/.github/workflows/behat.yml @@ -28,10 +28,53 @@ jobs: 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: | - composer install --prefer-dist --no-progress --no-interaction + 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: | - sudo -E ./vendor/bin/behat \ No newline at end of file + set -e + cd "$GITHUB_WORKSPACE/../easyengine" + sudo -E ./vendor/bin/behat + env: + COMPOSE_INTERACTIVE_NO_CLI: 1 \ No newline at end of file diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index e64bc04..b3f83ea 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -7,20 +7,6 @@ class FeatureContext implements Context, SnippetAcceptingContext { private $command_output; - /** - * @Given I have installed EasyEngine if not install it - */ - public function iHaveInstalledEasyengineIfNotInstallIt() - { - if (!file_exists('/usr/local/bin/ee')) { - $install_command = 'wget -qO ee https://rt.cx/ee4 && sudo bash ee && sudo rm ee'; - $install_output = shell_exec($install_command); - if (!file_exists('/usr/local/bin/ee')) { - throw new Exception("EasyEngine could not be installed."); - } - } - } - /** * @When I run "ee config set test_key test_value" */ diff --git a/features/config.feature b/features/config.feature index ee762f3..5b7a686 100644 --- a/features/config.feature +++ b/features/config.feature @@ -1,7 +1,6 @@ Feature: EasyEngine Configuration Scenario: Install EasyEngine and set/get configuration - Given I have installed EasyEngine if not install it When I run "ee config set test_key test_value" Then STDOUT should not return anything When I run "ee config get test_key"