Skip to content

Commit c5b7931

Browse files
committed
feat: split tests into functional and arch
1 parent d895b08 commit c5b7931

File tree

18 files changed

+178
-96
lines changed

18 files changed

+178
-96
lines changed

.github/workflows/testing.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,70 @@ jobs:
8989
token: ${{ secrets.CODECOV_TOKEN }}
9090
verbose: true
9191

92+
arch-testing:
93+
timeout-minutes: 4
94+
runs-on: ${{ matrix.os }}
95+
concurrency:
96+
cancel-in-progress: true
97+
group: arch-testing-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ matrix.php-version }}-${{ matrix.dependencies }}
98+
strategy:
99+
fail-fast: true
100+
matrix:
101+
os:
102+
- ubuntu-latest
103+
php-version:
104+
- '8.3'
105+
dependencies:
106+
- locked
107+
steps:
108+
- name: 📦 Check out the codebase
109+
uses: actions/[email protected]
110+
111+
- name: 🛠️ Setup PHP
112+
uses: shivammathur/[email protected]
113+
with:
114+
php-version: ${{ matrix.php-version }}
115+
extensions: mbstring, pdo, pdo_sqlite
116+
ini-values: error_reporting=E_ALL
117+
coverage: xdebug
118+
119+
- name: 🛠️ Setup problem matchers
120+
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
121+
122+
- name: 🤖 Validate composer.json and composer.lock
123+
run: make validate-composer
124+
125+
- name: 🔍 Get composer cache directory
126+
uses: wayofdev/gh-actions/actions/composer/[email protected]
127+
with:
128+
working-directory: app
129+
130+
- name: ♻️ Restore cached dependencies installed with composer
131+
uses: actions/[email protected]
132+
with:
133+
path: ${{ env.COMPOSER_CACHE_DIR }}
134+
key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}
135+
restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-
136+
137+
- name: 📥 Install "${{ matrix.dependencies }}" dependencies with composer
138+
uses: wayofdev/gh-actions/actions/composer/[email protected]
139+
with:
140+
working-directory: app
141+
dependencies: ${{ matrix.dependencies }}
142+
143+
- name: 🛠️ Prepare environment
144+
run: |
145+
make env
146+
cp -rf .env app/.env
147+
148+
- name: 🔑 Generate secret application key
149+
working-directory: app
150+
run: php artisan key:generate
151+
152+
- name: 🧪 Run architecture tests using pestphp/pest
153+
working-directory: app
154+
run: composer test:arch
155+
92156
mutation-testing:
93157
timeout-minutes: 16
94158
runs-on: ${{ matrix.os }}

Makefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,25 @@ infect-ci: ## Runs infection – mutation testing framework with github output (
308308
$(APP_COMPOSER) infect:ci
309309
.PHONY: lint-infect-ci
310310

311-
test: ## Run project php-unit and pest tests
311+
test: ## Run project Functional tests using pest
312312
$(APP_COMPOSER) test
313313
.PHONY: test
314314

315+
test-arch: ## Run project architecture tests using pest
316+
$(APP_COMPOSER) test:arch
317+
.PHONY: test-arch
318+
319+
test-all: test test-arch ## Run all project tests
320+
.PHONY: test-all
321+
315322
test-cc: ## Run project php-unit and pest tests in coverage mode and build report
316323
$(APP_COMPOSER) test:cc
317324
.PHONY: test-cc
318325

326+
test-pgsql: ## Run project tests with postgresql
327+
$(APP_COMPOSER) test:pgsql
328+
.PHONY: test-pgsql
329+
319330
api-docs-public: ## Generate openapi docs specification file for public api
320331
$(APP_EXEC) php artisan open-docs:generate public
321332
.PHONY: api-docs-public

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
<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>
3333
<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>
3434
</p>
35-
3635
<br>
3736

3837
# Laravel Starter Template

