# giberti/phpunit-local-server architecture

> Architecture diagram of the GitHub repository giberti/phpunit-local-server, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/giberti/phpunit-local-server
- Repository: https://github.com/giberti/phpunit-local-server

## Overview

##### Main Components

a. Test Environment Layer:
- PHPUnit Test Case (parent)
- LocalServerTestCase (extension)
- Test Classes (user implementation)

b. Server Management Layer:
- PHP Built-in Server Controller
- Server Configuration Manager
- Port Manager (for dynamic port assignment)

c. File System Integration:
- Document Root Handler
- Router Script Handler

d. Runtime Layer:
- PHP Binary Manager (for version switching)
- Process Manager

##### Component Relationships

- Bidirectional communication where applicable

##### Specific Implementation Details

- Test Environment     |

- LocalServerTestCase  |
- User Test Classes    |

- ↓

- Server Management    |

- Server Controller    |
- Config Manager       |
- Port Manager         |

- ↓

- Implementation Layer  |

- Docroot Handler      |
- Router Handler       |

- ↓

- Runtime Layer       |

- PHP Binary Manager   |
- Process Manager      |

##### Important Elements to Highlight

a. Entry Points:
- createServerWithDocroot()
- createServerWithRouter()
- getServerUrl()
- destroyServer()

b. Configuration Points:
- PHP Binary selection
- Document root path
- Router script path
- Port assignment

##### Technical Details

- Localhost connection (typically on port 8000)
- Dynamic port allocation mechanism
- File system interaction points
- Process management aspects

##### Implementation Notes

- Use standardized UML notation where applicable
- Version compatibility information
- Error handling paths

## Diagram (Mermaid)

```mermaid
graph TB
    %% Define styles
    classDef testEnv fill:#b3d9ff,stroke:#333,stroke-width:2px
    classDef serverMgmt fill:#90EE90,stroke:#333,stroke-width:2px
    classDef fileSystem fill:#FFB366,stroke:#333,stroke-width:2px
    classDef runtime fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef config fill:#FFE4B5,stroke:#333,stroke-width:2px

    %% Test Environment Layer
    subgraph TestEnv["Test Environment"]
        PHPUnit["PHPUnit TestCase"]
        LocalServer["LocalServerTestCase"]:::testEnv
        UserTests["User Test Classes"]:::testEnv
    end

    %% Server Management Layer
    subgraph ServerMgmt["Server Management"]
        ServerCtrl["Server Controller"]:::serverMgmt
        ConfigMgr["Configuration Manager"]:::serverMgmt
        PortMgr["Port Manager"]:::serverMgmt
    end

    %% File System Layer
    subgraph FSLayer["File System Integration"]
        DocRoot["Document Root Handler"]:::fileSystem
        Router["Router Script Handler"]:::fileSystem
        TestRes["Test Resources"]:::fileSystem
    end

    %% Runtime Layer
    subgraph Runtime["Runtime Layer"]
        PHPBin["PHP Binary Manager"]:::runtime
        ProcMgr["Process Manager"]:::runtime
    end

    %% Configuration Layer
    subgraph Config["Configuration"]
        ProjectConfig["Project Configuration"]:::config
        CIPipeline["CI/CD Pipeline"]:::config
    end

    %% Relationships
    PHPUnit --> LocalServer
    LocalServer --> UserTests
    LocalServer --> ServerCtrl
    ServerCtrl --> ConfigMgr
    ServerCtrl --> PortMgr
    ServerCtrl --> DocRoot
    ServerCtrl --> Router
    ServerCtrl --> PHPBin
    PHPBin --> ProcMgr
    DocRoot --> TestRes
    Router --> TestRes
    ConfigMgr --> ProjectConfig
    ProjectConfig --> CIPipeline

    %% Click events for component mapping
    click LocalServer "https://github.com/giberti/phpunit-local-server/blob/main/src/LocalServerTestCase.php"
    click DocRoot "https://github.com/giberti/phpunit-local-server/tree/main/tests/localhost/"
    click Router "https://github.com/giberti/phpunit-local-server/blob/main/tests/localhost/router.php"
    click TestRes "https://github.com/giberti/phpunit-local-server/blob/main/tests/localhost/a.php"
    click ProjectConfig "https://github.com/giberti/phpunit-local-server/blob/main/composer.json"
    click CIPipeline "https://github.com/giberti/phpunit-local-server/blob/main/.github/workflows/test-php.yml"

    %% Legend
    subgraph Legend
        L1["Test Environment"]:::testEnv
        L2["Server Management"]:::serverMgmt
        L3["File System"]:::fileSystem
        L4["Runtime"]:::runtime
        L5["Configuration"]:::config
    end
```
