Skip to content

Commit

Permalink
Removed Docker from the dev stack.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Nov 4, 2024
1 parent 5038495 commit 615d1b8
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 152 deletions.
82 changes: 42 additions & 40 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,59 +20,61 @@ jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
php-versions: ['8.2', '8.3']

services:
chrome:
image: selenium/standalone-chromium:130.0
ports:
- 4444:4444

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}

- name: Set up Docker Compose
run: docker compose up -d --build
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: pcov
ini-values: pcov.directory=.

- name: Copy codebase into container
run: |
container_id="$(docker compose ps -q phpserver)"
docker cp -L . "${container_id}":/app/
- name: Install dependencies
run: composer install

- name: Install Composer dependencies
run: docker compose exec phpserver composer install --ansi --no-suggest
- name: Validate composer.json
run: |
composer --verbose validate
composer normalize --dry-run
- name: Lint code
run: docker compose exec phpserver composer lint
- name: Check coding standards
run: composer lint
continue-on-error: ${{ vars.CI_LINT_IGNORE_FAILURE == '1' }}

- name: Restart server with Xdebug enabled
run: XDEBUG_ENABLE=true docker compose up -d phpserver

- name: Run tests with PHPUnit
run: docker compose exec -T -e XDEBUG_MODE=coverage phpserver vendor/bin/phpunit
continue-on-error: ${{ vars.CI_TEST_IGNORE_FAILURE == '1' }}
- name: Run unit tests
run: composer test-unit
continue-on-error: ${{ vars.CI_TEST_UNIT_IGNORE_FAILURE == '1' }}

- name: Run tests with Behat
run: docker compose exec -T -e XDEBUG_MODE=coverage phpserver vendor/bin/behat
continue-on-error: ${{ vars.CI_TEST_IGNORE_FAILURE == '1' }}

- name: Process test logs and artifacts
run: |
mkdir -p /tmp/logs
if docker compose ps --services --filter "status=running" | grep -q phpserver && docker compose exec phpserver test -d /app/.logs; then
docker compose cp phpserver:/app/.logs/. "/tmp/logs/"
fi
- name: Upload artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: artifacts
path: /tmp/logs
- name: Run BDD tests
run: composer test-bdd
continue-on-error: ${{ vars.CI_TEST_BDD_IGNORE_FAILURE == '1' }}
env:
BEHAT_JAVASCRIPT_BASE_URL: http://172.17.0.1:8888

- name: Upload logs as artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: logs
path: /tmp/logs
name: ${{github.job}}-logs-${{ matrix.php-versions }}
path: .logs
include-hidden-files: true
if-no-files-found: error

Expand All @@ -81,8 +83,8 @@ jobs:
if: ${{ env.CODECOV_TOKEN != '' }}
with:
files: |
/tmp/logs/coverage/behat/cobertura.xml
/tmp/logs/coverage/phpunit/cobertura.xml
.logs/coverage/behat/cobertura.xml
.logs/coverage/phpunit/cobertura.xml
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
env:
Expand All @@ -91,4 +93,4 @@ jobs:
- name: Setup tmate session
if: ${{ !cancelled() && github.event.inputs.enable_terminal }}
uses: mxschmitt/action-tmate@v3
timeout-minutes: 5
timeout-minutes: 15
26 changes: 11 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,39 +128,35 @@ You may optionally specify size of browser window in the screenshot step:

### Local development setup

```bash
docker compose up -d
docker compose exec phpserver composer install --ansi
```

### Lint code
### Install dependencies.

```bash
docker compose exec phpserver composer lint
composer install
```

### Lint fix
### Start Chrome container.

```bash
docker compose exec phpserver composer lint-fix
docker run -d -p 4444:4444 selenium/standalone-chromium:130.0
```

### Run tests
### Lint code

```bash
docker compose exec phpserver composer test
composer lint
```

### Enable Xdebug
### Fix code style

```bash
XDEBUG_ENABLE=true docker compose up -d phpserver
composer lint-fix
```

To disable, run
### Run tests

```bash
docker compose up -d phpserver
composer test-unit # Run unit tests.
composer test-bdd # Run BDD tests.
```

---
Expand Down
37 changes: 19 additions & 18 deletions behat.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
default:
autoload: [ "%paths.base%/tests/behat/bootstrap" ]
autoload: ["%paths.base%/tests/behat/bootstrap"]
suites:
default:
paths: [ "%paths.base%/tests/behat/features" ]
paths: ["%paths.base%/tests/behat/features"]
contexts:
- FeatureContext:
- screenshot_dir: '%paths.base%/.logs/screenshots'
- BehatCliContext
- DrevOps\BehatPhpServer\PhpServerContext:
-
docroot: "%paths.base%/tests/behat/features/fixtures"
host: "phpserver"
- DrevOps\BehatScreenshotExtension\Context\ScreenshotContext
- FeatureContext:
-
screenshot_dir: '%paths.base%/.logs/screenshots'

formatters:
pretty: true
# Disable JUnit formatter if memory leaks start to occur.
# See @https://github.com/Behat/Behat/pull/1423
junit:
output_path: '%paths.base%/.logs/test_results/behat'
- DrevOps\BehatPhpServer\PhpServerContext:
- docroot: "%paths.base%/tests/behat/features/fixtures"
host: "0.0.0.0"
port: 8888

