Skip to content

Commit 888f4f4

Browse files
kojiromikeclaude
andauthored
test: add unit and integration test suites (#14)
* test: add unit and integration test suites - Add 53 unit tests for MetadataDetector, CodeImporter, OpenEMRConnector, and ImportCodesCommand - Add 9 integration tests that run against Docker OpenEMR - Split phpunit.xml into unit/integration test suites - Add phpunit-integration.xml with relaxed settings for OpenEMR environment - Add GitHub Actions workflow for running unit tests in CI - Add Taskfile tasks: test:unit, test:integration, test:all Fixes #7 Co-Authored-By: Claude Opus 4.5 <[email protected]> * test: add e2e tests that load vocabs and verify database state - Add CQM valueset fixture for e2e testing - Add 7 e2e tests that actually import vocabulary data and verify: - Data is inserted into valueset and valueset_oid tables - Tracking table is updated correctly - Skip logic works when already loaded - Force flag bypasses skip logic - Cleanup removes temporary files - Code types are normalized correctly (ICD10CM -> ICD10, etc.) - Add task test:e2e command - Update phpunit configs with e2e test suite Co-Authored-By: Claude Opus 4.5 <[email protected]> * test: add configurable e2e tests for real vocabulary files - Add tests/Fixtures/vocabs.php.example config template - Add RealVocabularyImportE2ETest for testing with actual vocab files - Tests are skipped when no vocab files are configured - Supports testing version upgrade paths (previous/current/next) - Add .gitignore entries for vocab config and licensed files Co-Authored-By: Claude Opus 4.5 <[email protected]> * test: fix e2e tests for real vocabulary files - Fix RXNORM table name (uppercase: RXNCONSO) - Fix SNOMED RF2 table name (sct2_description) - Handle case where import succeeds but table is empty (skip test) - Check if table exists before counting rows - Use vendor ICD10 file (has matching checksum) - Vocab files go in .local/vocabs/ (already gitignored) Co-Authored-By: Claude Opus 4.5 <[email protected]> --------- Co-authored-by: Claude Opus 4.5 <[email protected]>
1 parent fe35b86 commit 888f4f4

16 files changed

+1900
-6
lines changed

.github/workflows/phpunit.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: PHPUnit
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
phpunit:
13+
name: Run PHPUnit (Unit Tests)
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Setup PHP
21+
uses: shivammathur/setup-php@v2
22+
with:
23+
php-version: '8.2'
24+
extensions: json, zip, xml, simplexml
25+
coverage: none
26+
tools: composer:v2
27+
28+
- name: Cache Composer dependencies
29+
uses: actions/cache@v4
30+
with:
31+
path: vendor
32+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
33+
restore-keys: |
34+
${{ runner.os }}-composer-
35+
36+
- name: Install dependencies
37+
run: composer install --prefer-dist --no-progress --no-interaction
38+
39+
- name: Run PHPUnit (unit tests only)
40+
run: vendor/bin/phpunit --testsuite unit --testdox

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ Thumbs.db
2727
/.phpunit.result.cache
2828
/.phpunit.cache/
2929

30+
# Vocabulary test configuration and files (may contain licensed data)
31+
tests/Fixtures/vocabs.php
32+
tests/Fixtures/*.vocab.zip
33+
3034
# Environment
3135
.env
3236
.env.local

Taskfile.yml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,31 @@ tasks:
212212
# === Testing ===
213213

214214
test:
215-
desc: Run PHPUnit tests
215+
desc: Run PHPUnit tests (unit tests only, runs locally)
216216
cmds:
217-
- composer test
217+
- composer test:unit
218+
219+
test:unit:
220+
desc: Run unit tests only (no Docker required)
221+
cmds:
222+
- composer test:unit
223+
224+
test:integration:
225+
desc: Run integration tests inside Docker (requires dev:start)
226+
cmds:
227+
- docker compose exec -w {{.CLI_PATH}} openemr php vendor/bin/phpunit -c phpunit-integration.xml --testsuite integration --testdox
228+
229+
test:e2e:
230+
desc: Run e2e tests that load vocabs and verify DB state (requires dev:start)
231+
cmds:
232+
- docker compose exec -w {{.CLI_PATH}} openemr php vendor/bin/phpunit -c phpunit-integration.xml --testsuite e2e --testdox
233+
234+
test:all:
235+
desc: Run all tests (unit locally, integration and e2e in Docker)
236+
cmds:
237+
- task: test:unit
238+
- task: test:integration
239+
- task: test:e2e
218240

219241
test:coverage:
220242
desc: Run PHPUnit with coverage report

composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,12 @@
136136
"phpcbf": "phpcbf",
137137
"phpcs": "phpcs",
138138
"phpstan": "phpstan --memory-limit=512M analyse",
139-
"phpunit": "phpunit --testdox",
139+
"phpunit": "vendor/bin/phpunit --testdox",
140140
"rector": "rector process --dry-run",
141141
"rector-fix": "rector process",
142-
"test": "@phpunit"
142+
"test": "@phpunit",
143+
"test:unit": "vendor/bin/phpunit --testsuite unit --testdox",
144+
"test:integration": "vendor/bin/phpunit -c phpunit-integration.xml --testsuite integration --testdox",
145+
"test:e2e": "vendor/bin/phpunit -c phpunit-integration.xml --testsuite e2e --testdox"
143146
}
144147
}

phpunit-integration.xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
PHPUnit configuration for integration tests.
4+
5+
Integration tests run against a live OpenEMR environment and may trigger
6+
warnings from OpenEMR internals (e.g., missing $_SERVER keys in CLI context).
7+
This config is less strict than the main phpunit.xml to accommodate these.
8+
-->
9+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
11+
bootstrap="vendor/autoload.php"
12+
colors="true"
13+
cacheDirectory=".phpunit.cache"
14+
executionOrder="depends,defects"
15+
beStrictAboutOutputDuringTests="false"
16+
failOnRisky="false"
17+
failOnWarning="false">
18+
<testsuites>
19+
<testsuite name="integration">
20+
<directory>tests/Integration</directory>
21+
</testsuite>
22+
<testsuite name="e2e">
23+
<directory>tests/E2E</directory>
24+
</testsuite>
25+
</testsuites>
26+
27+
<source>
28+
<include>
29+
<directory>src</directory>
30+
</include>
31+
</source>
32+
</phpunit>

phpunit.xml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,24 @@
99
failOnRisky="true"
1010
failOnWarning="true">
1111
<testsuites>
12-
<testsuite name="default">
13-
<directory>tests</directory>
12+
<testsuite name="unit">
13+
<directory>tests/Unit</directory>
14+
</testsuite>
15+
<testsuite name="integration">
16+
<directory>tests/Integration</directory>
17+
</testsuite>
18+
<testsuite name="e2e">
19+
<directory>tests/E2E</directory>
1420
</testsuite>
1521
</testsuites>
1622

23+
<groups>
24+
<exclude>
25+
<group>integration</group>
26+
<group>e2e</group>
27+
</exclude>
28+
</groups>
29+
1730
<source>
1831
<include>
1932
<directory>src</directory>

0 commit comments

Comments
 (0)