# Unit Tests for Barrierefrei-Mobil.de

This directory contains unit tests for the backend logic of the Barrierefrei-Mobil.de application.

## Test Structure

The tests are organized into the following directories:

- `Unit/Controller`: Tests for controller classes
- `Unit/DataHandler`: Tests for data handler classes
- `Unit/DBManager`: Tests for database manager classes

## Running Tests

To run the tests, you need to have PHPUnit installed. The project already includes PHPUnit as a dependency in the vendor directory.

### Running All Tests

From the project root directory, run:

```bash
vendor/bin/phpunit
```

### Running Specific Test Suites

To run only the controller tests:

```bash
vendor/bin/phpunit --testsuite Unit/Controller
```

To run only the data handler tests:

```bash
vendor/bin/phpunit --testsuite Unit/DataHandler
```

To run only the database manager tests:

```bash
vendor/bin/phpunit --testsuite Unit/DBManager
```

### Running Individual Test Files

To run a specific test file:

```bash
vendor/bin/phpunit tests/Unit/Controller/ControllerContactIndexTest.php
```

## Test Coverage

The PHPUnit configuration is set up to generate code coverage reports. To generate a coverage report, run:

```bash
vendor/bin/phpunit --coverage-html coverage
```

This will generate an HTML coverage report in the `coverage` directory.

## Writing New Tests

When writing new tests:

1. Follow the existing directory structure
2. Extend `PHPUnit\Framework\TestCase`
3. Use descriptive test method names that start with "test"
4. Use mocks for external dependencies
5. Test both success and failure cases

Example:

```php
public function testSomeMethodSuccess()
{
    // Test the success case
}

public function testSomeMethodFailure()
{
    // Test the failure case
}
```