Skip to content

Commit

Permalink
Merge pull request #43 from wunderio/feature/testing-refactor
Browse files Browse the repository at this point in the history
Dev env refactor
  • Loading branch information
ragnarkurmwunder authored Apr 24, 2023
2 parents 434bf5c + 072b0d7 commit e35989b
Show file tree
Hide file tree
Showing 16 changed files with 151 additions and 153 deletions.
16 changes: 9 additions & 7 deletions .lando.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: ping
recipe: drupal9

services:
appserver:
type: php:7.4
webroot: drupal9/web
build_as_root:
- /app/.lando/build_as_root
build:
Expand All @@ -12,8 +11,6 @@ services:
- /app/.lando/run_as_root
run:
- /app/.lando/run
mariadb:
type: mariadb:10.6
memcached:
type: memcached:1.5.12
redis:
Expand All @@ -37,10 +34,15 @@ services:
# solr
# varnish

config:
php: "8.1"
via: nginx
webroot: drupal/web
database: "mariadb:10.6"
composer_version: 2
xdebug: off

tooling:
install:
service: appserver
cmd: /app/.lando/cmd-install
test:
service: appserver
cmd: /app/.lando/cmd-test
Expand Down
22 changes: 13 additions & 9 deletions .lando/build
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
# must be different between branches
# it allows easy branch switching
# without need for rebuild
drupal_root=drupal9
proj="/app/$drupal_root"
web="$proj/web"
sites="$web/sites"
app="/app"
proj="$app/drupal"
webroot="$proj/web"
sites="$webroot/sites"
default="$sites/default"
pingroot="$app/drupal-ping"

set +e
rm -rf "$proj"
Expand All @@ -20,14 +21,17 @@ set -e

# NB! When Composer breaks:
# https://www.drupal.org/project/drupal/issues/3255749
cd /app
composer create-project drupal/recommended-project "$drupal_root"
cd "$app"
composer create-project drupal/recommended-project "$proj"

chmod 755 "$default"
rm -f "$default/settings.php"
ln -s /app/settings.php "$default/"
ln -s /app/_ping.custom.php "$web/"
ln -s /app/_ping.php "$web/"
ln -s "$pingroot/settings.php" "$default/"
ln -s "$pingroot/_ping.custom.php" "$webroot/"
ln -s "$pingroot/_ping.php" "$webroot/"
chmod 644 "$pingroot/settings.php"

cd "$proj"
composer require --dev drush/drush
composer require 'wunderio/code-quality:^2' --dev
composer require 'phpunit/phpunit:^9' --dev
23 changes: 0 additions & 23 deletions .lando/cmd-install

This file was deleted.

12 changes: 6 additions & 6 deletions .lando/cmd-scan
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/bin/bash

set -euo pipefail
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/app/vendor/bin
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/app/drupal/vendor/bin

cd /app
# Due to autoloader issues need to run the scan on linked _ping.php in drupal webroot.
cd /app/drupal/web

set -x

php -l _ping.php
php -l settings.php
phpcs -sp --report=full --runtime-set testVersion 7.4 --standard=Drupal,DrupalPractice,Security,PHPCompatibility,VariableAnalysis,WunderDrupal,WunderSecurity _ping.php settings.php
phpstan analyze --level=5 --autoload-file scan-autoload.php -- _ping.php settings.php
psalm
phpcs -sp --report=full --runtime-set testVersion 7.4 --standard=Drupal,DrupalPractice,Security,PHPCompatibility,VariableAnalysis,WunderDrupal,WunderSecurity _ping.php
phpstan analyze --level=5 -- _ping.php
psalm --config=/app/drupal-ping/psalm.xml
7 changes: 4 additions & 3 deletions .lando/cmd-test
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/bin/bash

set -euo pipefail
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/app/drupal/vendor/bin

cd /app
cd /app/drupal

set -x
php -d memory_limit=-1 /app/vendor/bin/phpunit

php -d memory_limit=-1 /app/drupal/vendor/bin/phpunit /app/drupal-ping/tests
9 changes: 2 additions & 7 deletions .lando/run
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@
set -xeuo pipefail
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin

# must be different between branches
# it allows easy branch switching
# without need for rebuild
drupal_root=drupal9

export PATH="$PATH:/app/$drupal_root/vendor/bin"
export PATH="$PATH:/app/drupal/vendor/bin"

# cannot do this during the build
# because db is not available at the build time.
cd "/app/$drupal_root"
cd "/app/drupal"

set +e
drush status bootstrap | grep -q Successful
Expand Down
38 changes: 32 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ composer require wunderio/drupal-ping:^2

## Changelog

### v2.5.2

- Remove testfile existence checking. It was fixed with keeping `mtime` in the filename.
- README: Refactor development and testing documentation
- Update tests
- Refactor testing environment

