Skip to content

Commit

Permalink
add: standardized testsuite (#8)
Browse files Browse the repository at this point in the history
* add: standardized testsuite

* stan

* config

* stan

* unit

* stan
  • Loading branch information
mleutenegger authored Jul 21, 2022
1 parent 649f2a6 commit 9cc4b61
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 125 deletions.
110 changes: 20 additions & 90 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ on:
- .htaccess
- '**.md'
branches:
- develop
- master
pull_request:
paths-ignore:
Expand All @@ -24,94 +23,25 @@ on:
- .htaccess
- '**.md'
branches:
- develop
- master
env:
DB: MYSQL
PDO: 1
SS_ENVIRONMENT_TYPE: "dev"
RECIPE_CMS_VERSION: 4.x-dev

jobs:
phpunit:
name: 🧩 PHPUnit
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php:
- 7.3
- 7.4
container: brettt89/silverstripe-web:${{ matrix.php }}-apache
services:
database:
image: mysql:5.7
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
env:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
env:
SS_DEFAULT_ADMIN_USERNAME: admin
SS_DEFAULT_ADMIN_PASSWORD: admin
SS_DATABASE_SERVER: database
SS_DATABASE_NAME: ss_default_${{ matrix.php }}
SS_DATABASE_USERNAME: root
SS_DATABASE_PASSWORD: ''
SS_ENVIRONMENT_TYPE: dev
steps:
- name: Install Composer
run: |
curl \
-sS https://getcomposer.org/installer \
| php && \
mv -f composer.phar /usr/local/bin/composer
- name: Checkout code
uses: actions/checkout@v2
- name: install dependencies
run: |
composer require --no-update silverstripe/recipe-cms:$RECIPE_CMS_VERSION &&\
composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile
- name: run phpunit
run: vendor/bin/phpunit -c "phpunit.xml" tests/
- name: generate coverage
run: phpdbg -qrr vendor/bin/phpunit -dmemory_limit=512M --coverage-clover=coverage.xml tests/
if: ${{ matrix.php == '7.4' }}
- name: submit coverage
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
if: ${{ matrix.php == '7.4' }}
phpstan:
name: 🔺 PHPStan
runs-on: ubuntu-latest
container: brettt89/silverstripe-web:7.4-apache
steps:
- name: Install Composer
run: |
curl \
-sS https://getcomposer.org/installer \
| php && \
mv -f composer.phar /usr/local/bin/composer
- name: Checkout code
uses: actions/checkout@v2
- name: install dependencies
run: |
composer require --no-update silverstripe/recipe-cms:$RECIPE_CMS_VERSION &&\
composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile
- name: run phpstan
run: vendor/bin/phpstan analyse src/ -c "phpstan.neon" -a vendor/symbiote/silverstripe-phpstan/bootstrap.php --level 4
phpcs:
name: 🔮 PHPcs
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: lint source
uses: chindit/actions-phpcs@master
with:
dir: src/
- name: lint tests
uses: chindit/actions-phpcs@master
with:
dir: tests/
silverstripe-module:
name: 🧰 Silverstripe Module Testsuite
uses: syntro-opensource/workflows/.github/workflows/silverstripe-module.yml@master
with:
phpunit: true
phpstan: true
phpcs: true
# silverstripe-client:
# name: 📦 Client Testsuite
# uses: syntro-opensource/workflows/.github/workflows/client.yml@master
# with:
# eslint: true
# eslint_dir: client/src/seo-field/
# eslint_configfile: client/src/seo-field/.eslintrc
# eslint_ext:
# eslint_max-warnings:
# stylelint: true
# stylelint_glob: client/src/seo-field/**/*.scss
# stylelint_max-warnings:
12 changes: 9 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.0",
"symbiote/silverstripe-phpstan": "^4",
"phpstan/phpstan-shim": "~0.11.0",
"phpunit/phpunit": "^5.7"
"syntro/silverstripe-phpstan": "^1",
"phpunit/phpunit": "^9.5"
},
"keywords": [
"silverstripe metadata",
Expand All @@ -39,6 +38,13 @@
"phpunit": "../../bin/phpunit",
"phpunit-flush": "../../bin/phpunit . '' flush=1"
},
"config": {
"allow-plugins": {
"composer/installers": true,
"silverstripe/vendor-plugin": true,
"silverstripe/recipe-plugin": true
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
6 changes: 1 addition & 5 deletions phpstan-dev.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
parameters:
autoload_directories:
- src
- tests/php
includes:
- ../../symbiote/silverstripe-phpstan/phpstan.neon
- ../../syntro/silverstripe-phpstan/phpstan.neon
6 changes: 1 addition & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
parameters:
autoload_directories:
- src
- tests/php
includes:
- vendor/symbiote/silverstripe-phpstan/phpstan.neon
- vendor/syntro/silverstripe-phpstan/phpstan.neon
34 changes: 17 additions & 17 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@

<phpunit
bootstrap="vendor/silverstripe/framework/tests/bootstrap.php"
colors="true"
backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutTodoAnnotatedTests="true"
failOnRisky="true"
failOnWarning="true"
colors="true"
backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutTodoAnnotatedTests="true"
failOnRisky="true"
failOnWarning="true"
>
<testsuite name="Default">
<directory>tests/php</directory>
</testsuite>

<filter>
<blacklist>
<coverage>
<exclude>
<directory suffix=".php">vendor/</directory>
</blacklist>

<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</exclude>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit>
10 changes: 9 additions & 1 deletion src/Dev/TestDataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,22 @@
*/
class SharedObject extends DataObject implements TestOnly
{

/**
* @config
*/
private static $sharing_allow_user_overwrite = true;

/**
* @config
*/
private static $sharing_fallback_description = [
'Description',
'getDefaultDescription'
];

/**
* Database fields
* @config
* @var array
*/
private static $db = [
Expand All @@ -32,6 +39,7 @@ class SharedObject extends DataObject implements TestOnly
/**
* Defines extension names and parameters to be applied
* to this object upon construction.
* @config
* @var array
*/
private static $extensions = [
Expand Down
10 changes: 8 additions & 2 deletions src/Extension/ShareExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class ShareExtension extends DataExtension implements SharingMetaSource

/**
* Database fields
* @config
* @var array
*/
private static $db = [
Expand All @@ -67,6 +68,7 @@ class ShareExtension extends DataExtension implements SharingMetaSource

/**
* Has_one relationship
* @config
* @var array
*/
private static $has_one = [
Expand All @@ -75,6 +77,7 @@ class ShareExtension extends DataExtension implements SharingMetaSource

/**
* Relationship version ownership
* @config
* @var array
*/
private static $owns = [
Expand All @@ -83,6 +86,7 @@ class ShareExtension extends DataExtension implements SharingMetaSource

/**
* Add default values to database
* @config
* @var array
*/
private static $defaults = [
Expand All @@ -92,6 +96,7 @@ class ShareExtension extends DataExtension implements SharingMetaSource

/**
* fields to be translated by fluent
* @config
* @var array
*/
private static $field_include = [
Expand All @@ -101,6 +106,7 @@ class ShareExtension extends DataExtension implements SharingMetaSource

/**
* fields to be ignored by fluent
* @config
* @var array
*/
private static $field_exclude = [
Expand Down Expand Up @@ -323,14 +329,14 @@ public function getFallbackDescription()
if ($fallbackField && is_array($fallbackField)) {
foreach ($fallbackField as $field) {
$string = $this->getDescriptionFromField($field);
if ($string && $string != '') {
if ($string) {
return $string;
}
}
} elseif ($fallbackField) {
// return (string) $owner->obj($fallbackField);
$string = $this->getDescriptionFromField($fallbackField);
if ($string && $string != '') {
if ($string) {
return $string;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/Extension/ShareSiteConfigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ShareSiteConfigExtension extends DataExtension
{
/**
* Database fields
* @config
* @var array
*/
private static $db = [
Expand All @@ -24,6 +25,7 @@ class ShareSiteConfigExtension extends DataExtension

/**
* Has_one relationship
* @config
* @var array
*/
private static $has_one = [
Expand All @@ -32,6 +34,7 @@ class ShareSiteConfigExtension extends DataExtension

/**
* Relationship version ownership
* @config
* @var array
*/
private static $owns = [
Expand All @@ -40,6 +43,7 @@ class ShareSiteConfigExtension extends DataExtension

/**
* fields to be ignored by fluent
* @config
* @var array
*/
private static $field_exclude = [
Expand Down
2 changes: 1 addition & 1 deletion tests/php/ShareMetadataPageExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ShareMetadataPageExtensionTest extends SapphireTest
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
$config = DataObject::get_one(SiteConfig::class);
Expand Down
2 changes: 1 addition & 1 deletion tests/php/ShareSiteConfigExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ShareSiteConfigExtensionTest extends SapphireTest
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
$config = DataObject::get_one(SiteConfig::class);
Expand Down

0 comments on commit 9cc4b61

Please sign in to comment.