extensions:
Behat\MinkExtension:
browserkit_http: ~
files_path: "%paths.base%/tests/behat/features/fixtures"
base_url: http://0.0.0.0:8888
browser_name: chrome
base_url: http://phpserver:8888
javascript_session: selenium2
selenium2:
wd_host: "http://chrome:4444/wd/hub"
wd_host: "http://localhost:4444/wd/hub"
capabilities:
browser: chrome
extra_capabilities:
Expand All @@ -43,10 +35,12 @@ default:
- '--disable-translate' # Disables the built-in translation feature, preventing Chrome from offering to translate pages.
- '--no-first-run' # Skips the initial setup screen that Chrome typically shows when running for the first time.
- '--test-type' # Disables certain security features and UI components that are unnecessary for automated testing, making Chrome more suitable for test environments.

DrevOps\BehatScreenshotExtension:
dir: '%paths.base%/.logs/screenshots'
fail: true
purge: true

DVDoug\Behat\CodeCoverage\Extension:
filter:
include:
Expand All @@ -60,3 +54,10 @@ default:
target: .logs/coverage/behat/.coverage-html
cobertura:
target: .logs/coverage/behat/cobertura.xml

formatters:
pretty: true
# Disable JUnit formatter if memory leaks start to occur.
# See @https://github.com/Behat/Behat/pull/1423
junit:
output_path: '%paths.base%/.logs/test_results/behat'
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@
"rector --clear-cache",
"phpcbf"
],
"test": [
"if [ \"${XDEBUG_MODE}\" = 'coverage' ]; then phpunit; else phpunit --no-coverage; fi",
"behat"
]
"reset": "rm -Rf vendor vendor-bin composer.lock",
"test-bdd": "behat --colors",
"test-unit": "phpunit"
}
}
10 changes: 0 additions & 10 deletions docker-compose.yml

This file was deleted.

22 changes: 15 additions & 7 deletions src/DrevOps/BehatScreenshotExtension/Context/ScreenshotContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*/
class ScreenshotContext extends RawMinkContext implements ScreenshotAwareContextInterface {

/**
* Screenshot step line.
*/
Expand Down Expand Up @@ -87,13 +88,13 @@ public function beforeScenarioInit(BeforeScenarioScope $scope): void {
}
catch (\Exception $exception) {
throw new \RuntimeException(
sprintf(
'Please make sure that Selenium server is running. %s',
$exception->getMessage(),
),
$exception->getCode(),
$exception,
);
sprintf(
'Please make sure that Selenium server is running. %s',
$exception->getMessage(),
),
$exception->getCode(),
$exception,
);
}
}
}
Expand Down Expand Up @@ -299,6 +300,13 @@ protected function makeFileName(string $ext, ?string $filename = NULL, bool $fai
$url = NULL;
}

if (!empty($url) && !empty(getenv('BEHAT_SCREENSHOT_TOKEN_HOST'))) {
$host = parse_url($url, PHP_URL_HOST);
if ($host) {
$url = str_replace($host, getenv('BEHAT_SCREENSHOT_TOKEN_HOST'), $url);
}
}

$data = [
'ext' => $ext,
'step_name' => $step->getText(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,36 @@ public function initialize(ExtensionManager $extensionManager): void {
* {@inheritdoc}
*/
public function configure(ArrayNodeDefinition $builder): void {
$definitionChildren = $builder->children();
// @phpcs:disable Drupal.WhiteSpace.ObjectOperatorIndent.Indent
// @formatter:off
// @phpstan-ignore-next-line
$definitionChildren
->scalarNode('dir')->cannotBeEmpty()->defaultValue('%paths.base%/screenshots')->end()
->scalarNode('fail')->cannotBeEmpty()->defaultValue(TRUE)->end()
->scalarNode('fail_prefix')->cannotBeEmpty()->defaultValue('failed_')->end()
->scalarNode('purge')->cannotBeEmpty()->defaultValue(FALSE)->end()
$builder->children()
->scalarNode('dir')
->cannotBeEmpty()
->defaultValue('%paths.base%/screenshots')
->end()
->scalarNode('fail')
->cannotBeEmpty()
->defaultValue(TRUE)
->end()
->scalarNode('fail_prefix')
->cannotBeEmpty()
->defaultValue('failed_')
->end()
->scalarNode('purge')
->cannotBeEmpty()
->defaultValue(FALSE)
->end()
->scalarNode('filenamePattern')
->cannotBeEmpty()
->defaultValue('{datetime:U}.{feature_file}.feature_{step_line}.{ext}')->end()
->cannotBeEmpty()
->defaultValue('{datetime:U}.{feature_file}.feature_{step_line}.{ext}')
->end()
->scalarNode('filenamePatternFailed')
->cannotBeEmpty()
->defaultValue('{datetime:U}.{fail_prefix}{feature_file}.feature_{step_line}.{ext}')->end();
->cannotBeEmpty()
->defaultValue('{datetime:U}.{fail_prefix}{feature_file}.feature_{step_line}.{ext}')
->end();
// @formatter:on
// @phpcs:enable Drupal.WhiteSpace.ObjectOperatorIndent.Indent
}

/**
Expand Down
Loading

0 comments on commit 615d1b8

Please sign in to comment.