app/composer.json

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
},
8080
"autoload-dev": {
8181
"psr-4": {
82-
"Tests\\": "tests/"
82+
"Tests\\": "tests/src/"
8383
}
8484
},
8585
"config": {
@@ -123,11 +123,11 @@
123123
"post-create-project-cmd": [
124124
"@php artisan key:generate --ansi"
125125
],
126-
"cs:diff": "php vendor/bin/php-cs-fixer fix --dry-run -v --diff",
127-
"cs:fix": "php vendor/bin/php-cs-fixer fix -v",
128-
"deptrac": "php vendor/bin/deptrac analyse --config-file=deptrac.yaml -v --cache-file=.build/.deptrac.cache",
129-
"deptrac:ci": "php vendor/bin/deptrac analyse --config-file=deptrac.yaml -v --cache-file=.build/.deptrac.cache --formatter github-actions",
130-
"deptrac:gv": "php vendor/bin/deptrac analyse --config-file=deptrac.yaml -v --cache-file=.build/.deptrac.cache --formatter graphviz-image --output ../assets/deptrac.svg",
126+
"cs:diff": "php-cs-fixer fix --dry-run -v --diff",
127+
"cs:fix": "php-cs-fixer fix -v",
128+
"deptrac": "deptrac analyse --config-file=deptrac.yaml -v --cache-file=.build/.deptrac.cache",
129+
"deptrac:ci": "deptrac analyse --config-file=deptrac.yaml -v --cache-file=.build/.deptrac.cache --formatter github-actions",
130+
"deptrac:gv": "deptrac analyse --config-file=deptrac.yaml -v --cache-file=.build/.deptrac.cache --formatter graphviz-image --output ../assets/deptrac.svg",
131131
"infect": [
132132
"Composer\\Config::disableProcessTimeout",
133133
"@putenv XDEBUG_MODE=coverage",
@@ -138,21 +138,31 @@
138138
"@putenv XDEBUG_MODE=coverage",
139139
"php -d memory_limit=2G vendor/bin/roave-infection-static-analysis-plugin --threads=2 --ansi --logger-github --ignore-msi-with-no-mutations --only-covered"
140140
],
141-
"psalm": "php vendor/bin/psalm --show-info=true",
142-
"psalm:baseline": "php vendor/bin/psalm --set-baseline=psalm-baseline.xml",
143-
"psalm:ci": "php vendor/bin/psalm --output-format=github --shepherd --show-info=false --stats --threads=4",
144-
"stan": "php vendor/bin/phpstan analyse --memory-limit=2G",
145-
"stan:baseline": "php vendor/bin/phpstan analyse --generate-baseline --memory-limit=2G --allow-empty-baseline",
146-
"stan:ci": "php vendor/bin/phpstan analyse --memory-limit=2G --error-format=github",
141+
"psalm": "psalm --show-info=true",
142+
"psalm:baseline": "psalm --set-baseline=psalm-baseline.xml",
143+
"psalm:ci": "psalm --output-format=github --shepherd --show-info=false --stats --threads=4",
144+
"stan": "phpstan analyse --memory-limit=2G",
145+
"stan:baseline": "phpstan analyse --generate-baseline --memory-limit=2G --allow-empty-baseline",
146+
"stan:ci": "phpstan analyse --memory-limit=2G --error-format=github",
147147
"test": [
148148
"@putenv XDEBUG_MODE=coverage",
149149
"@putenv DB_CONNECTION=memory",
150-
"php vendor/bin/pest --color=always"
150+
"pest --color=always"
151+
],
152+
"test:arch": [
153+
"@putenv XDEBUG_MODE=coverage",
154+
"@putenv DB_CONNECTION=memory",
155+
"pest --color=always --configuration pest.xml.dist"
151156
],
152157
"test:cc": [
153158
"@putenv XDEBUG_MODE=coverage",
154159
"@putenv DB_CONNECTION=memory",
155-
"php vendor/bin/pest --coverage --coverage-clover=.build/phpunit/logs/clover.xml --color=always"
160+
"pest --coverage --coverage-clover=.build/phpunit/logs/clover.xml --color=always"
161+
],
162+
"test:pgsql": [
163+
"@putenv XDEBUG_MODE=coverage",
164+
"@putenv DB_CONNECTION=pgsql",
165+
"pest --color=always"
156166
]
157167
}
158168
}

app/pest.xml.dist

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
cacheResultFile=".build/phpunit/result.cache"
7+
failOnWarning="true"
8+
failOnRisky="true"
9+
executionOrder="random"
10+
stderr="true"
11+
beStrictAboutOutputDuringTests="true"
12+
>
13+
<extensions>
14+
<bootstrap class="Ergebnis\PHPUnit\SlowTestDetector\Extension"/>
15+
</extensions>
16+
<testsuites>
17+
<testsuite name="Arch Tests">
18+
<directory>tests/src/Arch</directory>
19+
</testsuite>
20+
</testsuites>
21+
<source>
22+
<include>
23+
<directory>src</directory>
24+
</include>
25+
</source>
26+
<php>
27+
<env name="APP_ENV" value="testing"/>
28+
<env name="BCRYPT_ROUNDS" value="4"/>
29+
<env name="CACHE_STORE" value="array"/>
30+
<env name="MAIL_MAILER" value="array"/>
31+
<env name="QUEUE_CONNECTION" value="sync"/>
32+
<env name="SESSION_DRIVER" value="array"/>
33+
<env name="TELESCOPE_ENABLED" value="false"/>
34+
<env name="DB_CONNECTION" value="memory"/>
35+
</php>
36+
</phpunit>

