Skip to content

Commit

Permalink
feat: split tests into functional and arch
Browse files Browse the repository at this point in the history
  • Loading branch information
lotyp committed Jun 11, 2024
1 parent d895b08 commit daa9cb5
Show file tree
Hide file tree
Showing 18 changed files with 178 additions and 96 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,70 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true

arch-testing:
timeout-minutes: 4
runs-on: ${{ matrix.os }}
concurrency:
cancel-in-progress: true
group: arch-testing-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ matrix.php-version }}-${{ matrix.dependencies }}
strategy:
fail-fast: true
matrix:
os:
- ubuntu-latest
php-version:
- '8.3'
dependencies:
- locked
steps:
- name: 📦 Check out the codebase
uses: actions/[email protected]

- name: 🛠️ Setup PHP
uses: shivammathur/[email protected]
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, pdo, pdo_sqlite
ini-values: error_reporting=E_ALL
coverage: xdebug

- name: 🛠️ Setup problem matchers
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"

- name: 🤖 Validate composer.json and composer.lock
run: make validate-composer

- name: 🔍 Get composer cache directory
uses: wayofdev/gh-actions/actions/composer/[email protected]
with:
working-directory: app

- name: ♻️ Restore cached dependencies installed with composer
uses: actions/[email protected]
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}
restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-

- name: 📥 Install "${{ matrix.dependencies }}" dependencies with composer
uses: wayofdev/gh-actions/actions/composer/[email protected]
with:
working-directory: app
dependencies: ${{ matrix.dependencies }}

- name: 🛠️ Prepare environment
run: |
make env
cp -rf .env app/.env
- name: 🔑 Generate secret application key
working-directory: app
run: php artisan key:generate

- name: 🧪 Run architecture tests using pestphp/pest
working-directory: app
run: composer test:arch

mutation-testing:
timeout-minutes: 16
runs-on: ${{ matrix.os }}
Expand Down
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,25 @@ infect-ci: ## Runs infection – mutation testing framework with github output (
$(APP_COMPOSER) infect:ci
.PHONY: lint-infect-ci

test: ## Run project php-unit and pest tests
test: ## Run project Functional tests using pest
$(APP_COMPOSER) test
.PHONY: test

test-arch: ## Run project architecture tests using pest
$(APP_COMPOSER) test:arch
.PHONY: test-arch

test-all: test test-arch ## Run all project tests
.PHONY: test-all

test-cc: ## Run project php-unit and pest tests in coverage mode and build report
$(APP_COMPOSER) test:cc
.PHONY: test-cc

test-pgsql: ## Run project tests with postgresql
$(APP_COMPOSER) test:pgsql
.PHONY: test-pgsql

api-docs-public: ## Generate openapi docs specification file for public api
$(APP_EXEC) php artisan open-docs:generate public
.PHONY: api-docs-public
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
<a href="https://discord.gg/CE3TcCC5vr" target="_blank"><img alt="Discord" src="https://img.shields.io/discord/1228506758562058391?style=flat-square&logo=discord&labelColor=7289d9&logoColor=white&color=39456d"></a>
<a href="https://x.com/intent/follow?screen_name=wayofdev" target="_blank"><img alt="Follow on Twitter (X)" src="https://img.shields.io/badge/-Follow-black?style=flat-square&logo=X"></a>
</p>

<br>

