Files
shopPRO/TESTING.md
Jacek Pyziak f5054047fd 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.
2026-02-11 00:26:01 +01:00

2.7 KiB

Testowanie shopPRO

Szybki start

Pelny zestaw testow

composer test

Alternatywnie (Windows):

./test.ps1
./test.bat
./test-simple.bat
./test-debug.bat

Alternatywnie (Git Bash):

./test.sh

Konkretny plik testowy

./test.ps1 tests/Unit/Domain/Product/ProductRepositoryTest.php
./test.ps1 tests/Unit/admin/Controllers/ArticlesControllerTest.php

Konkretny test (--filter)

./test.ps1 --filter testGetQuantityReturnsCorrectValue

Aktualny stan suite

Ostatnio zweryfikowano: 2026-02-10

OK (82 tests, 181 assertions)

Struktura testow

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)

./test.bat

Uruchamia:

C:\xampp\php\php.exe phpunit.phar --testdox

2. Standard (kropki)

./test-simple.bat

Uruchamia:

C:\xampp\php\php.exe phpunit.phar

3. Debug (pelne logowanie)

./test-debug.bat

Uruchamia:

C:\xampp\php\php.exe phpunit.phar --debug

4. PowerShell (najbardziej niezawodne)

./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

.  = test przeszedl
E  = error (blad wykonania)
F  = failure (niezgodna asercja)

Przyklad sukcesu:

................................................................. 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)

$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