Testing Strategies
Relevant source files
The following files were used as context for generating this wiki page:
The Nextcloud CAD Viewer project employs a multi-layered testing strategy to ensure the reliability of both its PHP backend and Vue.js frontend. The strategy encompasses unit testing, static analysis, and linting to maintain high code quality across the entire stack.
The primary goal is to validate core functionalities, such as CAD file format detection and application bootstrapping, while ensuring compatibility with Nextcloud 33 and PHP 8.2. Developers can refer to the Developer Guide for environment setup.
Backend Testing Architecture
The backend testing suite is primarily driven by PHPUnit and supplemented by static analysis tools. It focuses on the logic within the lib/ directory.
Unit Testing with PHPUnit
The project uses PHPUnit 10.4 for unit tests. The configuration is defined in tests/phpunit.xml, which specifies that tests are located in the tests/unit directory and should cover the lib source directory.
Sources: tests/phpunit.xml:1-16, composer.json:15
Static Analysis and Linting
To ensure type safety and adherence to coding standards, several tools are integrated:
- Psalm & PHPStan: Used for deep static analysis to find bugs without executing code.
- PHP CS Fixer: Enforces the Nextcloud coding standard.
- Linting: A custom script validates PHP syntax across the project (excluding vendor directories).
Sources: composer.json:13-18, composer.json:33-36, AGENTS.md:46-49
Test Execution Commands
| Tool | Command | Purpose |
|---|---|---|
| PHPUnit | composer test:unit | Executes backend unit tests. |
| Psalm | composer psalm | Performs static analysis. |
| PHP CS Fixer | composer cs:check | Verifies coding standard compliance. |
| Syntax Lint | composer lint | Checks for PHP syntax errors. |
Sources: composer.json:32-37, AGENTS.md:42-45
Frontend Testing Architecture
The frontend uses Jest as its primary test runner, configured specifically for a Vue 3 and TypeScript environment.
Jest Configuration
The jest.config.js file defines how the frontend tests are executed. Key configurations include:
- Environment: Uses
jsdomto simulate a browser environment. - Transforms: Employs
@vue/vue3-jestfor.vuefiles andbabel-jestfor JavaScript/TypeScript files. - Mocks: Mocks core dependencies like
@mlightcad/cad-viewerandelement-plusto isolate components during testing. - Globals: Provides global Nextcloud objects like
OCandOCAthat are expected at runtime.
Sources: jest.config.js:1-50, package.json:52-56
Frontend Test Flow
The following diagram illustrates how Jest processes a test file:
The diagram shows the transformation pipeline used by Jest to handle different file extensions before executing them in the jsdom environment.
Sources: jest.config.js:5-13, package.json:14
Automated Verification Targets
The project focuses its testing efforts on critical integration points and utility logic.
CAD Format Validation
A key area of testing is the cadLoader utility, which ensures that only supported MIME types (DWG and DXF) are processed by the viewer.
describe('isSupportedCADFormat', () => {
it('should return true for DWG MIME types', () => {
expect(isSupportedCADFormat('application/acad')).toBe(true);
expect(isSupportedCADFormat('image/vnd.dwg')).toBe(true);
});
});
Sources: tests/unit/cadLoader.spec.ts:5-10
Coverage and Quality Requirements
The project configuration includes strict requirements for test execution:
- PHP Version: Analysis and tests must target PHP 8.2.
- Platform Constraints: Backend tests may require specific Nextcloud core classes, which might lead to failures if not properly mocked in local environments.
- Frontend Coverage: Jest is configured to collect coverage from all
.tsand.vuefiles in thesrc/directory, excluding entry points likemain.ts.
Sources: AGENTS.md:42-45, jest.config.js:42-47, composer.json:47-49
Continuous Integration Logic
The testing strategy is designed to be executed within GitHub Actions, following Nextcloud organization patterns.
The sequence diagram details the automated workflow triggered upon code submission, involving both backend and frontend validation steps.
Sources: AGENTS.md:51-54, composer.json:37
Conclusion
The testing strategy for Nextcloud CAD Viewer provides a robust framework for catching regressions. By combining PHPUnit for backend logic, Jest for frontend components, and comprehensive static analysis via Psalm and ESLint, the project ensures that the integration of the browser-based CAD viewer remains stable across updates to the Nextcloud ecosystem.