# Laravel Starter Template
Expand Down
38 changes: 24 additions & 14 deletions app/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
"Tests\\": "tests/src/"
}
},
"config": {
Expand Down Expand Up @@ -123,11 +123,11 @@
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
],
"cs:diff": "php vendor/bin/php-cs-fixer fix --dry-run -v --diff",
"cs:fix": "php vendor/bin/php-cs-fixer fix -v",
"deptrac": "php vendor/bin/deptrac analyse --config-file=deptrac.yaml -v --cache-file=.build/.deptrac.cache",
"deptrac:ci": "php vendor/bin/deptrac analyse --config-file=deptrac.yaml -v --cache-file=.build/.deptrac.cache --formatter github-actions",
"deptrac:gv": "php vendor/bin/deptrac analyse --config-file=deptrac.yaml -v --cache-file=.build/.deptrac.cache --formatter graphviz-image --output ../assets/deptrac.svg",
"cs:diff": "php-cs-fixer fix --dry-run -v --diff",
"cs:fix": "php-cs-fixer fix -v",
"deptrac": "deptrac analyse --config-file=deptrac.yaml -v --cache-file=.build/.deptrac.cache",
"deptrac:ci": "deptrac analyse --config-file=deptrac.yaml -v --cache-file=.build/.deptrac.cache --formatter github-actions",
"deptrac:gv": "deptrac analyse --config-file=deptrac.yaml -v --cache-file=.build/.deptrac.cache --formatter graphviz-image --output ../assets/deptrac.svg",
"infect": [
"Composer\\Config::disableProcessTimeout",
"@putenv XDEBUG_MODE=coverage",
Expand All @@ -138,21 +138,31 @@
"@putenv XDEBUG_MODE=coverage",
"php -d memory_limit=2G vendor/bin/roave-infection-static-analysis-plugin --threads=2 --ansi --logger-github --ignore-msi-with-no-mutations --only-covered"
],
"psalm": "php vendor/bin/psalm --show-info=true",
"psalm:baseline": "php vendor/bin/psalm --set-baseline=psalm-baseline.xml",
"psalm:ci": "php vendor/bin/psalm --output-format=github --shepherd --show-info=false --stats --threads=4",
"stan": "php vendor/bin/phpstan analyse --memory-limit=2G",
"stan:baseline": "php vendor/bin/phpstan analyse --generate-baseline --memory-limit=2G --allow-empty-baseline",
"stan:ci": "php vendor/bin/phpstan analyse --memory-limit=2G --error-format=github",
"psalm": "psalm --show-info=true",
"psalm:baseline": "psalm --set-baseline=psalm-baseline.xml",
"psalm:ci": "psalm --output-format=github --shepherd --show-info=false --stats --threads=4",
"stan": "phpstan analyse --memory-limit=2G",
"stan:baseline": "phpstan analyse --generate-baseline --memory-limit=2G --allow-empty-baseline",
"stan:ci": "phpstan analyse --memory-limit=2G --error-format=github",
"test": [
"@putenv XDEBUG_MODE=coverage",
"@putenv DB_CONNECTION=memory",
"php vendor/bin/pest --color=always"
"pest --color=always"
],
"test:pgsql": [
"@putenv XDEBUG_MODE=coverage",
"@putenv DB_CONNECTION=pgsql",
"pest --color=always"
],
"test:arch": [
"@putenv XDEBUG_MODE=coverage",
"@putenv DB_CONNECTION=memory",
"pest --color=always --configuration pest.xml.dist"
],
"test:cc": [
"@putenv XDEBUG_MODE=coverage",
"@putenv DB_CONNECTION=memory",
"php vendor/bin/pest --coverage --coverage-clover=.build/phpunit/logs/clover.xml --color=always"
"pest --coverage --coverage-clover=.build/phpunit/logs/clover.xml --color=always"
]
}
}
36 changes: 36 additions & 0 deletions app/pest.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
cacheResultFile=".build/phpunit/result.cache"
failOnWarning="true"
failOnRisky="true"
executionOrder="random"
stderr="true"
beStrictAboutOutputDuringTests="true"
>
<extensions>
<bootstrap class="Ergebnis\PHPUnit\SlowTestDetector\Extension"/>
</extensions>
<testsuites>
<testsuite name="Arch Tests">
<directory>tests/src/Arch</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>src</directory>
</include>
</source>
<php>
<env name="APP_ENV" value="testing"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_STORE" value="array"/>
<env name="MAIL_MAILER" value="array"/>
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="TELESCOPE_ENABLED" value="false"/>
<env name="DB_CONNECTION" value="memory"/>
</php>
</phpunit>
4 changes: 0 additions & 4 deletions app/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,3 @@ parameters:
message: "#^Method Domain\\\\Product\\\\Models\\\\Product\\:\\:category\\(\\) return type with generic class Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\BelongsTo does not specify its types\\: TRelatedModel, TChildModel$#"
count: 1
path: src/Domain/Product/Models/Product.php
-
message: "#^Undefined variable\\: \\$this$#"
count: 1
path: tests/Pest.php
2 changes: 2 additions & 0 deletions app/phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ parameters:
- config/
- routes/
checkModelProperties: true
excludePaths:
- tests/src/Arch
tmpDir: .build/phpstan/
31 changes: 22 additions & 9 deletions app/phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,34 @@
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
cacheResultFile=".build/phpunit/result.cache"
failOnWarning="true"
failOnRisky="true"
executionOrder="random"
stderr="true"
beStrictAboutOutputDuringTests="true"
>
<extensions>
<bootstrap class="Ergebnis\PHPUnit\SlowTestDetector\Extension"/>
</extensions>
<testsuites>
<testsuite name="Bridge">
<directory>./tests/Bridge</directory>
</testsuite>
<testsuite name="Domain">
<directory>./tests/Domain</directory>
</testsuite>
<testsuite name="Support">
<directory>./tests/Support</directory>
<testsuite name="Functional Tests">
<directory>tests/src/Functional</directory>
</testsuite>
</testsuites>
<coverage>
<report>
<html outputDirectory=".build/coverage"/>
<text outputFile=".build/coverage.txt"/>
<clover outputFile=".build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile=".build/report.junit.xml"/>
</logging>
<source>
<include>
<directory>./src</directory>
<directory>src</directory>
</include>
</source>
<php>
Expand Down
15 changes: 2 additions & 13 deletions app/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
<code><![CDATA[$item]]></code>
</MixedAssignment>
</file>
<file src="tests/Bridge/Laravel/Admin/Category/Controllers/CategoryControllerTest.php">
<file src="tests/src/Functional/Bridge/Laravel/Admin/Category/Controllers/CategoryControllerTest.php">
<MissingClosureParamType>
<code><![CDATA[$json]]></code>
<code><![CDATA[$json]]></code>
Expand Down Expand Up @@ -238,7 +238,7 @@
<code><![CDATA[$category->uuid]]></code>
</MixedOperand>
</file>
<file src="tests/CreatesApplication.php">
<file src="tests/src/Functional/CreatesApplication.php">
<MixedAssignment>
<code><![CDATA[$app]]></code>
</MixedAssignment>
Expand All @@ -250,15 +250,4 @@
<code><![CDATA[make]]></code>
</MixedMethodCall>
</file>
<file src="tests/Pest.php">
<InternalMethod>
<code><![CDATA[in]]></code>
</InternalMethod>
<InvalidScope>
<code><![CDATA[$this]]></code>
</InvalidScope>
<MissingClosureReturnType>
<code><![CDATA[function () {]]></code>
</MissingClosureReturnType>
</file>
</files>
1 change: 1 addition & 0 deletions app/psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<directory name="tests/"/>
<directory name="routes/"/>
<ignoreFiles>
<directory name="tests/src/Arch/"/>
<directory name="vendor/"/>
</ignoreFiles>
<file name=".php-cs-fixer.dist.php"/>
Expand Down
47 changes: 0 additions & 47 deletions app/tests/Pest.php

This file was deleted.

8 changes: 8 additions & 0 deletions app/tests/src/Arch/DebugTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

declare(strict_types=1);

arch('do not forget dumps in your production code')
->expect(['trap', 'dd', 'dump', 'exit', 'die', 'print_r', 'var_dump', 'echo', 'print'])
->not
->toBeUsed();
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace Tests\Bridge\Laravel\Admin\Category\Controllers;
namespace Tests\Functional\Bridge\Laravel\Admin\Category\Controllers;

use Domain\Category\Models\Category;
use Illuminate\Testing\Fluent\AssertableJson;
use Tests\TestCase;
use Tests\Functional\TestCase;

final class CategoryControllerTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

declare(strict_types=1);

namespace Tests\Bridge\Laravel;
namespace Tests\Functional\Bridge\Laravel;

// use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use Tests\Functional\TestCase;

class ExampleTest extends TestCase
{
Expand Down
Loading

0 comments on commit daa9cb5

Please sign in to comment.