Fix: testy + bugfix SettingsRepository::allSettings() + migracja phpunit.xml
- SettingsRepository::allSettings() — inicjalizacja $settings = [] przed pętlą (bug: false ?? [] zwracało false gdy cache pusty a DB null) - Stuby wydzielone do tests/stubs/CacheHandler.php + S.php - phpunit.xml zmigurowany do schematu PHPUnit 10 (coverage → source) - composer.lock dodany do repozytorium Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -18,12 +18,13 @@ class SettingsRepository
|
|||||||
{
|
{
|
||||||
if ( !$settings = \Shared\Cache\CacheHandler::fetch( 'settings_details' ) )
|
if ( !$settings = \Shared\Cache\CacheHandler::fetch( 'settings_details' ) )
|
||||||
{
|
{
|
||||||
$results = $this->db->select( 'pp_settings', '*' );
|
$settings = [];
|
||||||
|
$results = $this->db->select( 'pp_settings', '*' );
|
||||||
if ( is_array( $results ) )
|
if ( is_array( $results ) )
|
||||||
foreach ( $results as $row )
|
foreach ( $results as $row )
|
||||||
$settings[ $row['param'] ] = $row['value'];
|
$settings[ $row['param'] ] = $row['value'];
|
||||||
|
|
||||||
\Shared\Cache\CacheHandler::store( 'settings_details', $settings ?? [] );
|
\Shared\Cache\CacheHandler::store( 'settings_details', $settings );
|
||||||
}
|
}
|
||||||
|
|
||||||
return $settings ?? [];
|
return $settings ?? [];
|
||||||
|
|||||||
1688
composer.lock
generated
Normal file
1688
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
12
phpunit.xml
12
phpunit.xml
@@ -1,20 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="tests/bootstrap.php" colors="true">
|
||||||
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
|
|
||||||
bootstrap="tests/bootstrap.php"
|
|
||||||
colors="true">
|
|
||||||
|
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="Unit">
|
<testsuite name="Unit">
|
||||||
<directory>tests/Unit</directory>
|
<directory>tests/Unit</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
|
<source>
|
||||||
<coverage>
|
|
||||||
<include>
|
<include>
|
||||||
<directory>autoload/Domain</directory>
|
<directory>autoload/Domain</directory>
|
||||||
<directory>autoload/Shared</directory>
|
<directory>autoload/Shared</directory>
|
||||||
</include>
|
</include>
|
||||||
</coverage>
|
</source>
|
||||||
|
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class SettingsRepositoryTest extends TestCase
|
|||||||
$db = $this->mockDb();
|
$db = $this->mockDb();
|
||||||
$db->expects($this->never())->method('select');
|
$db->expects($this->never())->method('select');
|
||||||
|
|
||||||
\CacheHandlerStub::store('settings_details', ['cached' => '1']);
|
\Shared\Cache\CacheHandler::store('settings_details', ['cached' => '1']);
|
||||||
|
|
||||||
$repo = new SettingsRepository($db);
|
$repo = new SettingsRepository($db);
|
||||||
$result = $repo->allSettings();
|
$result = $repo->allSettings();
|
||||||
|
|||||||
@@ -1,51 +1,21 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
// Medoo ORM — potrzebny do mockowania w testach
|
// Medoo ORM
|
||||||
require_once __DIR__ . '/../libraries/medoo/medoo.php';
|
require_once __DIR__ . '/../libraries/medoo/medoo.php';
|
||||||
|
|
||||||
// Stub: \Shared\Cache\CacheHandler — musi być załadowany PRZED autoloaderem
|
// Stuby — muszą być załadowane PRZED autoloaderem PSR-4,
|
||||||
// żeby nie nadpisała go prawdziwa klasa
|
// żeby nie zostały nadpisane przez prawdziwe klasy
|
||||||
namespace Shared\Cache {
|
require_once __DIR__ . '/stubs/CacheHandler.php';
|
||||||
class CacheHandler
|
require_once __DIR__ . '/stubs/S.php';
|
||||||
{
|
|
||||||
private static array $store = [];
|
|
||||||
|
|
||||||
public static function reset(): void { self::$store = []; }
|
// PSR-4 autoloader dla Domain\
|
||||||
|
// Shared\ jest obsłużona przez stub powyżej — pomijamy w autoloaderze
|
||||||
public static function fetch(string $key): mixed
|
spl_autoload_register(function (string $class): void {
|
||||||
{
|
if (strncmp($class, 'Domain\\', 7) === 0) {
|
||||||
return self::$store[$key] ?? false;
|
$rel = substr($class, 7);
|
||||||
}
|
$file = __DIR__ . '/../autoload/Domain/' . str_replace('\\', '/', $rel) . '.php';
|
||||||
|
if (file_exists($file)) {
|
||||||
public static function store(string $key, mixed $value, int $ttl = 0): void
|
require $file;
|
||||||
{
|
|
||||||
self::$store[$key] = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function delete(string $key): void
|
|
||||||
{
|
|
||||||
unset(self::$store[$key]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
// Stub: \S — metody statyczne używane przez repozytoria
|
|
||||||
namespace {
|
|
||||||
class S
|
|
||||||
{
|
|
||||||
public static function delete_cache(): void {}
|
|
||||||
public static function htacces(): void {}
|
|
||||||
public static function get_domain(string $domain = ''): ?string { return $domain ?: null; }
|
|
||||||
public static function send_email(string $to, string $subject, string $body): bool { return true; }
|
|
||||||
}
|
|
||||||
|
|
||||||
// PSR-4 autoloader dla Domain\
|
|
||||||
// Shared\ jest już obsłużona przez stubę powyżej — pomijamy ją w autoloaderze
|
|
||||||
spl_autoload_register(function (string $class): void {
|
|
||||||
if (strncmp($class, 'Domain\\', 7) === 0) {
|
|
||||||
$rel = substr($class, 7);
|
|
||||||
$file = __DIR__ . '/../autoload/Domain/' . str_replace('\\', '/', $rel) . '.php';
|
|
||||||
if (file_exists($file)) { require $file; }
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|||||||
24
tests/stubs/CacheHandler.php
Normal file
24
tests/stubs/CacheHandler.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
namespace Shared\Cache;
|
||||||
|
|
||||||
|
class CacheHandler
|
||||||
|
{
|
||||||
|
private static array $store = [];
|
||||||
|
|
||||||
|
public static function reset(): void { self::$store = []; }
|
||||||
|
|
||||||
|
public static function fetch(string $key): mixed
|
||||||
|
{
|
||||||
|
return self::$store[$key] ?? false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function store(string $key, mixed $value, int $ttl = 0): void
|
||||||
|
{
|
||||||
|
self::$store[$key] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function delete(string $key): void
|
||||||
|
{
|
||||||
|
unset(self::$store[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
8
tests/stubs/S.php
Normal file
8
tests/stubs/S.php
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
class S
|
||||||
|
{
|
||||||
|
public static function delete_cache(): void {}
|
||||||
|
public static function htacces(): void {}
|
||||||
|
public static function get_domain(string $domain = ''): ?string { return $domain ?: null; }
|
||||||
|
public static function send_email(string $to, string $subject, string $body): bool { return true; }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user