Skip to content

Commit

Permalink
Push: Update Curl types for PHP8
Browse files Browse the repository at this point in the history
  • Loading branch information
pprkut committed Apr 26, 2024
1 parent 77125a4 commit b0916fc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 30 deletions.
11 changes: 6 additions & 5 deletions ApnsPHP/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@

namespace ApnsPHP;

use DateTimeImmutable;
use ApnsPHP\Push\Exception;
use Psr\Log\LoggerInterface;
use CurlHandle;
use DateTimeImmutable;
use Lcobucci\JWT\Signer\Key\InMemory;
use Lcobucci\JWT\Signer\Ecdsa\MultibyteStringConverter;
use Lcobucci\JWT\Signer\Ecdsa\Sha256;
use Lcobucci\JWT\Configuration;
use Psr\Log\LoggerInterface;

/**
* The Push Notification Provider.
Expand Down Expand Up @@ -147,9 +148,9 @@ class Push

/**
* SSL Socket.
* @var resource|\CurlHandle|null
* @var CurlHandle|null
*/
protected $hSocket;
protected ?CurlHandle $hSocket;

/**
* HTTP/2 Error-response messages.
Expand Down Expand Up @@ -412,7 +413,7 @@ public function connect(): void
*/
public function disconnect(): bool
{
if (is_resource($this->hSocket) || is_object($this->hSocket)) {
if (is_object($this->hSocket)) {
$this->logger->info('Disconnected.');
curl_close($this->hSocket);
unset($this->hSocket); // curl_close($handle) has no effect in PHP >= 8.0
Expand Down
4 changes: 0 additions & 4 deletions ApnsPHP/Tests/PushConnectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ public function testConnectSuccess(): void
{
$this->set_reflection_property_value('logger', $this->logger);

$this->mock_function('curl_init', function () {
return new stdClass();
});
$this->mock_function('curl_setopt_array', function () {
return true;
});
Expand All @@ -46,7 +43,6 @@ public function testConnectSuccess(): void

$this->class->connect();

$this->unmock_function('curl_init');
$this->unmock_function('curl_setopt_array');
}

Expand Down
26 changes: 5 additions & 21 deletions ApnsPHP/Tests/PushSendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testSendThrowsExceptionOnNoConnection(): void
*/
public function testSendThrowsExceptionOnEmptyQueue(): void
{
$this->set_reflection_property_value('hSocket', new stdClass());
$this->set_reflection_property_value('hSocket', curl_init());

$this->expectException('ApnsPHP\Push\Exception');
$this->expectExceptionMessage('No notifications queued to be sent');
Expand All @@ -66,9 +66,6 @@ public function testSendFailsWithoutRetrying(): void
$this->mock_function('curl_close', function () {
return null;
});
$this->mock_function('curl_init', function () {
return new stdClass();
});
$this->mock_function('curl_errno', function () {
return 0;
});
Expand All @@ -86,7 +83,7 @@ public function testSendFailsWithoutRetrying(): void
$message = [ 1 => [ 'MESSAGE' => $this->message, 'ERRORS' => [] ] ];

$this->set_reflection_property_value('environment', 1);
$this->set_reflection_property_value('hSocket', new stdClass());
$this->set_reflection_property_value('hSocket', curl_init());
$this->set_reflection_property_value('messageQueue', $message);
$this->set_reflection_property_value('logger', $this->logger);
$this->set_reflection_property_value('writeInterval', 0);
Expand Down Expand Up @@ -117,7 +114,6 @@ public function testSendFailsWithoutRetrying(): void
$this->unmock_function('curl_setopt_array');
$this->unmock_function('curl_getinfo');
$this->unmock_function('curl_close');
$this->unmock_function('curl_init');
}

/**
Expand All @@ -139,14 +135,11 @@ public function testSendFailsWithRetrying(): void
$this->mock_function('curl_close', function () {
return null;
});
$this->mock_function('curl_init', function () {
return new stdClass();
});

$message = [ 1 => [ 'MESSAGE' => $this->message, 'ERRORS' => [] ] ];

$this->set_reflection_property_value('environment', 1);
$this->set_reflection_property_value('hSocket', new stdClass());
$this->set_reflection_property_value('hSocket', curl_init());
$this->set_reflection_property_value('messageQueue', $message);
$this->set_reflection_property_value('logger', $this->logger);
$this->set_reflection_property_value('writeInterval', 0);
Expand Down Expand Up @@ -190,7 +183,6 @@ public function testSendFailsWithRetrying(): void
$this->unmock_function('curl_setopt_array');
$this->unmock_function('curl_getinfo');
$this->unmock_function('curl_close');
$this->unmock_function('curl_init');
}

/**
Expand Down Expand Up @@ -218,14 +210,11 @@ public function testSendRemovesWhenNoError(): void
$this->mock_function('curl_error', function () {
return '';
});
$this->mock_function('curl_init', function () {
return new stdClass();
});

$message = [ 1 => [ 'MESSAGE' => $this->message, 'ERRORS' => [] ] ];

$this->set_reflection_property_value('environment', 1);
$this->set_reflection_property_value('hSocket', new stdClass());
$this->set_reflection_property_value('hSocket', curl_init());
$this->set_reflection_property_value('messageQueue', $message);
$this->set_reflection_property_value('logger', $this->logger);
$this->set_reflection_property_value('writeInterval', 0);
Expand Down Expand Up @@ -256,7 +245,6 @@ public function testSendRemovesWhenNoError(): void
$this->unmock_function('curl_setopt_array');
$this->unmock_function('curl_getinfo');
$this->unmock_function('curl_close');
$this->unmock_function('curl_init');
}

/**
Expand All @@ -278,14 +266,11 @@ public function testSendSuccessfullySends(): void
$this->mock_function('curl_close', function () {
return null;
});
$this->mock_function('curl_init', function () {
return new stdClass();
});

$message = [ 1 => [ 'MESSAGE' => $this->message, 'ERRORS' => [] ] ];

$this->set_reflection_property_value('environment', 1);
$this->set_reflection_property_value('hSocket', new stdClass());
$this->set_reflection_property_value('hSocket', curl_init());
$this->set_reflection_property_value('messageQueue', $message);
$this->set_reflection_property_value('logger', $this->logger);
$this->set_reflection_property_value('writeInterval', 0);
Expand All @@ -304,6 +289,5 @@ public function testSendSuccessfullySends(): void
$this->unmock_function('curl_setopt_array');
$this->unmock_function('curl_getinfo');
$this->unmock_function('curl_close');
$this->unmock_function('curl_init');
}
}

0 comments on commit b0916fc

Please sign in to comment.