Files
shopPRO/docs/TESTING.md
Jacek Pyziak 702e3a94be ver. 0.318: shopPRO export produktów + nowe API endpoints
- NEW: IntegrationsRepository::shopproExportProduct() — eksport produktu do
  zdalnej instancji shopPRO (pola główne, tłumaczenia, custom fields, zdjęcia)
- NEW: sendImageToShopproApi() — wysyłka zdjęć przez API shopPRO (base64 POST)
- REFACTOR: shopproImportProduct() — wydzielono shopproDb() i
  missingShopproSetting(); dodano security_information, producer_id,
  custom fields, alt zdjęcia
- NEW: AttributeRepository::ensureAttributeForApi() i
  ensureAttributeValueForApi() — idempotent find-or-create dla słowników
- NEW: API POST dictionaries/ensure_attribute — utwórz lub znajdź atrybut
- NEW: API POST dictionaries/ensure_attribute_value — utwórz lub znajdź wartość
- NEW: API POST products/upload_image — przyjmuje base64, zapisuje plik i DB
- NEW: IntegrationsController::shoppro_product_export() — akcja admina
- NEW: przycisk "Eksportuj do shopPRO" w liście produktów
- NEW: pole API key w ustawieniach integracji shopPRO

Tests: 765 tests, 2153 assertions — all green

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-24 11:43:17 +01:00

3.9 KiB

Testowanie shopPRO

Szybki start

# Pelny suite (PowerShell — rekomendowane)
./test.ps1

# Konkretny plik
./test.ps1 tests/Unit/Domain/Product/ProductRepositoryTest.php

# Konkretny test
./test.ps1 --filter testGetQuantityReturnsCorrectValue

# Alternatywne
composer test              # standard
./test.bat                 # testdox (czytelna lista)
./test-simple.bat          # kropki
./test-debug.bat           # debug
./test.sh                  # Git Bash

Aktualny stan

OK (765 tests, 2153 assertions)

Zweryfikowano: 2026-02-24 (ver. 0.318)

Konfiguracja

  • PHPUnit 9.6 via phpunit.phar
  • Bootstrap: tests/bootstrap.php
  • Config: phpunit.xml

Struktura testow

tests/
|-- bootstrap.php
|-- stubs/
|   |-- CacheHandler.php       (inline w bootstrap)
|   |-- Helpers.php            (Shared\Helpers\Helpers stub)
|   `-- ShopProduct.php        (shop\Product stub)
|-- Unit/
|   |-- Domain/
|   |   |-- Article/ArticleRepositoryTest.php
|   |   |-- Attribute/AttributeRepositoryTest.php
|   |   |-- Banner/BannerRepositoryTest.php
|   |   |-- Basket/BasketCalculatorTest.php
|   |   |-- Cache/CacheRepositoryTest.php
|   |   |-- Category/CategoryRepositoryTest.php
|   |   |-- Coupon/CouponRepositoryTest.php
|   |   |-- Dictionaries/DictionariesRepositoryTest.php
|   |   |-- Integrations/IntegrationsRepositoryTest.php
|   |   |-- Languages/LanguagesRepositoryTest.php
|   |   |-- Layouts/LayoutsRepositoryTest.php
|   |   |-- Newsletter/NewsletterRepositoryTest.php
|   |   |-- Pages/PagesRepositoryTest.php
|   |   |-- PaymentMethod/PaymentMethodRepositoryTest.php
|   |   |-- Producer/ProducerRepositoryTest.php
|   |   |-- Product/ProductRepositoryTest.php
|   |   |-- ProductSet/ProductSetRepositoryTest.php
|   |   |-- Promotion/PromotionRepositoryTest.php
|   |   |-- Settings/SettingsRepositoryTest.php
|   |   |-- ShopStatus/ShopStatusRepositoryTest.php
|   |   |-- Transport/TransportRepositoryTest.php
|   |   |-- Update/UpdateRepositoryTest.php
|   |   `-- User/UserRepositoryTest.php
|   `-- admin/
|       `-- Controllers/
|           |-- ArticlesControllerTest.php
|           |-- DictionariesControllerTest.php
|           |-- IntegrationsControllerTest.php
|           |-- ProductArchiveControllerTest.php
|           |-- SettingsControllerTest.php
|           |-- ShopAttributeControllerTest.php
|           |-- ShopCategoryControllerTest.php
|           |-- ShopCouponControllerTest.php
|           |-- ShopPaymentMethodControllerTest.php
|           |-- ShopProducerControllerTest.php
|           |-- ShopProductControllerTest.php
|           |-- ShopProductSetsControllerTest.php
|           |-- ShopPromotionControllerTest.php
|           |-- ShopStatusesControllerTest.php
|           |-- ShopTransportControllerTest.php
|           `-- UsersControllerTest.php
|   `-- api/
|       |-- ApiRouterTest.php
|       `-- Controllers/
|           |-- OrdersApiControllerTest.php
|           |-- ProductsApiControllerTest.php
|           `-- DictionariesApiControllerTest.php
`-- Integration/                (puste — zarezerwowane)

Dodawanie nowych testow

  1. Plik w tests/Unit/Domain/<Module>/<Class>Test.php, tests/Unit/admin/Controllers/<Class>Test.php lub tests/Unit/api/Controllers/<Class>Test.php.
  2. Rozszerz PHPUnit\Framework\TestCase.
  3. Nazwy metod zaczynaj od test.
  4. Wzorzec AAA: Arrange, Act, Assert.

Mockowanie Medoo

$mockDb = $this->createMock(\medoo::class);
$mockDb->method('get')->willReturn(42);

$repo = new ProductRepository($mockDb);
$value = $repo->getQuantity(123);

$this->assertEquals(42, $value);

Bootstrap — stuby

tests/bootstrap.php rejestruje autoloader i definiuje stuby:

  • Redis, RedisConnection — klasy Redis (aby nie wymagac rozszerzenia)
  • Shared\Cache\CacheHandler — inline stub z get()/set()/exists()/delete()/deletePattern()
  • Shared\Helpers\Helpers — z tests/stubs/Helpers.php
  • shop\Product — z tests/stubs/ShopProduct.php