[web-php] master: Enhancement: Turn PHPT tests into PHPUnit test cases (#943)
| From: | Andreas Möller via GitHub | Date: | Tue, 13 Feb 2024 13:30:11 +0000 |
| Subject: | [web-php] master: Enhancement: Turn PHPT tests into PHPUnit test cases (#943) | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-31467@lists.php.net to get a copy of this message | ||
Author: Andreas Möller (localheinz)
Committer: GitHub (web-flow)
Pusher: saundefined
Date: 2024-02-13T16:16:24+03:00
Commit: https://github.com/php/web-php/commit/33dd2a89e1cfd5d926fa628609c917edc780bb4d
Raw diff: https://github.com/php/web-php/commit/33dd2a89e1cfd5d926fa628609c917edc780bb4d.diff
Enhancement: Turn PHPT tests into PHPUnit test cases (#943)
Changed paths:
A tests/Unit/CleanAntiSpamTest.php
A tests/Unit/GenChallengeTest.php
A tests/Unit/IsEmailableAddressTest.php
A tests/Unit/TestAnswerTest.php
A tests/Unit/UserNotes/SorterTest.php
D tests/Unit/UserNotes/Sorter/sort-no-notes.phpt
D tests/Unit/UserNotes/Sorter/sort-notes-full.phpt
D tests/Unit/UserNotes/Sorter/sort-single-note-with-no-votes.phpt
D tests/Unit/UserNotes/Sorter/sort-some-notes.phpt
D tests/Unit/clean-anti-spam.phpt
D tests/Unit/gen-challenge.phpt
D tests/Unit/is-emailable-address.phpt
D tests/Unit/test-answer.phpt
M composer.json
M tests/phpunit.xml
Diff:
diff --git a/composer.json b/composer.json
index 2b512311e5..f413b64ac9 100644
--- a/composer.json
+++ b/composer.json
@@ -22,7 +22,7 @@
},
"autoload-dev": {
"psr-4": {
- "phpweb\\Test\\EndToEnd\\": "tests/EndToEnd/"
+ "phpweb\\Test\\": "tests/"
}
},
"config": {
diff --git a/tests/Unit/CleanAntiSpamTest.php b/tests/Unit/CleanAntiSpamTest.php
new file mode 100644
index 0000000000..8d16fed9f1
--- /dev/null
+++ b/tests/Unit/CleanAntiSpamTest.php
@@ -0,0 +1,54 @@
+<?php
+
+declare(strict_types=1);
+
+namespace phpweb\Test\Unit;
+
+use PHPUnit\Framework;
+
+#[Framework\Attributes\CoversFunction('clean_AntiSPAM')]
+final class CleanAntiSpamTest extends Framework\TestCase
+{
+ public static function setUpBeforeClass(): void
+ {
+ require_once __DIR__ . '/../../include/email-validation.inc';
+ }
+
+ #[Framework\Attributes\DataProvider('provideEmailAndExpectedEmail')]
+ public function testCleanAntiSpamReturnsCleanedEmail(
+ string $email,
+ string $expectedEmail,
+ ): void
+ {
+ $cleanedEmail = clean_AntiSPAM($email);
+
+ self::assertSame($expectedEmail, $cleanedEmail);
+ }
+
+ /**
+ * @return \Generator<string, array{0: string, 1: string}>
+ */
+ public static function provideEmailAndExpectedEmail(): \Generator
+ {
+ $values = [
+ 'asasasd324324@php.net' => 'asasasd324324@php.net',
+ 'jcastagnetto-delete-this-@yahoo.com' =>
'jcastagnetto@yahoo.com',
+ 'jcastagnetto-i-hate-spam@NOSPAMyahoo.com' =>
'jcastagnetto@yahoo.com',
+ 'jcastagnetto-NO-SPAM@yahoo.com' => 'jcastagnetto@yahoo.com',
+ 'jcastagnetto@NoSpam-yahoo.com' => 'jcastagnetto@yahoo.com',
+ 'jesusmc@scripps.edu' => 'jesusmc@scripps.edu',
+ 'jmcastagnetto@chek2.com' => 'jmcastagnetto@chek2.com',
+ 'jmcastagnetto@yahoo.com' => 'jmcastagnetto@yahoo.com',
+ 'some-wrong@asdas.com' => 'some-wrong@asdas.com',
+ 'wrong-address-with@@@@-remove_me-and-some-i-hate_SPAM-stuff' =>
'wrong-address-with@@@@and-somestuff',
+ 'wrong-email-address@lists.php.net' =>
'wrong-email-address@lists.php.net',
+ ];
+
+ foreach ($values as $email => $expectedEmail) {
+ yield $email => [
+ $email,
+ $expectedEmail,
+ ];
+ }
+ }
+}
diff --git a/tests/Unit/GenChallengeTest.php b/tests/Unit/GenChallengeTest.php
new file mode 100644
index 0000000000..a22e861312
--- /dev/null
+++ b/tests/Unit/GenChallengeTest.php
@@ -0,0 +1,160 @@
+<?php
+
+declare(strict_types=1);
+
+namespace phpweb\Test\Unit;
+
+use PHPUnit\Framework;
+
+#[Framework\Attributes\CoversFunction('gen_challenge')]
+#[Framework\Attributes\UsesFunction('gen_minus')]
+#[Framework\Attributes\UsesFunction('gen_plus')]
+#[Framework\Attributes\UsesFunction('print_infix')]
+#[Framework\Attributes\UsesFunction('print_prefix')]
+final class GenChallengeTest extends Framework\TestCase
+{
+ public static function setUpBeforeClass(): void
+ {
+ require_once __DIR__ . '/../../manual/spam_challenge.php';
+
+ mt_srand(9001);
+ }
+
+ public function testGenChallengeReturnsChallenge(): void {
+ $challenges = array_map(static function (): array {
+ [$function, $argumentOne, $argumentTwo, $question] = gen_challenge();
+
+ return [
+ 'function' => $function,
+ 'argumentOne' => $argumentOne,
+ 'argumentTwo' => $argumentTwo,
+ 'question' => $question,
+ ];
+ }, range(1, 20));
+
+ $expected = [
+ [
+ 'function' => 'min',
+ 'argumentOne' => 'two',
+ 'argumentTwo' => 'one',
+ 'question' => 'min(two, one)',
+ ],
+ [
+ 'function' => 'minus',
+ 'argumentOne' => 'five',
+ 'argumentTwo' => 'five',
+ 'question' => 'five minus five',
+ ],
+ [
+ 'function' => 'minus',
+ 'argumentOne' => 'four',
+ 'argumentTwo' => 'four',
+ 'question' => 'four minus four',
+ ],
+ [
+ 'function' => 'min',
+ 'argumentOne' => 'nine',
+ 'argumentTwo' => 'seven',
+ 'question' => 'min(nine, seven)',
+ ],
+ [
+ 'function' => 'minus',
+ 'argumentOne' => 'seven',
+ 'argumentTwo' => 'six',
+ 'question' => 'seven minus six',
+ ],
+ [
+ 'function' => 'max',
+ 'argumentOne' => 'three',
+ 'argumentTwo' => 'six',
+ 'question' => 'max(three, six)',
+ ],
+ [
+ 'function' => 'max',
+ 'argumentOne' => 'six',
+ 'argumentTwo' => 'five',
+ 'question' => 'max(six, five)',
+ ],
+ [
+ 'function' => 'max',
+ 'argumentOne' => 'four',
+ 'argumentTwo' => 'three',
+ 'question' => 'max(four, three)',
+ ],
+ [
+ 'function' => 'min',
+ 'argumentOne' => 'two',
+ 'argumentTwo' => 'nine',
+ 'question' => 'min(two, nine)',
+ ],
+ [
+ 'function' => 'plus',
+ 'argumentOne' => 'eight',
+ 'argumentTwo' => 'one',
+ 'question' => 'eight plus one',
+ ],
+ [
+ 'function' => 'plus',
+ 'argumentOne' => 'three',
+ 'argumentTwo' => 'five',
+ 'question' => 'three plus five',
+ ],
+ [
+ 'function' => 'min',
+ 'argumentOne' => 'eight',
+ 'argumentTwo' => 'three',
+ 'question' => 'min(eight, three)',
+ ],
+ [
+ 'function' => 'max',
+ 'argumentOne' => 'zero',
+ 'argumentTwo' => 'nine',
+ 'question' => 'max(zero, nine)',
+ ],
+ [
+ 'function' => 'min',
+ 'argumentOne' => 'five',
+ 'argumentTwo' => 'nine',
+ 'question' => 'min(five, nine)',
+ ],
+ [
+ 'function' => 'minus',
+ 'argumentOne' => 'six',
+ 'argumentTwo' => 'four',
+ 'question' => 'six minus four',
+ ],
+ [
+ 'function' => 'max',
+ 'argumentOne' => 'one',
+ 'argumentTwo' => 'one',
+ 'question' => 'max(one, one)',
+ ],
+ [
+ 'function' => 'plus',
+ 'argumentOne' => 'five',
+ 'argumentTwo' => 'zero',
+ 'question' => 'five plus zero',
+ ],
+ [
+ 'function' => 'minus',
+ 'argumentOne' => 'nine',
+ 'argumentTwo' => 'eight',
+ 'question' => 'nine minus eight',
+ ],
+ [
+ 'function' => 'minus',
+ 'argumentOne' => 'three',
+ 'argumentTwo' => 'one',
+ 'question' => 'three minus one',
+ ],
+ [
+ 'function' => 'min',
+ 'argumentOne' => 'three',
+ 'argumentTwo' => 'one',
+ 'question' => 'min(three, one)',
+ ],
+ ];
+
+ self::assertSame($expected, $challenges);
+ }
+}
diff --git a/tests/Unit/IsEmailableAddressTest.php b/tests/Unit/IsEmailableAddressTest.php
new file mode 100644
index 0000000000..900f356e1d
--- /dev/null
+++ b/tests/Unit/IsEmailableAddressTest.php
@@ -0,0 +1,73 @@
+<?php
+
+declare(strict_types=1);
+
+namespace phpweb\Test\Unit;
+
+use PHPUnit\Framework;
+
+#[Framework\Attributes\CoversFunction('is_emailable_address')]
+final class IsEmailableAddressTest extends Framework\TestCase
+{
+ public static function setUpBeforeClass(): void
+ {
+ require_once __DIR__ . '/../../include/email-validation.inc';
+ }
+
+ #[Framework\Attributes\DataProvider('provideInvalidEmail')]
+ public function testIsEmailableAddressReturnsFalseWhenEmailIsInvalid(string $email): void
+ {
+ $isEmailableAddress = is_emailable_address($email);
+
+ self::assertFalse($isEmailableAddress);
+ }
+
+ /**
+ * @return \Generator<string, array{0: string}>
+ */
+ public static function provideInvalidEmail(): \Generator
+ {
+ $values = [
+ 'jcastagnetto-i-hate-spam@NOSPAMyahoo.test',
+ 'jcastagnetto@NoSpam-yahoo.com',
+ 'jmcastagnetto@chek2.com',
+ 'wrong-address-with@@@@-remove_me-and-some-i-hate_SPAM-stuff',
+ 'wrong-email-address@lists.php.net',
+ ];
+
+ foreach ($values as $value) {
+ yield $value => [
+ $value,
+ ];
+ }
+ }
+
+ #[Framework\Attributes\DataProvider('provideValidEmail')]
+ public function testIsEmailableAddressReturnsTrueWhenEmailIsValid(string $email): void
+ {
+ $isEmailableAddress = is_emailable_address($email);
+
+ self::assertTrue($isEmailableAddress);
+ }
+
+ /**
+ * @return \Generator<string, array{0: string}>
+ */
+ public static function provideValidEmail(): \Generator
+ {
+ $values = [
+ 'asasasd324324@php.net',
+ 'jcastagnetto-delete-this-@yahoo.com',
+ 'jcastagnetto-NO-SPAM@yahoo.com',
+ 'jesusmc@scripps.edu',
+ 'jmcastagnetto@yahoo.com',
+ 'some-wrong@asdas.com',
+ ];
+
+ foreach ($values as $value) {
+ yield $value => [
+ $value,
+ ];
+ }
+ }
+}
diff --git a/tests/Unit/TestAnswerTest.php b/tests/Unit/TestAnswerTest.php
new file mode 100644
index 0000000000..a2ae710d63
--- /dev/null
+++ b/tests/Unit/TestAnswerTest.php
@@ -0,0 +1,101 @@
+<?php
+
+declare(strict_types=1);
+
+namespace phpweb\Test\Unit;
+
+use PHPUnit\Framework;
+
+#[Framework\Attributes\CoversFunction('test_answer')]
+#[Framework\Attributes\UsesFunction('minus')]
+#[Framework\Attributes\UsesFunction('plus')]
+final class TestAnswerTest extends Framework\TestCase
+{
+ public static function setUpBeforeClass(): void
+ {
+ require_once __DIR__ . '/../../manual/spam_challenge.php';
+ }
+
+
#[Framework\Attributes\DataProvider('provideFunctionArgumentsAnswerAndExpectedIsValid')]
+ public function testAnswerReturnsIsValid(
+ string $function,
+ string $argumentOne,
+ string $argumentTwo,
+ string $answer,
+ bool $expectedIsValid,
+ ): void {
+ $isValid = test_answer(
+ $function,
+ $argumentOne,
+ $argumentTwo,
+ $answer,
+ );
+
+ self::assertSame($expectedIsValid, $isValid);
+ }
+
+ /**
+ * @return array<int, array{function: string, argumentOne: string, argumentTwo: string,
answer: string, expectedIsValid: bool}>
+ */
+ public static function provideFunctionArgumentsAnswerAndExpectedIsValid(): array
+ {
+ return [
+ [
+ 'function' => 'max',
+ 'argumentOne' => 'two',
+ 'argumentTwo' => 'one',
+ 'answer' => 'two',
+ 'expectedIsValid' => true,
+ ],
+ [
+ 'function' => 'min',
+ 'argumentOne' => 'two',
+ 'argumentTwo' => 'one',
+ 'answer' => 'one',
+ 'expectedIsValid' => true,
+ ],
+ [
+ 'function' => 'minus',
+ 'argumentOne' => 'five',
+ 'argumentTwo' => 'five',
+ 'answer' => 'zero',
+ 'expectedIsValid' => true,
+ ],
+ [
+ 'function' => 'plus',
+ 'argumentOne' => 'eight',
+ 'argumentTwo' => 'one',
+ 'answer' => 'nine',
+ 'expectedIsValid' => true,
+ ],
+ [
+ 'function' => 'max',
+ 'argumentOne' => 'three',
+ 'argumentTwo' => 'six',
+ 'answer' => 'nine',
+ 'expectedIsValid' => false,
+ ],
+ [
+ 'function' => 'min',
+ 'argumentOne' => 'two',
+ 'argumentTwo' => 'nine',
+ 'answer' => 'seven',
+ 'expectedIsValid' => false,
+ ],
+ [
+ 'function' => 'minus',
+ 'argumentOne' => 'seven',
+ 'argumentTwo' => 'six',
+ 'answer' => 'four',
+ 'expectedIsValid' => false,
+ ],
+ [
+ 'function' => 'plus',
+ 'argumentOne' => 'eight',
+ 'argumentTwo' => 'one',
+ 'answer' => 'seven',
+ 'expectedIsValid' => false,
+ ],
+ ];
+ }
+}
diff --git a/tests/Unit/UserNotes/Sorter/sort-no-notes.phpt
b/tests/Unit/UserNotes/Sorter/sort-no-notes.phpt
deleted file mode 100644
index 891587b298..0000000000
--- a/tests/Unit/UserNotes/Sorter/sort-no-notes.phpt
+++ /dev/null
@@ -1,28 +0,0 @@
---TEST--
-sort no notes
---INI--
-precision=-1
---FILE--
-<?php
-
-use phpweb\UserNotes\Sorter;
-use phpweb\UserNotes\UserNote;
-
-require_once __DIR__ . "/../../../../src/autoload.php";
-
-$notes = [];
-
-$sorter = new Sorter();
-$sorter->sort($notes);
-var_dump(array_map(function (UserNote $note): array {
- return [
- "id" => $note->id,
- "ts" => $note->ts,
- "upvotes" => $note->upvotes,
- "downvotes" => $note->downvotes,
- ];
-}, $notes));
-?>
---EXPECT--
-array(0) {
-}
diff --git a/tests/Unit/UserNotes/Sorter/sort-notes-full.phpt
b/tests/Unit/UserNotes/Sorter/sort-notes-full.phpt
deleted file mode 100644
index b2d3790ec2..0000000000
--- a/tests/Unit/UserNotes/Sorter/sort-notes-full.phpt
+++ /dev/null
@@ -1,540 +0,0 @@
---TEST--
-sort sample notes from strpos notes
---INI--
-precision=-1
---FILE--
-<?php
-
-use phpweb\UserNotes\Sorter;
-use phpweb\UserNotes\UserNote;
-
-require_once __DIR__ . "/../../../../src/autoload.php";
-
-$file = file(__DIR__ . "/../../../../backend/notes/d7/d7742c269d23ea86");
-$notes = [];
-foreach ($file as $line) {
- @list($id, $sect, $rate, $ts, $user, $note, $up, $down) = explode("|", $line);
- $notes[$id] = new UserNote($id, $sect, $rate, $ts, $user, base64_decode($note, true), (int)
$up, (int) $down);
-}
-
-$sorter = new Sorter();
-$sorter->sort($notes);
-var_dump(array_map(function (UserNote $note): array {
- return [
- "id" => $note->id,
- "ts" => $note->ts,
- "upvotes" => $note->upvotes,
- "downvotes" => $note->downvotes,
- ];
-}, $notes));
-?>
---EXPECT--
-array(46) {
- [110464]=>
- array(4) {
- ["id"]=>
- string(6) "110464"
- ["ts"]=>
- string(10) "1351105628"
- ["upvotes"]=>
- int(10)
- ["downvotes"]=>
- int(2)
- }
- [93816]=>
- array(4) {
- ["id"]=>
- string(5) "93816"
- ["ts"]=>
- string(10) "1254343074"
- ["upvotes"]=>
- int(4)
- ["downvotes"]=>
- int(1)
- }
- [92849]=>
- array(4) {
- ["id"]=>
- string(5) "92849"
- ["ts"]=>
- string(10) "1249997359"
- ["upvotes"]=>
- int(4)
- ["downvotes"]=>
- int(1)
- }
- [70394]=>
- array(4) {
- ["id"]=>
- string(5) "70394"
- ["ts"]=>
- string(10) "1160823504"
- ["upvotes"]=>
- int(7)
- ["downvotes"]=>
- int(3)
- }
- [106407]=>
- array(4) {
- ["id"]=>
- string(6) "106407"
- ["ts"]=>
- string(10) "1320695958"
- ["upvotes"]=>
- int(5)
- ["downvotes"]=>
- int(2)
- }
- [87868]=>
- array(4) {
- ["id"]=>
- string(5) "87868"
- ["ts"]=>
- string(10) "1230396484"
- ["upvotes"]=>
- int(5)
- ["downvotes"]=>
- int(2)
- }
- [82229]=>
- array(4) {
- ["id"]=>
- string(5) "82229"
- ["ts"]=>
- string(10) "1207066654"
- ["upvotes"]=>
- int(3)
- ["downvotes"]=>
- int(1)
- }
- [80363]=>
- array(4) {
- ["id"]=>
- string(5) "80363"
- ["ts"]=>
- string(10) "1200066332"
- ["upvotes"]=>
- int(3)
- ["downvotes"]=>
- int(1)
- }
- [75146]=>
- array(4) {
- ["id"]=>
- string(5) "75146"
- ["ts"]=>
- string(10) "1179195708"
- ["upvotes"]=>
- int(3)
- ["downvotes"]=>
- int(1)
- }
- [102773]=>
- array(4) {
- ["id"]=>
- string(6) "102773"
- ["ts"]=>
- string(10) "1299300266"
- ["upvotes"]=>
- int(6)
- ["downvotes"]=>
- int(3)
- }
- [111422]=>
- array(4) {
- ["id"]=>
- string(6) "111422"
- ["ts"]=>
- string(10) "1361224553"
- ["upvotes"]=>
- int(4)
- ["downvotes"]=>
- int(2)
- }
- [94469]=>
- array(4) {
- ["id"]=>
- string(5) "94469"
- ["ts"]=>
- string(10) "1257516214"
- ["upvotes"]=>
- int(4)
- ["downvotes"]=>
- int(2)
- }
- [99476]=>
- array(4) {
- ["id"]=>
- string(5) "99476"
- ["ts"]=>
- string(10) "1282186230"
- ["upvotes"]=>
- int(2)
- ["downvotes"]=>
- int(1)
- }
- [99332]=>
- array(4) {
- ["id"]=>
- string(5) "99332"
- ["ts"]=>
- string(10) "1281503061"
- ["upvotes"]=>
- int(2)
- ["downvotes"]=>
- int(1)
- }
- [96926]=>
- array(4) {
- ["id"]=>
- string(5) "96926"
- ["ts"]=>
- string(10) "1269330508"
- ["upvotes"]=>
- int(2)
- ["downvotes"]=>
- int(1)
- }
- [93887]=>
- array(4) {
- ["id"]=>
- string(5) "93887"
- ["ts"]=>
- string(10) "1254733546"
- ["upvotes"]=>
- int(2)
- ["downvotes"]=>
- int(1)
- }
- [87061]=>
- array(4) {
- ["id"]=>
- string(5) "87061"
- ["ts"]=>
- string(10) "1226944352"
- ["upvotes"]=>
- int(2)
- ["downvotes"]=>
- int(1)
- }
- [85835]=>
- array(4) {
- ["id"]=>
- string(5) "85835"
- ["ts"]=>
- string(10) "1221823065"
- ["upvotes"]=>
- int(2)
- ["downvotes"]=>
- int(1)
- }
- [72466]=>
- array(4) {
- ["id"]=>
- string(5) "72466"
- ["ts"]=>
- string(10) "1169208947"
- ["upvotes"]=>
- int(2)
- ["downvotes"]=>
- int(1)
- }
- [69927]=>
- array(4) {
- ["id"]=>
- string(5) "69927"
- ["ts"]=>
- string(10) "1159299208"
- ["upvotes"]=>
- int(2)
- ["downvotes"]=>
- int(1)
- }
- [41762]=>
- array(4) {
- ["id"]=>
- string(5) "41762"
- ["ts"]=>
- string(10) "1082561916"
- ["upvotes"]=>
- int(2)
- ["downvotes"]=>
- int(1)
- }
- [107678]=>
- array(4) {
- ["id"]=>
- string(6) "107678"
- ["ts"]=>
- string(10) "1330185500"
- ["upvotes"]=>
- int(3)
- ["downvotes"]=>
- int(2)
- }
- [89788]=>
- array(4) {
- ["id"]=>
- string(5) "89788"
- ["ts"]=>
- string(10) "1237801686"
- ["upvotes"]=>
- int(3)
- ["downvotes"]=>
- int(2)
- }
- [74286]=>
- array(4) {
- ["id"]=>
- string(5) "74286"
- ["ts"]=>
- string(10) "1175594279"
- ["upvotes"]=>
- int(3)
- ["downvotes"]=>
- int(2)
- }
- [58688]=>
- array(4) {
- ["id"]=>
- string(5) "58688"
- ["ts"]=>
- string(10) "1131719326"
- ["upvotes"]=>
- int(3)
- ["downvotes"]=>
- int(2)
- }
- [45088]=>
- array(4) {
- ["id"]=>
- string(5) "45088"
- ["ts"]=>
- string(10) "1093449145"
- ["upvotes"]=>
- int(3)
- ["downvotes"]=>
- int(2)
- }
- [49739]=>
- array(4) {
- ["id"]=>
- string(5) "49739"
- ["ts"]=>
- string(10) "1107758025"
- ["upvotes"]=>
- int(2)
- ["downvotes"]=>
- int(0)
- }
- [108426]=>
- array(4) {
- ["id"]=>
- string(6) "108426"
- ["ts"]=>
- string(10) "1335372412"
- ["upvotes"]=>
- int(2)
- ["downvotes"]=>
- int(2)
- }
- [107240]=>
- array(4) {
- ["id"]=>
- string(6) "107240"
- ["ts"]=>
- string(10) "1327390683"
- ["upvotes"]=>
- int(2)
- ["downvotes"]=>
- int(2)
- }
- [105984]=>
- array(4) {
- ["id"]=>
- string(6) "105984"
- ["ts"]=>
- string(10) "1317340435"
- ["upvotes"]=>
- int(2)
- ["downvotes"]=>
- int(2)
- }
- [99440]=>
- array(4) {
- ["id"]=>
- string(5) "99440"
- ["ts"]=>
- string(10) "1282058725"
- ["upvotes"]=>
- int(4)
- ["downvotes"]=>
- int(4)
- }
- [93566]=>
- array(4) {
- ["id"]=>
- string(5) "93566"
- ["ts"]=>
- string(10) "1253094436"
- ["upvotes"]=>
- int(2)
- ["downvotes"]=>
- int(2)
- }
- [88798]=>
- array(4) {
- ["id"]=>
- string(5) "88798"
- ["ts"]=>
- string(10) "1234090865"
- ["upvotes"]=>
- int(1)
- ["downvotes"]=>
- int(1)
- }
- [84910]=>
- array(4) {
- ["id"]=>
- string(5) "84910"
- ["ts"]=>
- string(10) "1217938595"
- ["upvotes"]=>
- int(2)
- ["downvotes"]=>
- int(2)
- }
- [83914]=>
- array(4) {
- ["id"]=>
- string(5) "83914"
- ["ts"]=>
- string(10) "1213760931"
- ["upvotes"]=>
- int(1)
- ["downvotes"]=>
- int(1)
- }
- [78483]=>
- array(4) {
- ["id"]=>
- string(5) "78483"
- ["ts"]=>
- string(10) "1192337362"
- ["upvotes"]=>
- int(1)
- ["downvotes"]=>
- int(1)
- }
- [74763]=>
- array(4) {
- ["id"]=>
- string(5) "74763"
- ["ts"]=>
- string(10) "1177577911"
- ["upvotes"]=>
- int(1)
- ["downvotes"]=>
- int(1)
- }
- [74432]=>
- array(4) {
- ["id"]=>
- string(5) "74432"
- ["ts"]=>
- string(10) "1176269720"
- ["upvotes"]=>
- int(1)
- ["downvotes"]=>
- int(1)
- }
- [47879]=>
- array(4) {
- ["id"]=>
- string(5) "47879"
- ["ts"]=>
- string(10) "1102066114"
- ["upvotes"]=>
- int(1)
- ["downvotes"]=>
- int(1)
- }
- [40617]=>
- array(4) {
- ["id"]=>
- string(5) "40617"
- ["ts"]=>
- string(10) "1078853206"
- ["upvotes"]=>
- int(0)
- ["downvotes"]=>
- int(0)
- }
- [38375]=>
- array(4) {
- ["id"]=>
- string(5) "38375"
- ["ts"]=>
- string(10) "1071743640"
- ["upvotes"]=>
- int(1)
- ["downvotes"]=>
- int(1)
- }
- [106295]=>
- array(4) {
- ["id"]=>
- string(6) "106295"
- ["ts"]=>
- string(10) "1319574977"
- ["upvotes"]=>
- int(2)
- ["downvotes"]=>
- int(3)
- }
- [95875]=>
- array(4) {
- ["id"]=>
- string(5) "95875"
- ["ts"]=>
- string(10) "1264517173"
- ["upvotes"]=>
- int(2)
- ["downvotes"]=>
- int(3)
- }
- [102336]=>
- array(4) {
- ["id"]=>
- string(6) "102336"
- ["ts"]=>
- string(10) "1297217360"
- ["upvotes"]=>
- int(1)
- ["downvotes"]=>
- int(2)
- }
- [93781]=>
- array(4) {
- ["id"]=>
- string(5) "93781"
- ["ts"]=>
- string(10) "1254189367"
- ["upvotes"]=>
- int(1)
- ["downvotes"]=>
- int(2)
- }
- [90065]=>
- array(4) {
- ["id"]=>
- string(5) "90065"
- ["ts"]=>
- string(10) "1238827503"
- ["upvotes"]=>
- int(1)
- ["downvotes"]=>
- int(2)
- }
-}
-
diff --git a/tests/Unit/UserNotes/Sorter/sort-single-note-with-no-votes.phpt
b/tests/Unit/UserNotes/Sorter/sort-single-note-with-no-votes.phpt
deleted file mode 100644
index d90e710cfe..0000000000
--- a/tests/Unit/UserNotes/Sorter/sort-single-note-with-no-votes.phpt
+++ /dev/null
@@ -1,41 +0,0 @@
---TEST--
-sort a single note with no votes
---INI--
-precision=-1
---FILE--
-<?php
-
-use phpweb\UserNotes\Sorter;
-use phpweb\UserNotes\UserNote;
-
-require_once __DIR__ . "/../../../../src/autoload.php";
-
-$notes = [
- new UserNote('1', '', '', '1613487094', '',
'', 0, 0),
-];
-
-$sorter = new Sorter();
-$sorter->sort($notes);
-var_dump(array_map(function (UserNote $note): array {
- return [
- "id" => $note->id,
- "ts" => $note->ts,
- "upvotes" => $note->upvotes,
- "downvotes" => $note->downvotes,
- ];
-}, $notes));
-?>
---EXPECT--
-array(1) {
- [0]=>
- array(4) {
- ["id"]=>
- string(1) "1"
- ["ts"]=>
- string(10) "1613487094"
- ["upvotes"]=>
- int(0)
- ["downvotes"]=>
- int(0)
- }
-}
diff --git a/tests/Unit/UserNotes/Sorter/sort-some-notes.phpt
b/tests/Unit/UserNotes/Sorter/sort-some-notes.phpt
deleted file mode 100644
index 9782e362af..0000000000
--- a/tests/Unit/UserNotes/Sorter/sort-some-notes.phpt
+++ /dev/null
@@ -1,77 +0,0 @@
---TEST--
-sort some notes
---INI--
-precision=-1
---FILE--
-<?php
-
-use phpweb\UserNotes\Sorter;
-use phpweb\UserNotes\UserNote;
-
-require_once __DIR__ . "/../../../../src/autoload.php";
-
-$notes = [
- new UserNote('1', '', '', '1613487094', '',
'', 0, 2),
- new UserNote('2', '', '', '1508180150', '',
'', 0, 0),
- new UserNote('3', '', '', '1508179844', '',
'', 14, 3),
- new UserNote('4', '', '', '1508179844', '',
'', 14, 3),
-];
-
-$sorter = new Sorter();
-$sorter->sort($notes);
-var_dump(array_map(function (UserNote $note): array {
- return [
- "id" => $note->id,
- "ts" => $note->ts,
- "upvotes" => $note->upvotes,
- "downvotes" => $note->downvotes,
- ];
-}, $notes));
-?>
---EXPECT--
-array(4) {
- [2]=>
- array(4) {
- ["id"]=>
- string(1) "3"
- ["ts"]=>
- string(10) "1508179844"
- ["upvotes"]=>
- int(14)
- ["downvotes"]=>
- int(3)
- }
- [3]=>
- array(4) {
- ["id"]=>
- string(1) "4"
- ["ts"]=>
- string(10) "1508179844"
- ["upvotes"]=>
- int(14)
- ["downvotes"]=>
- int(3)
- }
- [1]=>
- array(4) {
- ["id"]=>
- string(1) "2"
- ["ts"]=>
- string(10) "1508180150"
- ["upvotes"]=>
- int(0)
- ["downvotes"]=>
- int(0)
- }
- [0]=>
- array(4) {
- ["id"]=>
- string(1) "1"
- ["ts"]=>
- string(10) "1613487094"
- ["upvotes"]=>
- int(0)
- ["downvotes"]=>
- int(2)
- }
-}
diff --git a/tests/Unit/UserNotes/SorterTest.php b/tests/Unit/UserNotes/SorterTest.php
new file mode 100644
index 0000000000..16d3f60aa9
--- /dev/null
+++ b/tests/Unit/UserNotes/SorterTest.php
@@ -0,0 +1,409 @@
+<?php
+
+declare(strict_types=1);
+
+namespace phpweb\Test\Unit\UserNotes;
+
+use PHPUnit\Framework;
+use phpweb\UserNotes\Sorter;
+use phpweb\UserNotes\UserNote;
+
+#[Framework\Attributes\CoversClass(Sorter::class)]
+#[Framework\Attributes\UsesClass(UserNote::class)]
+final class SorterTest extends Framework\TestCase
+{
+ public function testSortSortsNotesWhenNotesAreEmpty(): void
+ {
+ $notes = [];
+
+ $sorter = new Sorter();
+
+ $sorter->sort($notes);
+
+ self::assertSame([], $notes);
+ }
+
+ public function testSortSortsSingleNoteWithNoVotes(): void
+ {
+ $notes = [
+ new UserNote('1', '', '', '1613487094',
'', '', 0, 0),
+ ];
+
+ $sorter = new Sorter();
+
+ $sorter->sort($notes);
+
+ $normalized = array_map(static function (UserNote $note): array {
+ return self::normalize($note);
+ }, $notes);
+
+ $expected = [
+ 0 => [
+ 'downvotes' => 0,
+ 'id' => '1',
+ 'ts' => '1613487094',
+ 'upvotes' => 0,
+ ],
+ ];
+
+ self::assertSame($expected, $normalized);
+ }
+
+ public function testSortSortsSomeNotes(): void
+ {
+ $notes = [
+ new UserNote('1', '', '', '1613487094',
'', '', 0, 2),
+ new UserNote('2', '', '', '1508180150',
'', '', 0, 0),
+ new UserNote('3', '', '', '1508179844',
'', '', 14, 3),
+ new UserNote('4', '', '', '1508179844',
'', '', 14, 3),
+ ];
+
+ $sorter = new Sorter();
+
+ $sorter->sort($notes);
+
+ $normalized = array_map(static function (UserNote $note): array {
+ return self::normalize($note);
+ }, $notes);
+
+ $expected = [
+ 2 => [
+ 'downvotes' => 3,
+ 'id' => '3',
+ 'ts' => '1508179844',
+ 'upvotes' => 14,
+ ],
+ 3 => [
+ 'downvotes' => 3,
+ 'id' => '4',
+ 'ts' => '1508179844',
+ 'upvotes' => 14,
+ ],
+ 1 => [
+ 'downvotes' => 0,
+ 'id' => '2',
+ 'ts' => '1508180150',
+ 'upvotes' => 0,
+ ],
+ 0 => [
+ 'downvotes' => 2,
+ 'id' => '1',
+ 'ts' => '1613487094',
+ 'upvotes' => 0,
+ ],
+ ];
+
+ self::assertSame($expected, $normalized);
+ }
+
+ public function testSortSortsFullNotes(): void
+ {
+ $file = file(__DIR__ . '/../../../backend/notes/d7/d7742c269d23ea86');
+
+ $notes = [];
+
+ foreach ($file as $line) {
+ @list($id, $sect, $rate, $ts, $user, $note, $up, $down) = explode('|',
$line);
+ $notes[$id] = new UserNote($id, $sect, $rate, $ts, $user, base64_decode($note, true),
(int) $up, (int) $down);
+ }
+
+ $sorter = new Sorter();
+
+ $sorter->sort($notes);
+
+ $normalized = array_map(static function (UserNote $note): array {
+ return self::normalize($note);
+ }, $notes);
+
+ $expected = [
+ 110464 => [
+ 'downvotes' => 2,
+ 'id' => '110464',
+ 'ts' => '1351105628',
+ 'upvotes' => 10,
+ ],
+ 93816 => [
+ 'downvotes' => 1,
+ 'id' => '93816',
+ 'ts' => '1254343074',
+ 'upvotes' => 4,
+ ],
+ 92849 => [
+ 'downvotes' => 1,
+ 'id' => '92849',
+ 'ts' => '1249997359',
+ 'upvotes' => 4,
+ ],
+ 70394 => [
+ 'downvotes' => 3,
+ 'id' => '70394',
+ 'ts' => '1160823504',
+ 'upvotes' => 7,
+ ],
+ 106407 => [
+ 'downvotes' => 2,
+ 'id' => '106407',
+ 'ts' => '1320695958',
+ 'upvotes' => 5,
+ ],
+ 87868 => [
+ 'downvotes' => 2,
+ 'id' => '87868',
+ 'ts' => '1230396484',
+ 'upvotes' => 5,
+ ],
+ 82229 => [
+ 'downvotes' => 1,
+ 'id' => '82229',
+ 'ts' => '1207066654',
+ 'upvotes' => 3,
+ ],
+ 80363 => [
+ 'downvotes' => 1,
+ 'id' => '80363',
+ 'ts' => '1200066332',
+ 'upvotes' => 3,
+ ],
+ 75146 => [
+ 'downvotes' => 1,
+ 'id' => '75146',
+ 'ts' => '1179195708',
+ 'upvotes' => 3,
+ ],
+ 102773 => [
+ 'downvotes' => 3,
+ 'id' => '102773',
+ 'ts' => '1299300266',
+ 'upvotes' => 6,
+ ],
+ 111422 => [
+ 'downvotes' => 2,
+ 'id' => '111422',
+ 'ts' => '1361224553',
+ 'upvotes' => 4,
+ ],
+ 94469 => [
+ 'downvotes' => 2,
+ 'id' => '94469',
+ 'ts' => '1257516214',
+ 'upvotes' => 4,
+ ],
+ 99476 => [
+ 'downvotes' => 1,
+ 'id' => '99476',
+ 'ts' => '1282186230',
+ 'upvotes' => 2,
+ ],
+ 99332 => [
+ 'downvotes' => 1,
+ 'id' => '99332',
+ 'ts' => '1281503061',
+ 'upvotes' => 2,
+ ],
+ 96926 => [
+ 'downvotes' => 1,
+ 'id' => '96926',
+ 'ts' => '1269330508',
+ 'upvotes' => 2,
+ ],
+ 93887 => [
+ 'downvotes' => 1,
+ 'id' => '93887',
+ 'ts' => '1254733546',
+ 'upvotes' => 2,
+ ],
+ 87061 => [
+ 'downvotes' => 1,
+ 'id' => '87061',
+ 'ts' => '1226944352',
+ 'upvotes' => 2,
+ ],
+ 85835 => [
+ 'downvotes' => 1,
+ 'id' => '85835',
+ 'ts' => '1221823065',
+ 'upvotes' => 2,
+ ],
+ 72466 => [
+ 'downvotes' => 1,
+ 'id' => '72466',
+ 'ts' => '1169208947',
+ 'upvotes' => 2,
+ ],
+ 69927 => [
+ 'downvotes' => 1,
+ 'id' => '69927',
+ 'ts' => '1159299208',
+ 'upvotes' => 2,
+ ],
+ 41762 => [
+ 'downvotes' => 1,
+ 'id' => '41762',
+ 'ts' => '1082561916',
+ 'upvotes' => 2,
+ ],
+ 107678 => [
+ 'downvotes' => 2,
+ 'id' => '107678',
+ 'ts' => '1330185500',
+ 'upvotes' => 3,
+ ],
+ 89788 => [
+ 'downvotes' => 2,
+ 'id' => '89788',
+ 'ts' => '1237801686',
+ 'upvotes' => 3,
+ ],
+ 74286 => [
+ 'downvotes' => 2,
+ 'id' => '74286',
+ 'ts' => '1175594279',
+ 'upvotes' => 3,
+ ],
+ 58688 => [
+ 'downvotes' => 2,
+ 'id' => '58688',
+ 'ts' => '1131719326',
+ 'upvotes' => 3,
+ ],
+ 45088 => [
+ 'downvotes' => 2,
+ 'id' => '45088',
+ 'ts' => '1093449145',
+ 'upvotes' => 3,
+ ],
+ 49739 => [
+ 'downvotes' => 0,
+ 'id' => '49739',
+ 'ts' => '1107758025',
+ 'upvotes' => 2,
+ ],
+ 108426 => [
+ 'downvotes' => 2,
+ 'id' => '108426',
+ 'ts' => '1335372412',
+ 'upvotes' => 2,
+ ],
+ 107240 => [
+ 'downvotes' => 2,
+ 'id' => '107240',
+ 'ts' => '1327390683',
+ 'upvotes' => 2,
+ ],
+ 105984 => [
+ 'downvotes' => 2,
+ 'id' => '105984',
+ 'ts' => '1317340435',
+ 'upvotes' => 2,
+ ],
+ 99440 => [
+ 'downvotes' => 4,
+ 'id' => '99440',
+ 'ts' => '1282058725',
+ 'upvotes' => 4,
+ ],
+ 93566 => [
+ 'downvotes' => 2,
+ 'id' => '93566',
+ 'ts' => '1253094436',
+ 'upvotes' => 2,
+ ],
+ 88798 => [
+ 'downvotes' => 1,
+ 'id' => '88798',
+ 'ts' => '1234090865',
+ 'upvotes' => 1,
+ ],
+ 84910 => [
+ 'downvotes' => 2,
+ 'id' => '84910',
+ 'ts' => '1217938595',
+ 'upvotes' => 2,
+ ],
+ 83914 => [
+ 'downvotes' => 1,
+ 'id' => '83914',
+ 'ts' => '1213760931',
+ 'upvotes' => 1,
+ ],
+ 78483 => [
+ 'downvotes' => 1,
+ 'id' => '78483',
+ 'ts' => '1192337362',
+ 'upvotes' => 1,
+ ],
+ 74763 => [
+ 'downvotes' => 1,
+ 'id' => '74763',
+ 'ts' => '1177577911',
+ 'upvotes' => 1,
+ ],
+ 74432 => [
+ 'downvotes' => 1,
+ 'id' => '74432',
+ 'ts' => '1176269720',
+ 'upvotes' => 1,
+ ],
+ 47879 => [
+ 'downvotes' => 1,
+ 'id' => '47879',
+ 'ts' => '1102066114',
+ 'upvotes' => 1,
+ ],
+ 40617 => [
+ 'downvotes' => 0,
+ 'id' => '40617',
+ 'ts' => '1078853206',
+ 'upvotes' => 0,
+ ],
+ 38375 => [
+ 'downvotes' => 1,
+ 'id' => '38375',
+ 'ts' => '1071743640',
+ 'upvotes' => 1,
+ ],
+ 106295 => [
+ 'downvotes' => 3,
+ 'id' => '106295',
+ 'ts' => '1319574977',
+ 'upvotes' => 2,
+ ],
+ 95875 => [
+ 'downvotes' => 3,
+ 'id' => '95875',
+ 'ts' => '1264517173',
+ 'upvotes' => 2,
+ ],
+ 102336 => [
+ 'downvotes' => 2,
+ 'id' => '102336',
+ 'ts' => '1297217360',
+ 'upvotes' => 1,
+ ],
+ 93781 => [
+ 'downvotes' => 2,
+ 'id' => '93781',
+ 'ts' => '1254189367',
+ 'upvotes' => 1,
+ ],
+ 90065 => [
+ 'downvotes' => 2,
+ 'id' => '90065',
+ 'ts' => '1238827503',
+ 'upvotes' => 1,
+ ],
+ ];
+
+ self::assertSame($expected, $normalized);
+ }
+
+ private static function normalize(UserNote $note): array
+ {
+ return [
+ 'downvotes' => $note->downvotes,
+ 'id' => $note->id,
+ 'ts' => $note->ts,
+ 'upvotes' => $note->upvotes,
+ ];
+ }
+}
diff --git a/tests/Unit/clean-anti-spam.phpt b/tests/Unit/clean-anti-spam.phpt
deleted file mode 100644
index 3a4c1f7c0c..0000000000
--- a/tests/Unit/clean-anti-spam.phpt
+++ /dev/null
@@ -1,53 +0,0 @@
---TEST--
-clean_AntiSPAM() removes spam terms
---FILE--
-<?php
-
-require_once __DIR__ . '/../../include/email-validation.inc';
-
-$emails = array (
- 'asasasd324324@php.net',
- 'jcastagnetto-delete-this-@yahoo.com',
- 'jcastagnetto-i-hate-spam@NOSPAMyahoo.com',
- 'jcastagnetto-NO-SPAM@yahoo.com',
- 'jcastagnetto@NoSpam-yahoo.com',
- 'jesusmc@scripps.edu',
- 'jmcastagnetto@chek2.com',
- 'jmcastagnetto@yahoo.com',
- 'some-wrong@asdas.com',
- 'wrong-address-with@@@@-remove_me-and-some-i-hate_SPAM-stuff',
- 'wrong-email-address@lists.php.net',
-);
-
-$cleanedEmails = array_map(static function (string $email): string {
- return clean_AntiSPAM($email);
-}, $emails);
-
-var_dump($cleanedEmails);
-
-?>
---EXPECT--
-array(11) {
- [0]=>
- string(21) "asasasd324324@php.net"
- [1]=>
- string(22) "jcastagnetto@yahoo.com"
- [2]=>
- string(22) "jcastagnetto@yahoo.com"
- [3]=>
- string(22) "jcastagnetto@yahoo.com"
- [4]=>
- string(22) "jcastagnetto@yahoo.com"
- [5]=>
- string(19) "jesusmc@scripps.edu"
- [6]=>
- string(23) "jmcastagnetto@chek2.com"
- [7]=>
- string(23) "jmcastagnetto@yahoo.com"
- [8]=>
- string(20) "some-wrong@asdas.com"
- [9]=>
- string(35) "wrong-address-with@@@@and-somestuff"
- [10]=>
- string(33) "wrong-email-address@lists.php.net"
-}
diff --git a/tests/Unit/gen-challenge.phpt b/tests/Unit/gen-challenge.phpt
deleted file mode 100644
index 54cb864ef6..0000000000
--- a/tests/Unit/gen-challenge.phpt
+++ /dev/null
@@ -1,246 +0,0 @@
---TEST--
-gen_challenge() generates a spam challenge
---FILE--
-<?php
-
-require_once __DIR__ . '/../../manual/spam_challenge.php';
-
-mt_srand(9001);
-
-$challenges = array_map(static function (): array {
- [$function, $argumentOne, $argumentTwo, $question] = gen_challenge();
-
- return [
- 'function' => $function,
- 'argumentOne' => $argumentOne,
- 'argumentTwo' => $argumentTwo,
- 'question' => $question,
- ];
-}, range(1, 20));
-
-var_dump($challenges);
-
-?>
---EXPECT--
-array(20) {
- [0]=>
- array(4) {
- ["function"]=>
- string(3) "min"
- ["argumentOne"]=>
- string(3) "two"
- ["argumentTwo"]=>
- string(3) "one"
- ["question"]=>
- string(13) "min(two, one)"
- }
- [1]=>
- array(4) {
- ["function"]=>
- string(5) "minus"
- ["argumentOne"]=>
- string(4) "five"
- ["argumentTwo"]=>
- string(4) "five"
- ["question"]=>
- string(15) "five minus five"
- }
- [2]=>
- array(4) {
- ["function"]=>
- string(5) "minus"
- ["argumentOne"]=>
- string(4) "four"
- ["argumentTwo"]=>
- string(4) "four"
- ["question"]=>
- string(15) "four minus four"
- }
- [3]=>
- array(4) {
- ["function"]=>
- string(3) "min"
- ["argumentOne"]=>
- string(4) "nine"
- ["argumentTwo"]=>
- string(5) "seven"
- ["question"]=>
- string(16) "min(nine, seven)"
- }
- [4]=>
- array(4) {
- ["function"]=>
- string(5) "minus"
- ["argumentOne"]=>
- string(5) "seven"
- ["argumentTwo"]=>
- string(3) "six"
- ["question"]=>
- string(15) "seven minus six"
- }
- [5]=>
- array(4) {
- ["function"]=>
- string(3) "max"
- ["argumentOne"]=>
- string(5) "three"
- ["argumentTwo"]=>
- string(3) "six"
- ["question"]=>
- string(15) "max(three, six)"
- }
- [6]=>
- array(4) {
- ["function"]=>
- string(3) "max"
- ["argumentOne"]=>
- string(3) "six"
- ["argumentTwo"]=>
- string(4) "five"
- ["question"]=>
- string(14) "max(six, five)"
- }
- [7]=>
- array(4) {
- ["function"]=>
- string(3) "max"
- ["argumentOne"]=>
- string(4) "four"
- ["argumentTwo"]=>
- string(5) "three"
- ["question"]=>
- string(16) "max(four, three)"
- }
- [8]=>
- array(4) {
- ["function"]=>
- string(3) "min"
- ["argumentOne"]=>
- string(3) "two"
- ["argumentTwo"]=>
- string(4) "nine"
- ["question"]=>
- string(14) "min(two, nine)"
- }
- [9]=>
- array(4) {
- ["function"]=>
- string(4) "plus"
- ["argumentOne"]=>
- string(5) "eight"
- ["argumentTwo"]=>
- string(3) "one"
- ["question"]=>
- string(14) "eight plus one"
- }
- [10]=>
- array(4) {
- ["function"]=>
- string(4) "plus"
- ["argumentOne"]=>
- string(5) "three"
- ["argumentTwo"]=>
- string(4) "five"
- ["question"]=>
- string(15) "three plus five"
- }
- [11]=>
- array(4) {
- ["function"]=>
- string(3) "min"
- ["argumentOne"]=>
- string(5) "eight"
- ["argumentTwo"]=>
- string(5) "three"
- ["question"]=>
- string(17) "min(eight, three)"
- }
- [12]=>
- array(4) {
- ["function"]=>
- string(3) "max"
- ["argumentOne"]=>
- string(4) "zero"
- ["argumentTwo"]=>
- string(4) "nine"
- ["question"]=>
- string(15) "max(zero, nine)"
- }
- [13]=>
- array(4) {
- ["function"]=>
- string(3) "min"
- ["argumentOne"]=>
- string(4) "five"
- ["argumentTwo"]=>
- string(4) "nine"
- ["question"]=>
- string(15) "min(five, nine)"
- }
- [14]=>
- array(4) {
- ["function"]=>
- string(5) "minus"
- ["argumentOne"]=>
- string(3) "six"
- ["argumentTwo"]=>
- string(4) "four"
- ["question"]=>
- string(14) "six minus four"
- }
- [15]=>
- array(4) {
- ["function"]=>
- string(3) "max"
- ["argumentOne"]=>
- string(3) "one"
- ["argumentTwo"]=>
- string(3) "one"
- ["question"]=>
- string(13) "max(one, one)"
- }
- [16]=>
- array(4) {
- ["function"]=>
- string(4) "plus"
- ["argumentOne"]=>
- string(4) "five"
- ["argumentTwo"]=>
- string(4) "zero"
- ["question"]=>
- string(14) "five plus zero"
- }
- [17]=>
- array(4) {
- ["function"]=>
- string(5) "minus"
- ["argumentOne"]=>
- string(4) "nine"
- ["argumentTwo"]=>
- string(5) "eight"
- ["question"]=>
- string(16) "nine minus eight"
- }
- [18]=>
- array(4) {
- ["function"]=>
- string(5) "minus"
- ["argumentOne"]=>
- string(5) "three"
- ["argumentTwo"]=>
- string(3) "one"
- ["question"]=>
- string(15) "three minus one"
- }
- [19]=>
- array(4) {
- ["function"]=>
- string(3) "min"
- ["argumentOne"]=>
- string(5) "three"
- ["argumentTwo"]=>
- string(3) "one"
- ["question"]=>
- string(15) "min(three, one)"
- }
-}
diff --git a/tests/Unit/is-emailable-address.phpt b/tests/Unit/is-emailable-address.phpt
deleted file mode 100644
index d5c39d531b..0000000000
--- a/tests/Unit/is-emailable-address.phpt
+++ /dev/null
@@ -1,43 +0,0 @@
---TEST--
-is_emailable_address() returns whether email is emailable
---FILE--
-<?php
-
-require_once __DIR__ . '/../../include/email-validation.inc';
-
-$emails = array(
- 'asasasd324324@php.net',
- 'jcastagnetto-delete-this-@yahoo.com',
- 'jcastagnetto-i-hate-spam@NOSPAMyahoo.test',
- 'jcastagnetto-NO-SPAM@yahoo.com',
- 'jcastagnetto@NoSpam-yahoo.com',
- 'jesusmc@scripps.edu',
- 'jmcastagnetto@chek2.com',
- 'jmcastagnetto@yahoo.com',
- 'some-wrong@asdas.com',
- 'wrong-address-with@@@@-remove_me-and-some-i-hate_SPAM-stuff',
- 'wrong-email-address@lists.php.net',
-);
-
-$emailsThatAreEmailableAddresses = array_filter($emails, static function (string $email): bool {
- return is_emailable_address($email);
-});
-
-var_dump($emailsThatAreEmailableAddresses);
-
-?>
---EXPECT--
-array(6) {
- [0]=>
- string(21) "asasasd324324@php.net"
- [1]=>
- string(35) "jcastagnetto-delete-this-@yahoo.com"
- [3]=>
- string(30) "jcastagnetto-NO-SPAM@yahoo.com"
- [5]=>
- string(19) "jesusmc@scripps.edu"
- [7]=>
- string(23) "jmcastagnetto@yahoo.com"
- [8]=>
- string(20) "some-wrong@asdas.com"
-}
diff --git a/tests/Unit/test-answer.phpt b/tests/Unit/test-answer.phpt
deleted file mode 100644
index f3bfcd402c..0000000000
--- a/tests/Unit/test-answer.phpt
+++ /dev/null
@@ -1,211 +0,0 @@
---TEST--
-test_answer() returns true when answer to spam challenge is valid
---FILE--
-<?php
-
-require_once __DIR__ . '/../../manual/spam_challenge.php';
-
-$answers = [
- [
- 'function' => 'max',
- 'argumentOne' => 'two',
- 'argumentTwo' => 'one',
- 'question' => 'max(two, one)',
- 'answer' => 'two',
- 'isValid' => true,
- ],
- [
- 'function' => 'min',
- 'argumentOne' => 'two',
- 'argumentTwo' => 'one',
- 'question' => 'min(two, one)',
- 'answer' => 'one',
- 'isValid' => true,
- ],
- [
- 'function' => 'minus',
- 'argumentOne' => 'five',
- 'argumentTwo' => 'five',
- 'question' => 'minus(five, five)',
- 'answer' => 'zero',
- 'isValid' => true,
- ],
- [
- 'function' => 'plus',
- 'argumentOne' => 'eight',
- 'argumentTwo' => 'one',
- 'question' => 'plus(eight, one)',
- 'answer' => 'nine',
- 'isValid' => true,
- ],
- [
- 'function' => 'max',
- 'argumentOne' => 'three',
- 'argumentTwo' => 'six',
- 'question' => 'max(three, six)',
- 'answer' => 'nine',
- 'isValid' => false,
- ],
- [
- 'function' => 'min',
- 'argumentOne' => 'two',
- 'argumentTwo' => 'nine',
- 'question' => 'min(two, nine)',
- 'answer' => 'seven',
- 'isValid' => false,
- ],
- [
- 'function' => 'minus',
- 'argumentOne' => 'seven',
- 'argumentTwo' => 'six',
- 'question' => 'minus(seven, six)',
- 'answer' => 'four',
- 'isValid' => false,
- ],
- [
- 'function' => 'plus',
- 'argumentOne' => 'eight',
- 'argumentTwo' => 'one',
- 'question' => 'plus(eight, one)',
- 'answer' => 'seven',
- 'isValid' => false,
- ],
-];
-
-$results = array_map(static function (array $answer): array {
- $answer['isValid'] = test_answer(
- $answer['function'],
- $answer['argumentOne'],
- $answer['argumentTwo'],
- $answer['answer']
- );
-
- return $answer;
-}, $answers);
-
-var_dump($results);
-
-?>
---EXPECT--
-array(8) {
- [0]=>
- array(6) {
- ["function"]=>
- string(3) "max"
- ["argumentOne"]=>
- string(3) "two"
- ["argumentTwo"]=>
- string(3) "one"
- ["question"]=>
- string(13) "max(two, one)"
- ["answer"]=>
- string(3) "two"
- ["isValid"]=>
- bool(true)
- }
- [1]=>
- array(6) {
- ["function"]=>
- string(3) "min"
- ["argumentOne"]=>
- string(3) "two"
- ["argumentTwo"]=>
- string(3) "one"
- ["question"]=>
- string(13) "min(two, one)"
- ["answer"]=>
- string(3) "one"
- ["isValid"]=>
- bool(true)
- }
- [2]=>
- array(6) {
- ["function"]=>
- string(5) "minus"
- ["argumentOne"]=>
- string(4) "five"
- ["argumentTwo"]=>
- string(4) "five"
- ["question"]=>
- string(17) "minus(five, five)"
- ["answer"]=>
- string(4) "zero"
- ["isValid"]=>
- bool(true)
- }
- [3]=>
- array(6) {
- ["function"]=>
- string(4) "plus"
- ["argumentOne"]=>
- string(5) "eight"
- ["argumentTwo"]=>
- string(3) "one"
- ["question"]=>
- string(16) "plus(eight, one)"
- ["answer"]=>
- string(4) "nine"
- ["isValid"]=>
- bool(true)
- }
- [4]=>
- array(6) {
- ["function"]=>
- string(3) "max"
- ["argumentOne"]=>
- string(5) "three"
- ["argumentTwo"]=>
- string(3) "six"
- ["question"]=>
- string(15) "max(three, six)"
- ["answer"]=>
- string(4) "nine"
- ["isValid"]=>
- bool(false)
- }
- [5]=>
- array(6) {
- ["function"]=>
- string(3) "min"
- ["argumentOne"]=>
- string(3) "two"
- ["argumentTwo"]=>
- string(4) "nine"
- ["question"]=>
- string(14) "min(two, nine)"
- ["answer"]=>
- string(5) "seven"
- ["isValid"]=>
- bool(false)
- }
- [6]=>
- array(6) {
- ["function"]=>
- string(5) "minus"
- ["argumentOne"]=>
- string(5) "seven"
- ["argumentTwo"]=>
- string(3) "six"
- ["question"]=>
- string(17) "minus(seven, six)"
- ["answer"]=>
- string(4) "four"
- ["isValid"]=>
- bool(false)
- }
- [7]=>
- array(6) {
- ["function"]=>
- string(4) "plus"
- ["argumentOne"]=>
- string(5) "eight"
- ["argumentTwo"]=>
- string(3) "one"
- ["question"]=>
- string(16) "plus(eight, one)"
- ["answer"]=>
- string(5) "seven"
- ["isValid"]=>
- bool(false)
- }
-}
diff --git a/tests/phpunit.xml b/tests/phpunit.xml
index 3eac985e8a..5e81e856f0 100644
--- a/tests/phpunit.xml
+++ b/tests/phpunit.xml
@@ -27,6 +27,8 @@
<coverage includeUncoveredFiles="true"/>
<source>
<include>
+ <directory suffix=".php">../manual/</directory>
+ <directory suffix=".inc">../include/</directory>
<directory suffix=".php">../src/</directory>
</include>
</source>
@@ -35,7 +37,7 @@
<directory suffix=".php">EndToEnd/</directory>
</testsuite>
<testsuite name="unit">
- <directory suffix=".phpt">Unit/</directory>
+ <directory suffix=".php">Unit/</directory>
</testsuite>
</testsuites>
</phpunit>