app/phpstan-baseline.neon

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,3 @@ parameters:
44
message: "#^Method Domain\\\\Product\\\\Models\\\\Product\\:\\:category\\(\\) return type with generic class Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\BelongsTo does not specify its types\\: TRelatedModel, TChildModel$#"
55
count: 1
66
path: src/Domain/Product/Models/Product.php
7-
-
8-
message: "#^Undefined variable\\: \\$this$#"
9-
count: 1
10-
path: tests/Pest.php

app/phpstan.neon.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ parameters:
99
- config/
1010
- routes/
1111
checkModelProperties: true
12+
excludePaths:
13+
- tests/src/Arch
1214
tmpDir: .build/phpstan/

app/phpunit.xml.dist

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,34 @@
33
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
44
bootstrap="vendor/autoload.php"
55
colors="true"
6+
cacheResultFile=".build/phpunit/result.cache"
7+
failOnWarning="true"
8+
failOnRisky="true"
9+
executionOrder="random"
10+
stderr="true"
11+
beStrictAboutOutputDuringTests="true"
612
>
13+
<extensions>
14+
<bootstrap class="Ergebnis\PHPUnit\SlowTestDetector\Extension"/>
15+
</extensions>
716
<testsuites>
8-
<testsuite name="Bridge">
9-
<directory>./tests/Bridge</directory>
10-
</testsuite>
11-
<testsuite name="Domain">
12-
<directory>./tests/Domain</directory>
13-
</testsuite>
14-
<testsuite name="Support">
15-
<directory>./tests/Support</directory>
17+
<testsuite name="Functional Tests">
18+
<directory>tests/src/Functional</directory>
1619
</testsuite>
1720
</testsuites>
21+
<coverage>
22+
<report>
23+
<html outputDirectory=".build/coverage"/>
24+
<text outputFile=".build/coverage.txt"/>
25+
<clover outputFile=".build/logs/clover.xml"/>
26+
</report>
27+
</coverage>
28+
<logging>
29+
<junit outputFile=".build/report.junit.xml"/>
30+
</logging>
1831
<source>
1932
<include>
20-
<directory>./src</directory>
33+
<directory>src</directory>
2134
</include>
2235
</source>
2336
<php>

app/psalm-baseline.xml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@
210210
<code><![CDATA[$item]]></code>
211211
</MixedAssignment>
212212
</file>
213-
<file src="tests/Bridge/Laravel/Admin/Category/Controllers/CategoryControllerTest.php">
213+
<file src="tests/src/Functional/Bridge/Laravel/Admin/Category/Controllers/CategoryControllerTest.php">
214214
<MissingClosureParamType>
215215
<code><![CDATA[$json]]></code>
216216
<code><![CDATA[$json]]></code>
@@ -238,7 +238,7 @@
238238
<code><![CDATA[$category->uuid]]></code>
239239
</MixedOperand>
240240
</file>
241-
<file src="tests/CreatesApplication.php">
241+
<file src="tests/src/Functional/CreatesApplication.php">
242242
<MixedAssignment>
243243
<code><![CDATA[$app]]></code>
244244
</MixedAssignment>
@@ -250,15 +250,4 @@
250250
<code><![CDATA[make]]></code>
251251
</MixedMethodCall>
252252
</file>
253-
<file src="tests/Pest.php">
254-
<InternalMethod>
255-
<code><![CDATA[in]]></code>
256-
</InternalMethod>
257-
<InvalidScope>
258-
<code><![CDATA[$this]]></code>
259-
</InvalidScope>
260-
<MissingClosureReturnType>
261-
<code><![CDATA[function () {]]></code>
262-
</MissingClosureReturnType>
263-
</file>
264253
</files>

app/psalm.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<directory name="tests/"/>
2323
<directory name="routes/"/>
2424
<ignoreFiles>
25+
<directory name="tests/src/Arch/"/>
2526
<directory name="vendor/"/>
2627
</ignoreFiles>
2728
<file name=".php-cs-fixer.dist.php"/>

0 commit comments

Comments
 (0)