167 lines
3.3 KiB
Markdown
167 lines
3.3 KiB
Markdown
# Testowanie shopPRO
|
|
|
|
## Szybki start
|
|
|
|
### Pelny zestaw testow
|
|
```bash
|
|
composer test
|
|
```
|
|
|
|
Alternatywnie (Windows):
|
|
```bash
|
|
./test.ps1
|
|
./test.bat
|
|
./test-simple.bat
|
|
./test-debug.bat
|
|
```
|
|
|
|
Alternatywnie (Git Bash):
|
|
```bash
|
|
./test.sh
|
|
```
|
|
|
|
### Konkretny plik testowy
|
|
```bash
|
|
./test.ps1 tests/Unit/Domain/Product/ProductRepositoryTest.php
|
|
./test.ps1 tests/Unit/admin/Controllers/ArticlesControllerTest.php
|
|
```
|
|
|
|
### Konkretny test (`--filter`)
|
|
```bash
|
|
./test.ps1 --filter testGetQuantityReturnsCorrectValue
|
|
```
|
|
|
|
## Aktualny stan suite
|
|
|
|
Ostatnio zweryfikowano: 2026-02-10
|
|
|
|
```text
|
|
OK (82 tests, 181 assertions)
|
|
```
|
|
|
|
## Struktura testow
|
|
|
|
```text
|
|
tests/
|
|
|-- bootstrap.php
|
|
|-- Unit/
|
|
| |-- Domain/
|
|
| | |-- Article/ArticleRepositoryTest.php
|
|
| | |-- Banner/BannerRepositoryTest.php
|
|
| | |-- Cache/CacheRepositoryTest.php
|
|
| | |-- Dictionaries/DictionariesRepositoryTest.php
|
|
| | |-- Product/ProductRepositoryTest.php
|
|
| | |-- Settings/SettingsRepositoryTest.php
|
|
| | `-- User/UserRepositoryTest.php
|
|
| `-- admin/
|
|
| `-- Controllers/
|
|
| |-- ArticlesControllerTest.php
|
|
| |-- DictionariesControllerTest.php
|
|
| |-- ProductArchiveControllerTest.php
|
|
| |-- SettingsControllerTest.php
|
|
| `-- UsersControllerTest.php
|
|
`-- Integration/
|
|
```
|
|
|
|
## Tryby uruchamiania
|
|
|
|
### 1. TestDox (czytelna lista)
|
|
```bash
|
|
./test.bat
|
|
```
|
|
Uruchamia:
|
|
```bash
|
|
C:\xampp\php\php.exe phpunit.phar --testdox
|
|
```
|
|
|
|
### 2. Standard (kropki)
|
|
```bash
|
|
./test-simple.bat
|
|
```
|
|
Uruchamia:
|
|
```bash
|
|
C:\xampp\php\php.exe phpunit.phar
|
|
```
|
|
|
|
### 3. Debug (pelne logowanie)
|
|
```bash
|
|
./test-debug.bat
|
|
```
|
|
Uruchamia:
|
|
```bash
|
|
C:\xampp\php\php.exe phpunit.phar --debug
|
|
```
|
|
|
|
### 4. PowerShell (najbardziej niezawodne)
|
|
```bash
|
|
./test.ps1
|
|
```
|
|
- najpierw probuje `php` z PATH
|
|
- jesli brak, probuje m.in. `C:\xampp\php\php.exe`
|
|
- zawsze dodaje `--do-not-cache-result`
|
|
|
|
## Interpretacja wynikow
|
|
|
|
```text
|
|
. = test przeszedl
|
|
E = error (blad wykonania)
|
|
F = failure (niezgodna asercja)
|
|
```
|
|
|
|
Przyklad sukcesu:
|
|
```text
|
|
................................................................. 65 / 82 ( 79%)
|
|
................. 82 / 82 (100%)
|
|
|
|
OK (82 tests, 181 assertions)
|
|
```
|
|
|
|
## Dodawanie nowych testow
|
|
|
|
1. Dodaj plik w odpowiednim module, np. `tests/Unit/Domain/<Module>/<Class>Test.php`.
|
|
2. Rozszerz `PHPUnit\Framework\TestCase`.
|
|
3. Nazwy metod zaczynaj od `test`.
|
|
4. Trzymaj sie wzorca AAA: Arrange, Act, Assert.
|
|
|
|
## Mockowanie (przyklad)
|
|
|
|
```php
|
|
$mockDb = $this->createMock(\medoo::class);
|
|
$mockDb->method('get')->willReturn(42);
|
|
|
|
$repo = new ProductRepository($mockDb);
|
|
$value = $repo->getQuantity(123);
|
|
|
|
$this->assertEquals(42, $value);
|
|
```
|
|
|
|
## Przydatne informacje
|
|
|
|
- Konfiguracja PHPUnit: `phpunit.xml`
|
|
- Bootstrap testow: `tests/bootstrap.php`
|
|
- Dodatkowy opis: `tests/README.md`
|
|
|
|
## Aktualizacja suite
|
|
|
|
Ostatnio zweryfikowano: 2026-02-12
|
|
|
|
```text
|
|
OK (119 tests, 256 assertions)
|
|
```
|
|
|
|
Nowe testy dodane 2026-02-12:
|
|
- `tests/Unit/Domain/User/UserRepositoryTest.php` (25 testow: CRUD, logon, 2FA verify/send, checkLogin, updateById)
|
|
- `tests/Unit/admin/Controllers/UsersControllerTest.php` (12 testow: kontrakty + normalizeUser)
|
|
|
|
Aktualizacja po migracji widokow Users (2026-02-12):
|
|
```text
|
|
OK (120 tests, 262 assertions)
|
|
```
|
|
|
|
## Aktualizacja suite (finalizacja Users)
|
|
Ostatnio zweryfikowano: 2026-02-12
|
|
|
|
```text
|
|
OK (120 tests, 262 assertions)
|
|
```
|