Release 0.9a: Move ng to main, modernize PHP 8.1+ client, update documentation and add Gitea workflow

This commit is contained in:
sandros committed 2026-09-28 09:19:38 +02:00
1 parent 76e09c0b96
commit 67bc8aa462
9 files changed
+1560 -1455

No files matched your search

+160
View File
@@ -0,0 +1,160 @@
<?php
declare(strict_types=1);
require_once __DIR__ . '/../ninjamail.class.php';
echo "=== ninjaMail PHP érvényesség és típusvizsgálat ===\n";
$passed = 0;
$failed = 0;
function runTest(string $description, callable $fn): void {
global $passed, $failed;
try {
$fn();
echo " [OK] $description\n";
$passed++;
} catch (Throwable $e) {
echo " [FAIL] $description: " . $e->getMessage() . "\n";
$failed++;
}
}
// 1. ninjaMail alaposztály
runTest("ninjaMail inicializálás és check()", function () {
$api = new ninjaMail('https://example.org', 'test-key');
assert($api->check() === true, "check() igaz kell legyen érvényes adatokkal");
$apiNoKey = new ninjaMail('https://example.org');
assert($apiNoKey->check() === false, "check() hamis kell legyen hiányzó kulccsal");
});
// 2. ninjaMailSend
runTest("ninjaMailSend metódusok és kötelező mezők validációja", function () {
$s = new ninjaMailSend('https://example.org', 'test-key');
assert($s->to('user@example.com') === true);
assert($s->subject('Teszt tárgy') === true);
assert($s->message('<b>HTML</b>', 'Szöveg') === true);
$emptySender = new ninjaMailSend('https://example.org', 'test-key');
try {
$emptySender->send();
throw new Exception("Nem dobott kivételt hiányzó mezők esetén");
} catch (InvalidArgumentException $e) {
// Sikeres teszt, elvárt kivétel
}
});
// 3. ninjaMailSubscription
runTest("ninjaMailSubscription beállítások és lista validáció", function () {
$sub = new ninjaMailSubscription('https://example.org', 'test-key');
assert($sub->list(10) === true);
assert($sub->list(0) === false);
assert($sub->list(-5) === false);
assert($sub->activated(true) === true);
assert($sub->namechange(true) === true);
$emptySub = new ninjaMailSubscription('https://example.org', 'test-key');
try {
$emptySub->subscribe('user@example.com');
throw new Exception("Nem dobott kivételt hiányzó lista esetén");
} catch (InvalidArgumentException $e) {
// Sikeres teszt
}
try {
$emptySub->unsubscribe('user@example.com');
throw new Exception("Nem dobott kivételt hiányzó lista esetén");
} catch (InvalidArgumentException $e) {
// Sikeres teszt
}
});
// 4. ninjaMailNewsletter
runTest("ninjaMailNewsletter hírlevél azonosító és üzenet validáció", function () {
$nl = new ninjaMailNewsletter('https://example.org', 'test-key');
assert($nl->subject('Tárgy') === true);
assert($nl->message('Tartalom') === true);
assert($nl->newsletter(25) === true);
assert($nl->newsletter() === 25);
assert($nl->newsletter(0) === false);
$emptyNl = new ninjaMailNewsletter('https://example.org', 'test-key');
try {
$emptyNl->create();
throw new Exception("Nem dobott kivételt üres üzenetnél");
} catch (InvalidArgumentException $e) {
// Sikeres teszt
}
try {
$emptyNl->update();
throw new Exception("Nem dobott kivételt hírlevél ID nélkül");
} catch (InvalidArgumentException $e) {
// Sikeres teszt
}
try {
$emptyNl->send();
throw new Exception("Nem dobott kivételt hírlevél ID nélkül");
} catch (InvalidArgumentException $e) {
// Sikeres teszt
}
});
// 5. ninjaMailCampaign
runTest("ninjaMailCampaign kampány validáció", function () {
$camp = new ninjaMailCampaign('https://example.org', 'test-key');
assert($camp->campaign(40) === true);
assert($camp->campaign() === 40);
assert($camp->campaign(0) === false);
try {
$camp->create('');
throw new Exception("Nem dobott kivételt üres névnél");
} catch (InvalidArgumentException $e) {
// Sikeres teszt
}
$emptyCamp = new ninjaMailCampaign('https://example.org', 'test-key');
try {
$emptyCamp->remove();
throw new Exception("Nem dobott kivételt kampány ID nélkül");
} catch (InvalidArgumentException $e) {
// Sikeres teszt
}
try {
$camp->update([]);
throw new Exception("Nem dobott kivételt üres listánál");
} catch (InvalidArgumentException $e) {
// Sikeres teszt
}
try {
$camp->attach(0);
throw new Exception("Nem dobott kivételt érvénytelen hírlevél ID-nél");
} catch (InvalidArgumentException $e) {
// Sikeres teszt
}
});
// 6. ninjaMailStatistics
runTest("ninjaMailStatistics azonosító validáció", function () {
$stat = new ninjaMailStatistics('https://example.org', 'test-key');
try {
$stat->get(0);
throw new Exception("Nem dobott kivételt 0 azonosítónál");
} catch (InvalidArgumentException $e) {
// Sikeres teszt
}
});
echo "\nTeszt összefoglaló: $passed sikeres, $failed sikertelen.\n";
if ($failed > 0) {
exit(1);
}
exit(0);