diff --git a/.github/workflows/behat.yml b/.github/workflows/behat.yml new file mode 100644 index 0000000..e8ead4c --- /dev/null +++ b/.github/workflows/behat.yml @@ -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 \ No newline at end of file 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" } } diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php new file mode 100644 index 0000000..b3f83ea --- /dev/null +++ b/features/bootstrap/FeatureContext.php @@ -0,0 +1,61 @@ +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..5b7a686 --- /dev/null +++ b/features/config.feature @@ -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" \ No newline at end of file