Files
immorechner/docs/development.md
2025-11-09 11:27:21 +01:00

5.7 KiB

Entwicklung

← Zurück zur Hauptseite

Entwickler-Workflow

Entwicklungsumgebung einrichten

Siehe Installation

Code-Änderungen testen

# Container starten
docker-compose up -d

# In Web-Container einloggen
docker-compose exec web bash

# Cache leeren nach Änderungen
php bin/console cache:clear

Testing

PHPUnit Tests

Das Projekt verwendet PHPUnit 12.4 für Tests.

Alle Tests ausführen

docker-compose exec web php bin/phpunit

Spezifische Tests

# Nur Entity-Tests
docker-compose exec web php bin/phpunit tests/Entity

# Nur API-Tests
docker-compose exec web php bin/phpunit tests/Api

# Einzelne Testklasse
docker-compose exec web php bin/phpunit tests/Entity/UserTest.php

Mit Details

docker-compose exec web php bin/phpunit --verbose

Code Coverage (optional)

docker-compose exec web php bin/phpunit --coverage-text

Test-Struktur

tests/
├── Entity/
│   ├── UserTest.php           # User-Entity Tests
│   ├── ImmobilieTest.php      # Immobilie-Entity Tests
│   ├── BundeslandTest.php     # Bundesland-Entity Tests
│   └── HeizungstypTest.php    # Heizungstyp-Entity Tests
└── Api/
    ├── BundeslandApiTest.php  # Bundesländer-API Tests
    ├── HeizungstypApiTest.php # Heizungstypen-API Tests
    └── ApiDocumentationTest.php # API-Docs Tests

Code Quality

PHP-CS-Fixer

Für konsistenten Code-Style nach Symfony Standards.

Code-Style prüfen (Dry-Run)

docker-compose exec web vendor/bin/php-cs-fixer fix --dry-run --diff

Code automatisch formatieren

docker-compose exec web vendor/bin/php-cs-fixer fix

Bestimmte Verzeichnisse

# Nur src/
docker-compose exec web vendor/bin/php-cs-fixer fix src

# Nur tests/
docker-compose exec web vendor/bin/php-cs-fixer fix tests

Code-Style Regeln

Konfiguration in .php-cs-fixer.dist.php:

  • Symfony Coding Standards
  • PSR-12 kompatibel
  • Short Array Syntax
  • Sortierte Imports
  • Trailing Commas in Arrays

Datenbank

Neue Entity erstellen

docker-compose exec web php bin/console make:entity

Migration erstellen

Nach Änderungen an Entities:

docker-compose exec web php bin/console doctrine:migrations:diff

Migration ausführen

docker-compose exec web php bin/console doctrine:migrations:migrate

Migration rückgängig machen

# Letzte Migration
docker-compose exec web php bin/console doctrine:migrations:migrate prev

# Zu spezifischer Version
docker-compose exec web php bin/console doctrine:migrations:migrate DoctrineMigrations\\Version20251109100000

Migration-Status

docker-compose exec web php bin/console doctrine:migrations:status

Datenbank-Schema validieren

docker-compose exec web php bin/console doctrine:schema:validate

Controller & Routes

Controller erstellen

docker-compose exec web php bin/console make:controller

Routes anzeigen

# Alle Routes
docker-compose exec web php bin/console debug:router

# Spezifische Route
docker-compose exec web php bin/console debug:router app_home

Symfony Console

Cache

# Cache leeren
docker-compose exec web php bin/console cache:clear

# Cache warmup
docker-compose exec web php bin/console cache:warmup

Services debuggen

# Alle Services
docker-compose exec web php bin/console debug:container

# Spezifischer Service
docker-compose exec web php bin/console debug:container UserRepository

Ereignisse anzeigen

docker-compose exec web php bin/console debug:event-dispatcher

Konfiguration anzeigen

docker-compose exec web php bin/console debug:config framework

Git Workflow

Feature-Branch erstellen

git checkout -b feature/neue-funktion

Änderungen committen

git add .
git commit -m "Feature: Beschreibung der Änderung"

Pull Request erstellen

  1. Push auf Remote Branch
  2. Pull Request in GitHub/GitLab erstellen
  3. Code Review abwarten
  4. Nach Approval mergen

Best Practices

Code-Organisation

  1. Controller: Dünn halten, Logik in Services auslagern
  2. Entities: Nur Datenmodell, keine Business-Logik
  3. Services: Wiederverwendbare Business-Logik
  4. Repositories: Nur Datenbank-Queries

Namenskonventionen

  • Controller: XyzController.php
  • Entity: Xyz.php
  • Repository: XyzRepository.php
  • Service: XyzService.php
  • Test: XyzTest.php

Security

  • Nie Passwörter im Klartext speichern
  • Immer UserPasswordHasher verwenden
  • CSRF-Tokens bei allen Forms
  • Input-Validierung auf Server-Seite
  • Output-Escaping (Twig macht automatisch)

Performance

  • Doctrine Query Cache nutzen
  • Eager Loading für Relationen
  • Opcache in Produktion aktivieren
  • Assets kompilieren für Produktion

Deployment

Vorbereitung

# .env.local für Produktion erstellen
cp .env .env.local

# Produktions-Werte setzen
APP_ENV=prod
APP_SECRET=<neues-secret-generieren>

Build für Produktion

# Composer Dependencies ohne Dev
composer install --no-dev --optimize-autoloader

# Cache warmup
php bin/console cache:warmup --env=prod

# Assets installieren
php bin/console assets:install public --symlink --relative --env=prod

Database Migration

php bin/console doctrine:migrations:migrate --no-interaction --env=prod

Siehe auch:

← Zurück zur Hauptseite