diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml new file mode 100644 index 00000000..5481a007 --- /dev/null +++ b/.github/workflows/phpunit.yml @@ -0,0 +1,11 @@ +name: phpunit + +on: [push] + +jobs: + phpunit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: php-actions/composer@v6 + - uses: php-actions/phpunit@v3 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..fee724eb --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,48 @@ +# intentionally malformed files +# pre-commit automatically excludes submodules +exclude: | + (?x)^( + .*\.dist| + roles/ood-head/files/auto-copy/var/www/ood/apps/common/common_attributes.yml| + roles/ood-head/files/auto-copy/var/www/ood/apps/sys/dashboard/config/locales/en.yml| + inventory.d/ipv4.py| + files/shibboleth/filtered-incommon-metadata.xml.j2| + )$ + +repos: + # auto formatters (no work required) ############################################################# + # - repo: https://github.com/pre-commit/pre-commit-hooks + # rev: v5.0.0 + # hooks: + # - id: trailing-whitespace + # - id: end-of-file-fixer + - repo: local + hooks: + - id: phpcbf + name: PHP Code Beautifier and Fixer + entry: phpcbf + language: system + files: \.php$ + args: [--standard=PSR2, --colors] + + # linters (work required) ######################################################################## + # - repo: https://github.com/pre-commit/pre-commit-hooks + # rev: v5.0.0 + # hooks: + # - id: check-yaml + # - id: check-json + # - id: check-xml + # - id: check-added-large-files + # - id: check-executables-have-shebangs + # - repo: https://github.com/gitleaks/gitleaks + # rev: v8.23.1 + # hooks: + # - id: gitleaks + - repo: local + hooks: + - id: phpcs + name: PHP CodeSniffer + entry: phpcs + language: system + files: \.php$ + args: [--standard=PSR2, --colors] diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 00000000..b3ac75ad --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,13 @@ + + + + test/unit + + + diff --git a/resources/init.php b/resources/init.php index 00858ceb..c1f8fd79 100644 --- a/resources/init.php +++ b/resources/init.php @@ -4,16 +4,14 @@ * init.php - Initialization script that is run on every page of Unity */ -use UnityWebPortal\lib\{ - UnityConfig, - UnityLDAP, - UnityMailer, - UnitySQL, - UnitySSO, - UnityUser, - UnityRedis, - UnityWebhook -}; +use UnityWebPortal\lib\UnityConfig; +use UnityWebPortal\lib\UnityLDAP; +use UnityWebPortal\lib\UnityMailer; +use UnityWebPortal\lib\UnitySQL; +use UnityWebPortal\lib\UnitySSO; +use UnityWebPortal\lib\UnityUser; +use UnityWebPortal\lib\UnityRedis; +use UnityWebPortal\lib\UnityWebhook; // // Initialize Session diff --git a/test/unit/UnitySiteTest.php b/test/unit/UnitySiteTest.php new file mode 100644 index 00000000..8eb06480 --- /dev/null +++ b/test/unit/UnitySiteTest.php @@ -0,0 +1,32 @@ +assertEquals($expected, $SITE->testValidSSHKey($key)); + } +} diff --git a/test/unit/bootstrap.php b/test/unit/bootstrap.php new file mode 100644 index 00000000..92837256 --- /dev/null +++ b/test/unit/bootstrap.php @@ -0,0 +1,15 @@ +