From 42c969c6969f830713e73390fe81372d849c14d9 Mon Sep 17 00:00:00 2001 From: Version Bot Date: Tue, 2 Jul 2024 10:32:54 +0000 Subject: [PATCH] to get an understanding on what happens within the loop I added an additional test --- php/phpunit.xml | 1 + php/tests/vaas/StreamsInLoopTest.php | 52 ++++++++++++++++++++++++++++ php/tests/vaas/VaasTest.php | 9 ++--- php/tests/vaas/phpunit.xml | 1 + 4 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 php/tests/vaas/StreamsInLoopTest.php diff --git a/php/phpunit.xml b/php/phpunit.xml index 121f5dee..cf5ecbef 100644 --- a/php/phpunit.xml +++ b/php/phpunit.xml @@ -1,6 +1,7 @@ + tests/vaas/StreamsInLoopTest.php tests/vaas/Sha256Test.php tests/vaas/VaasTest.php tests/vaas/ProtocolTest.php diff --git a/php/tests/vaas/StreamsInLoopTest.php b/php/tests/vaas/StreamsInLoopTest.php new file mode 100644 index 00000000..e66c09bc --- /dev/null +++ b/php/tests/vaas/StreamsInLoopTest.php @@ -0,0 +1,52 @@ +requestStreaming("GET", "https://secure.eicar.org/eicar.com.txt")); + $body1 = $response1->getBody(); + $this->assertEquals(true, $body1->isReadable()); + + $response2 = await($browser2->requestStreaming("GET", "https://secure.eicar.org/eicar.com.txt")); + $this->assertEquals(true, $body1->isReadable()); + $body2 = $response2->getBody(); + $this->assertEquals(true, $body2->isReadable()); + + assert($body2 instanceof ReadableStreamInterface); + $string2 = await(buffer($body2)); + } + + static function random_strings($length_of_string) { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $characters_length = strlen($characters); + $random_string = ''; + + // Generate random characters until the string reaches desired length + for ($i = 0; $i < $length_of_string; $i++) { + $random_index = random_int(0, $characters_length - 1); + $random_string .= $characters[$random_index]; + } + + return $random_string; + } +} \ No newline at end of file diff --git a/php/tests/vaas/VaasTest.php b/php/tests/vaas/VaasTest.php index b8c4a41c..89e56ae9 100644 --- a/php/tests/vaas/VaasTest.php +++ b/php/tests/vaas/VaasTest.php @@ -15,7 +15,6 @@ use VaasSdk\Vaas; use Dotenv\Dotenv; use Exception; -use GuzzleHttp\Promise\PromiseInterface; use Monolog\Formatter\JsonFormatter; use Monolog\Handler\StreamHandler; use Monolog\Handler\TestHandler; @@ -25,11 +24,8 @@ use Ramsey\Uuid\Generator\RandomBytesGenerator; use Ramsey\Uuid\Rfc4122\UuidV4; use React\EventLoop\Loop; -use React\EventLoop\StreamSelectLoop; use React\Http\Browser; use React\Http\Io\HttpBodyStream; -use React\Promise\PromiseInterface as PromisePromiseInterface; -use React\Socket\Connector; use React\Stream\ReadableResourceStream; use React\Stream\ReadableStreamInterface; use React\Stream\ThroughStream; @@ -39,7 +35,6 @@ use VaasSdk\VaasOptions; use WebSocket\BadOpcodeException; use function React\Async\await; -use function React\Promise\Stream\unwrapReadable; final class VaasTest extends TestCase { @@ -581,7 +576,7 @@ public function testForStream_WithCleanDelayedfor11Seconds_ReturnsClean() $randomString = $this->random_strings(11000); $stream = new ThroughStream(); - $writeTimer = Loop::addPeriodicTimer(0.00001, function () use ($stream, &$randomString) { + $writeTimer = Loop::addPeriodicTimer(0.001, function () use ($stream, &$randomString) { if ($randomString === "") { $stream->end(); return; @@ -661,7 +656,7 @@ public function testForStream_WithEicarUrlContentAsStream_ReturnsMaliciousWithDe $this->assertNotEmpty($verdict->Detection); } - function random_strings($length_of_string) { + static function random_strings($length_of_string) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $characters_length = strlen($characters); $random_string = ''; diff --git a/php/tests/vaas/phpunit.xml b/php/tests/vaas/phpunit.xml index 888c0418..530e0897 100644 --- a/php/tests/vaas/phpunit.xml +++ b/php/tests/vaas/phpunit.xml @@ -1,6 +1,7 @@ + StreamsInLoopTest.php Sha256Test.php VaasTest.php ProtocolTest.php