Add new controllers for file management and product archiving
- Introduced FilemanagerController to handle file manager access and URL generation. - Added ProductArchiveController for managing archived products, including listing and unarchiving functionality. - Implemented Site class with methods for finalizing admin login and handling special actions. - Created ShopProduct control class for managing product operations, including mass editing, product duplication, and image handling. - Added necessary methods for product management, including saving, deleting, and changing product statuses.
This commit is contained in:
194
TESTING.md
194
TESTING.md
@@ -1,136 +1,140 @@
|
||||
# 🧪 Testowanie shopPRO
|
||||
# Testowanie shopPRO
|
||||
|
||||
## Szybki start
|
||||
|
||||
### Uruchom wszystkie testy
|
||||
### Pelny zestaw testow
|
||||
```bash
|
||||
./test.bat # Windows CMD (z nazwami testów)
|
||||
./test-simple.bat # Tylko kropki (szybki)
|
||||
./test-debug.bat # Pełne szczegóły (debug)
|
||||
./test.ps1 # PowerShell (autodetekcja PHP)
|
||||
./test.sh # Git Bash
|
||||
composer test
|
||||
```
|
||||
|
||||
### Konkretny plik
|
||||
Alternatywnie (Windows):
|
||||
```bash
|
||||
./test.bat tests/Unit/Domain/Product/ProductRepositoryTest.php
|
||||
./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
|
||||
```
|
||||
|
||||
## Tryby wyświetlania
|
||||
### Konkretny test (`--filter`)
|
||||
```bash
|
||||
./test.ps1 --filter testGetQuantityReturnsCorrectValue
|
||||
```
|
||||
|
||||
### 1. TestDox (domyślny) - Czytelna lista ✅
|
||||
## 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
|
||||
| `-- admin/
|
||||
| `-- Controllers/
|
||||
| |-- ArticlesControllerTest.php
|
||||
| |-- DictionariesControllerTest.php
|
||||
| |-- ProductArchiveControllerTest.php
|
||||
| `-- SettingsControllerTest.php
|
||||
`-- Integration/
|
||||
```
|
||||
|
||||
## Tryby uruchamiania
|
||||
|
||||
### 1. TestDox (czytelna lista)
|
||||
```bash
|
||||
./test.bat
|
||||
```
|
||||
Wynik:
|
||||
```
|
||||
Product Repository
|
||||
✔ Get quantity returns correct value [2.78 ms]
|
||||
✔ Get quantity returns null when product not found
|
||||
✔ Find returns product data
|
||||
Uruchamia:
|
||||
```bash
|
||||
C:\xampp\php\php.exe phpunit.phar --testdox
|
||||
```
|
||||
|
||||
### 2. Simple - Tylko kropki 📊
|
||||
### 2. Standard (kropki)
|
||||
```bash
|
||||
./test-simple.bat
|
||||
```
|
||||
Wynik:
|
||||
```
|
||||
..... 5 / 5 (100%)
|
||||
OK (5 tests, 11 assertions)
|
||||
Uruchamia:
|
||||
```bash
|
||||
C:\xampp\php\php.exe phpunit.phar
|
||||
```
|
||||
|
||||
### 3. Debug - Wszystkie szczegóły 🔬
|
||||
### 3. Debug (pelne logowanie)
|
||||
```bash
|
||||
./test-debug.bat
|
||||
```
|
||||
Wynik:
|
||||
```
|
||||
Test 'testGetQuantity' started
|
||||
Test 'testGetQuantity' ended
|
||||
...
|
||||
Uruchamia:
|
||||
```bash
|
||||
C:\xampp\php\php.exe phpunit.phar --debug
|
||||
```
|
||||
|
||||
## Interpretacja wyników
|
||||
|
||||
### ✅ Sukces
|
||||
### 4. PowerShell (najbardziej niezawodne)
|
||||
```bash
|
||||
./test.ps1
|
||||
```
|
||||
..... 5 / 5 (100%)
|
||||
- najpierw probuje `php` z PATH
|
||||
- jesli brak, probuje m.in. `C:\xampp\php\php.exe`
|
||||
- zawsze dodaje `--do-not-cache-result`
|
||||
|
||||
OK (5 tests, 11 assertions)
|
||||
## Interpretacja wynikow
|
||||
|
||||
```text
|
||||
. = test przeszedl
|
||||
E = error (blad wykonania)
|
||||
F = failure (niezgodna asercja)
|
||||
```
|
||||
- `.` = test przeszedł
|
||||
- Wszystko działa!
|
||||
|
||||
### ❌ Błąd
|
||||
Przyklad sukcesu:
|
||||
```text
|
||||
................................................................. 65 / 82 ( 79%)
|
||||
................. 82 / 82 (100%)
|
||||
|
||||
OK (82 tests, 181 assertions)
|
||||
```
|
||||
..E.. 5 / 5 (100%)
|
||||
|
||||
ERRORS!
|
||||
Tests: 5, Assertions: 8, Errors: 1.
|
||||
```
|
||||
- `E` = Error - błąd w kodzie
|
||||
- Sprawdź szczegóły powyżej
|
||||
## Dodawanie nowych testow
|
||||
|
||||
### ❌ Niepowodzenie
|
||||
```
|
||||
..F.. 5 / 5 (100%)
|
||||
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.
|
||||
|
||||
FAILURES!
|
||||
Tests: 5, Assertions: 11, Failures: 1.
|
||||
```
|
||||
- `F` = Failure - asercja się nie powiodła
|
||||
- Oczekiwano innej wartości
|
||||
|
||||
## Przykładowy test
|
||||
## Mockowanie (przyklad)
|
||||
|
||||
```php
|
||||
public function testGetQuantityReturnsCorrectValue()
|
||||
{
|
||||
// Arrange - Przygotuj
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->method('get')->willReturn(42);
|
||||
$repository = new ProductRepository($mockDb);
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->method('get')->willReturn(42);
|
||||
|
||||
// Act - Wykonaj
|
||||
$quantity = $repository->getQuantity(123);
|
||||
$repo = new ProductRepository($mockDb);
|
||||
$value = $repo->getQuantity(123);
|
||||
|
||||
// Assert - Sprawdź
|
||||
$this->assertEquals(42, $quantity);
|
||||
}
|
||||
$this->assertEquals(42, $value);
|
||||
```
|
||||
|
||||
## Dodawanie nowych testów
|
||||
## Przydatne informacje
|
||||
|
||||
1. Utwórz plik w `tests/Unit/Domain/{Module}/{Class}Test.php`
|
||||
2. Rozszerz `TestCase`
|
||||
3. Metody testowe zaczynaj od `test`
|
||||
4. Użyj pattern **AAA** (Arrange, Act, Assert)
|
||||
|
||||
## Asercje
|
||||
|
||||
```php
|
||||
$this->assertEquals(expected, actual); // Równość
|
||||
$this->assertIsInt($value); // Typ
|
||||
$this->assertNull($value); // Null
|
||||
$this->assertTrue($condition); // Prawda
|
||||
$this->assertCount(3, $array); // Rozmiar
|
||||
```
|
||||
|
||||
## Mockowanie
|
||||
|
||||
```php
|
||||
// Prosty mock
|
||||
$mock = $this->createMock(\medoo::class);
|
||||
$mock->method('get')->willReturn('wartość');
|
||||
|
||||
// Z weryfikacją
|
||||
$mock->expects($this->once())
|
||||
->method('get')
|
||||
->with($this->equalTo('tabela'))
|
||||
->willReturn(42);
|
||||
```
|
||||
|
||||
---
|
||||
📚 Więcej: [tests/README.md](tests/README.md)
|
||||
- Konfiguracja PHPUnit: `phpunit.xml`
|
||||
- Bootstrap testow: `tests/bootstrap.php`
|
||||
- Dodatkowy opis: `tests/README.md`
|
||||
|
||||
Reference in New Issue
Block a user