### v2.5.1

- Instead of using `mtime` for file checks, store the timestamp into filename. It is a workaround for the NFS `mtime` issue.
Expand Down Expand Up @@ -164,19 +171,38 @@ If earlier fails (is empty), then next one is tried.

## Ping Development & Testing

- `lando install` - Install dev dependencies without Drupal
- `lando start` - Install basic Drupal and services
### Setting up development environment

1. Clone development and testing environment
* `git clone git@github.com:wunderio/drupal-project.git ~/projects/drupal-ping`
* Yes, save it as `drupal-ping`.
1. `cd drupal-ping/`
1. Clone the ping project itself
* `git clone git@github.com:wunderio/drupal-ping.git`
* Yes, save it as `drupal-ping` too, inside the folder of the same name. It is the actual repo we are going to work with.
* Checkout or create your development branch.
1. Link `.lando.yml`
* `rm -f .lando.yml` - at the top-level folder, remove the Lando conf file.
* `ln drupal-ping/.lando.yml` - link the Lando conf from the ping repo folder. Don't create this as a soft (`-s`) link because Lando would mount the project where the original file is. Therefore create the hard link which is indistinguishable for Lando.
1. Link `.lando/`
* `rm -rf .lando` - at the top-level folder, remove the Lando folder.
* `ln -s drupal-ping/.lando` - link the Lando scripts folder from the ping repo folder.
1. `lando start`
1. Note that the Drupal install will mess up `settings.php` a bit, don't commit.
1. https://ping.lndo.site/_ping.php
1. `lando scan`
1. `lando test`

### Development commands

- `lando test` - Execute phpunit tests
- `lando scan` - Run coding standard checks

Note: the Lando setup is defined so that D7 and D89 branched can be easily switched
both running their own own setup. Drupal and composer installations wont clash.
They have separate dirs.

## Maintainers

- [Janne Koponen](https://github.com/tharna)
- [Ragnar Kurm](https://github.com/ragnarkurmwunder)
- [Juhani Moilanen](https://github.com/Juhani-moilanen)

## License

Expand Down
29 changes: 0 additions & 29 deletions _ping.php
Original file line number Diff line number Diff line change
Expand Up @@ -1076,35 +1076,6 @@ protected function check2(): void {
return;
}
$this->file = $tmp;

// The following is for NFS file creation "weirdness".
//
// We try to give NFS some time for file creation.
// Sometimes the file appears after a delay.
// If ping is running in multiple containers accessing the same filesystem
// the usleep has to be quite small
// Otherwise parallel pings could steal eachothers files
// due to invalid mtime.
$check_time = 1.0;
for ($time = microtime(TRUE); microtime(TRUE) - $time < $check_time && !file_exists($tmp); usleep(10000)) {
}

// Enforces file creation.
// On NFS-based systems file creation is sometimes delayed.
// This seems to speed up things.
if (!touch($tmp)) {
$this->setStatus('warning', 'Could not touch file.', [
'file' => $tmp,
]);
return;
}

if (!file_exists($tmp)) {
$this->setStatus('warning', "File did not appear during $check_time sec nor after touch().", [
'file' => $tmp,
]);
return;
}
}

}
Expand Down
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
"email": "ragnar.kurm@wunder.io",
"homepage": "https://github.com/ragnarkurmwunder",
"role": "Developer"
},
{
"name": "Juhani Moilanen",
"email": "juhani.moilanen@wunder.io",
"homepage": "https://github.com/Juhani-moilanen",
"role": "Developer"
}
],
"keywords": [
Expand All @@ -27,10 +33,6 @@
"drupal/core": "^8 || ^9 || ^10",
"koodimonni/composer-dropin-installer": ">=1.0.1"
},
"require-dev": {
"wunderio/code-quality": "^2",
"phpunit/phpunit": "^9"
},
"config": {
"allow-plugins": {
"koodimonni/composer-dropin-installer": true,
Expand Down
2 changes: 0 additions & 2 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
autoloader="scan-autoload.php"
>
<projectFiles>
<file name="_ping.php" />
<file name="settings.php" />
</projectFiles>
</psalm>
28 changes: 0 additions & 28 deletions scan-autoload.php

This file was deleted.

2 changes: 1 addition & 1 deletion settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}

// DB.
$db = json_decode(getenv('LANDO_INFO'))->mariadb;
$db = json_decode(getenv('LANDO_INFO'))->database;
$databases['default']['default'] = [
'database' => $db->creds->database,
'username' => $db->creds->user,
Expand Down
2 changes: 2 additions & 0 deletions tests/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ protected function setUp(): void {
putenv($key);
}
}
putenv("PING_TOKEN");
unset($_GET['debug']);
}

/**
Expand Down
Loading

0 comments on commit e35989b

Please sign in to comment.