Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
francislavoie committed Sep 11, 2024
1 parent a30b64c commit af07bed
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
11 changes: 6 additions & 5 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@
use Vectorface\Gearman\Connection;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\Process;
use Vectorface\Gearman\Exception;
use Vectorface\Gearman\Exception\CouldNotConnectException;

class ClientTest extends TestCase
{
/**
* @var Client
*/
private $client;
private Client $client;

public function setUp(): void
{
$this->client = new Client();
$this->client->addServer();
}

/**
* @throws Exception
*/
public function testClient()
{
$process = new Process(["gearman", "-w", "-f", "replace", "--", "sed 's/__replace__/the best/g'"]);
Expand All @@ -32,7 +33,7 @@ public function testClient()
$this->client->doBackground('replace', 'php is __replace__');
$this->client->doHighBackground('replace', 'php is __replace__');
$this->client->doLowBackground('replace', 'php is __replace__');
} catch (CouldNotConnectException $e) {
} catch (CouldNotConnectException) {
$this->markTestSkipped('Skipped, please start Gearman on port ' . Connection::DEFAULT_PORT . ' to be able to run this test');
}

Expand Down
9 changes: 6 additions & 3 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testDefaultConnect()
{
try {
$connection = Connection::connect();
} catch (Exception $exception) {
} catch (Exception) {
$this->markTestSkipped('Skipped. You can try this test on your machine with gearman running.');
}

Expand All @@ -38,19 +38,22 @@ public function testDefaultConnect()
Connection::close($connection);
}

/**
* @throws Exception
*/
public function testSend()
{
try {
$connection = Connection::connect();
} catch (Exception $exception) {
} catch (Exception) {
$this->markTestSkipped('Skipped. You can try this test on your machine with gearman running.');
}

Connection::send($connection, 'echo_req', ['text' => 'foobar']);

do {
$ret = Connection::read($connection);
} while (is_array($ret) && !count($ret));
} while (!count($ret));

Connection::close($connection);

Expand Down
15 changes: 6 additions & 9 deletions tests/WorkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@

class WorkerTest extends TestCase
{
/**
* @var Worker
*/
protected $worker;
protected Worker $worker;

public function setUp(): void
{
Expand All @@ -22,7 +19,7 @@ public function setUp(): void
public function testAddFunction()
{
$gearmanFunctionName = 'reverse';
$callback = function ($job) {
$callback = static function ($job) {
return $job->workload();
};

Expand All @@ -48,7 +45,7 @@ public function testUnregister()
{
$gearmanFunctionName = 'reverse';
$gearmanFunctionNameSecond = 'reverse2';
$callback = function ($job) {
$callback = static function ($job) {
return $job->workload();
};

Expand Down Expand Up @@ -100,14 +97,14 @@ public function testWorker()
{
$this->markTestSkipped('Skipped. You can try this test on your machine with gearman running.');

$function = function ($payload) {
$function = static function ($payload) {
$result = str_replace('java', 'php', $payload);

return str_replace('java', 'php', $payload);
};

$function2 = function ($payload) {
while (false !== strpos($payload, 'java')) {
$function2 = static function ($payload) {
while (str_contains($payload, 'java')) {
$payload = preg_replace('/java/', 'php', $payload, 1);
sleep(1);
}
Expand Down

0 comments on commit af07bed

Please sign in to comment.