- Dodano testy: SettingsRepositoryTest, LanguagesRepositoryTest, UserRepositoryTest - Infrastruktura: phpunit.xml, composer.json (phpunit/phpunit ^10), tests/bootstrap.php - Bootstrap stuby: \Shared\Cache\CacheHandler (in-memory), \S - Zaktualizowano docs/TESTING.md dla cmsPRO - Paczka: updates/1.60/ver_1.691.zip + manifest Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
67 lines
1.5 KiB
Markdown
67 lines
1.5 KiB
Markdown
# Testowanie cmsPRO
|
|
|
|
## Szybki start
|
|
|
|
```bash
|
|
# Instalacja PHPUnit (jednorazowo)
|
|
composer install
|
|
|
|
# Uruchomienie testów
|
|
./vendor/bin/phpunit
|
|
|
|
# Konkretny plik
|
|
./vendor/bin/phpunit tests/Unit/Domain/Settings/SettingsRepositoryTest.php
|
|
|
|
# Konkretny test
|
|
./vendor/bin/phpunit --filter testAllSettingsReturnsMappedArray
|
|
```
|
|
|
|
## Aktualny stan
|
|
|
|
```text
|
|
Testy jednostkowe dla Domain\ (Faza 2 DDD)
|
|
```
|
|
|
|
## Konfiguracja
|
|
|
|
- **PHPUnit 10** via `composer`
|
|
- **Bootstrap:** `tests/bootstrap.php`
|
|
- **Config:** `phpunit.xml`
|
|
|
|
## Struktura testów
|
|
|
|
```
|
|
tests/
|
|
├── bootstrap.php ← autoloader + stuby (CacheHandler, S)
|
|
└── Unit/
|
|
└── Domain/
|
|
├── Languages/LanguagesRepositoryTest.php
|
|
├── Settings/SettingsRepositoryTest.php
|
|
└── User/UserRepositoryTest.php
|
|
```
|
|
|
|
## Stuby (bootstrap.php)
|
|
|
|
- `\Shared\Cache\CacheHandler` — in-memory stub z `fetch()`/`store()`/`delete()`/`reset()`
|
|
- `\S` — stub z `delete_cache()`, `htacces()`, `get_domain()`, `send_email()`
|
|
- `medoo` — mockowany przez PHPUnit (`$this->createMock(\medoo::class)`)
|
|
|
|
## Dodawanie nowych testów
|
|
|
|
1. Plik w `tests/Unit/Domain/<Modul>/<Klasa>Test.php`.
|
|
2. Rozszerz `PHPUnit\Framework\TestCase`.
|
|
3. Nazwy metod zaczynaj od `test`.
|
|
4. Wzorzec AAA: Arrange, Act, Assert.
|
|
|
|
## Mockowanie Medoo
|
|
|
|
```php
|
|
$db = $this->createMock(\medoo::class);
|
|
$db->method('get')->willReturn(['id' => 1]);
|
|
|
|
$repo = new SettingsRepository($db);
|
|
$value = $repo->visitCounter();
|
|
|
|
$this->assertSame('1', $value);
|
|
```
|