Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit 20f6f17

Browse files
authored
Merge pull request #21 from reactphp-parallel/add-tests-for-notify-and-destruct
Add tests for Notify and Destruct messages
2 parents 1fe51d2 + 70446d1 commit 20f6f17

File tree

5 files changed

+64
-11
lines changed

5 files changed

+64
-11
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ psalm: ## Run static analysis (Psalm)
4040
$(DOCKER_RUN) vendor/bin/psalm --threads=$(shell nproc) --shepherd --stats
4141

4242
unit: ## Run tests
43-
$(DOCKER_RUN) vendor/bin/phpunit --colors=always -c phpunit.xml.dist --coverage-text --coverage-html covHtml --coverage-clover ./build/logs/clover.xml --filter metricsDestructionTesting
43+
$(DOCKER_RUN) vendor/bin/phpunit --colors=always -c phpunit.xml.dist --coverage-text --coverage-html covHtml --coverage-clover ./build/logs/clover.xml
4444

4545
unit-ci: unit
4646
if [ -f ./build/logs/clover.xml ]; then wget https://scrutinizer-ci.com/ocular.phar && sleep 3 && php ocular.phar code-coverage:upload --format=php-clover ./build/logs/clover.xml; fi

src/AbstractGeneratedProxy.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,11 @@ final protected function proxyCallToMainThread(string $method, array $args)
4747
/**
4848
* @param mixed[] $args
4949
*/
50-
final protected function proxyNotifyMainThread(string $interface, string $method, array $args): void
50+
final protected function proxyNotifyMainThread(string $method, array $args): void
5151
{
5252
$this->out->send(new Notify(
5353
$this->hash,
5454
spl_object_hash($this),
55-
$interface,
5655
$method,
5756
$args,
5857
));

src/Message/Notify.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ final class Notify
88
{
99
private string $hash;
1010
private string $objectHash;
11-
private string $interface;
1211

1312
private string $method;
1413

@@ -18,11 +17,10 @@ final class Notify
1817
/**
1918
* @param mixed[] $args
2019
*/
21-
public function __construct(string $hash, string $objectHash, string $interface, string $method, array $args)
20+
public function __construct(string $hash, string $objectHash, string $method, array $args)
2221
{
2322
$this->hash = $hash;
2423
$this->objectHash = $objectHash;
25-
$this->interface = $interface;
2624
$this->method = $method;
2725
$this->args = $args;
2826
}
@@ -37,11 +35,6 @@ public function objectHash(): string
3735
return $this->objectHash;
3836
}
3937

40-
public function interface(): string
41-
{
42-
return $this->interface;
43-
}
44-
4538
public function method(): string
4639
{
4740
return $this->method;

tests/Message/DestructTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ReactParallel\Tests\ObjectProxy\Message;
6+
7+
use ReactParallel\ObjectProxy\Message\Destruct;
8+
use WyriHaximus\AsyncTestUtilities\AsyncTestCase;
9+
10+
use function bin2hex;
11+
use function random_bytes;
12+
13+
final class DestructTest extends AsyncTestCase
14+
{
15+
/**
16+
* @test
17+
*/
18+
public function getters(): void
19+
{
20+
$hash = bin2hex(random_bytes(1024));
21+
$objectHash = bin2hex(random_bytes(1024));
22+
23+
$call = new Destruct($hash, $objectHash);
24+
25+
self::assertSame($hash, $call->hash());
26+
self::assertSame($objectHash, $call->objectHash());
27+
}
28+
}

tests/Message/NotifyTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ReactParallel\Tests\ObjectProxy\Message;
6+
7+
use ReactParallel\ObjectProxy\Message\Notify;
8+
use WyriHaximus\AsyncTestUtilities\AsyncTestCase;
9+
10+
use function bin2hex;
11+
use function random_bytes;
12+
use function time;
13+
14+
final class NotifyTest extends AsyncTestCase
15+
{
16+
/**
17+
* @test
18+
*/
19+
public function getters(): void
20+
{
21+
$hash = bin2hex(random_bytes(1024));
22+
$objectHash = bin2hex(random_bytes(1024));
23+
$method = 'hammer';
24+
$args = [time()];
25+
26+
$call = new Notify($hash, $objectHash, $method, $args);
27+
28+
self::assertSame($hash, $call->hash());
29+
self::assertSame($objectHash, $call->objectHash());
30+
self::assertSame($method, $call->method());
31+
self::assertSame($args, $call->args());
32+
}
33+
}

0 commit comments

Comments
 (0)