Skip to content

Commit

Permalink
chore: update PHPUnit to latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
SMillerDev committed Dec 3, 2024
1 parent 2d11853 commit a844c11
Show file tree
Hide file tree
Showing 28 changed files with 89 additions and 87 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/php-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: uopz
tools: phpunit:9.5.x
extensions: uopz,mbstring

- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
Expand All @@ -45,7 +44,7 @@ jobs:
chmod 000 server_certificates_bundle_unreadable.pem
- name: Run PHPUnit
run: phpunit -c phpunit.xml
run: ./vendor/bin/phpunit -c phpunit.xml

sample_push:
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @covers \ApnsPHP\Message\CustomMessage
*/
class CustomMessageGetPayloadDictionaryTest extends CustomMessageTest
class CustomMessageGetPayloadDictionaryTest extends CustomMessageTestBase
{
/**
* Test that getPayloadDictionary returns complete payload with body if locKey isn't set
Expand Down
2 changes: 1 addition & 1 deletion ApnsPHP/Message/Tests/CustomMessageGetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @covers \ApnsPHP\Message\CustomMessage
*/
class CustomMessageGetTest extends CustomMessageTest
class CustomMessageGetTest extends CustomMessageTestBase
{
/**
* Test that getActionLocKey() gets the view button title.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @covers \ApnsPHP\Message\CustomMessage
*/
abstract class CustomMessageTest extends LunrBaseTest
abstract class CustomMessageTestBase extends LunrBaseTest
{
/**
* Class to test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @covers \ApnsPHP\Message\SafariMessage
*/
class SafariMessageGetPayloadDictionaryTest extends SafariMessageTest
class SafariMessageGetPayloadDictionaryTest extends SafariMessageTestBase
{
/**
* Test that getPayloadDictionary returns complete payload
Expand Down
2 changes: 1 addition & 1 deletion ApnsPHP/Message/Tests/SafariMessageGetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @covers \ApnsPHP\Message\SafariMessage
*/
class SafariMessageGetTest extends SafariMessageTest
class SafariMessageGetTest extends SafariMessageTestBase
{
/**
* Test that getAction() gets the label of the action button.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @covers \ApnsPHP\Message\SafariMessage
*/
abstract class SafariMessageTest extends LunrBaseTest
abstract class SafariMessageTestBase extends LunrBaseTest
{
/**
* Class to test
Expand Down
2 changes: 1 addition & 1 deletion ApnsPHP/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ protected function getJsonWebToken(): string
public function add(Message $message): void
{
$messagePayload = $message->getPayload();
$recipients = $message->getRecipientsNumber();
$recipients = $message->getRecipientsCount();

$messageQueueLen = count($this->messageQueue);
for ($i = 0; $i < $recipients; $i++) {
Expand Down
2 changes: 1 addition & 1 deletion ApnsPHP/Tests/MessageAddRecipientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @covers \ApnsPHP\Message
*/
class MessageAddRecipientTest extends MessageTest
class MessageAddRecipientTest extends MessageTestBase
{
/**
* Test that addRecipient throws exception on invalid token
Expand Down
2 changes: 1 addition & 1 deletion ApnsPHP/Tests/MessageGetPayloadDictionaryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @covers \ApnsPHP\Message
*/
class MessageGetPayloadDictionaryTest extends MessageTest
class MessageGetPayloadDictionaryTest extends MessageTestBase
{
/**
* Test that getPayloadDictionary returns complete payload
Expand Down
4 changes: 2 additions & 2 deletions ApnsPHP/Tests/MessageGetPayloadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @covers \ApnsPHP\Message
*/
class MessageGetPayloadTest extends MessageTest
class MessageGetPayloadTest extends MessageTestBase
{
/**
* Test that getPayload() returns complete JSON encoded payload
Expand Down Expand Up @@ -161,7 +161,7 @@ public function testCastToStringReturnsEmptyStringOnTooLongPayloadWithoutAutoAdj
*
* @return string String of certain size in bytes
*/
private function getLargeString($size): string
private function getLargeString(int $size): string
{
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$length = strlen($characters);
Expand Down
2 changes: 1 addition & 1 deletion ApnsPHP/Tests/MessageGetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* @covers \ApnsPHP\Message
*/
class MessageGetTest extends MessageTest
class MessageGetTest extends MessageTestBase
{
/**
* Test that getText() gets the message text.
Expand Down
6 changes: 3 additions & 3 deletions ApnsPHP/Tests/MessageSelfForRecipientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
*
* @covers \ApnsPHP\Message
*/
class MessageSelfForRecipientTest extends MessageTest
class MessageSelfForRecipientTest extends MessageTestBase
{
/**
* Test that selfForRecipient throws exception on invalid index
*
* @covers \ApnsPHP\Message::selfForRecipient
*/
public function testselfForRecipientThrowsExceptionOnInvalidIndex(): void
public function testSelfForRecipientThrowsExceptionOnInvalidIndex(): void
{
$this->expectException('ApnsPHP\Exception');
$this->expectExceptionMessage('No recipient at index \'1\'');
Expand All @@ -37,7 +37,7 @@ public function testselfForRecipientThrowsExceptionOnInvalidIndex(): void
*
* @covers \ApnsPHP\Message::selfForRecipient
*/
public function testselfForRecipientGetsMessage(): void
public function testSelfForRecipientGetsMessage(): void
{
$token = '1e82db91c7ceddd72bf33d74ae052ac9c84a065b35148ac401388843106a7485';
$message = new Message($token);
Expand Down
10 changes: 5 additions & 5 deletions ApnsPHP/Tests/MessageSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
*
* @covers \ApnsPHP\Message
*/
class MessageSetTest extends MessageTest
class MessageSetTest extends MessageTestBase
{
/**
* Unit test data provider for reserved apple namespace keys.
*
* @return array Variations of the reserved apple namespace key
*/
public function reservedAppleNamespaceKeyProvider(): array
public static function reservedAppleNamespaceKeyProvider(): array
{
$data = [];
$data[] = [ 'aps' ];
Expand All @@ -40,7 +40,7 @@ public function reservedAppleNamespaceKeyProvider(): array
*
* @return array Variations of valid custom identifiers
*/
public function validCustomIdentifierProvider(): array
public static function validCustomIdentifierProvider(): array
{
$data = [];
$data[] = [ '3491ac4b-0681-4c92-8308-d8d8441f4e64' ];
Expand All @@ -54,7 +54,7 @@ public function validCustomIdentifierProvider(): array
*
* @return array Variations of a valid message priority
*/
public function validPriorityProvider(): array
public static function validPriorityProvider(): array
{
$data = [];
$data[] = [ Priority::PrioritizePowerUsage ];
Expand All @@ -69,7 +69,7 @@ public function validPriorityProvider(): array
*
* @return array Variations of a valid push type
*/
public function validPushTypeProvider(): array
public static function validPushTypeProvider(): array
{
$data = [];
$data[] = [ PushType::Alert ];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* @covers \ApnsPHP\Message
*/
abstract class MessageTest extends LunrBaseTest
abstract class MessageTestBase extends LunrBaseTest
{
/**
* Class to test
Expand Down
32 changes: 19 additions & 13 deletions ApnsPHP/Tests/PushAddTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @covers \ApnsPHP\Push
*/
class PushAddTest extends PushTest
class PushAddTest extends PushTestBase
{
/**
* Test that add() successfully adds one message
Expand All @@ -26,16 +26,16 @@ public function testAddOneMessage(): void
{
$this->message->expects($this->once())
->method('getPayLoad')
->will($this->returnValue('payload'));
->willReturn('payload');

$this->message->expects($this->once())
->method('getRecipientsNumber')
->will($this->returnValue(1));
->method('getRecipientsCount')
->willReturn(1);

$this->message->expects($this->once())
->method('selfForRecipient')
->with(0)
->will($this->returnValue($this->message));
->willReturn($this->message);

$this->class->add($this->message);

Expand All @@ -60,16 +60,22 @@ public function testAddMultipleMessages(): void

$this->message->expects($this->once())
->method('getPayLoad')
->will($this->returnValue('payload'));
->willReturn('payload');

$this->message->expects($this->once())
->method('getRecipientsNumber')
->will($this->returnValue(4));
->method('getRecipientsCount')
->willReturn(4);

$map = [
[ 0, $this->message ],
[ 1, $this->message ],
[ 2, $this->message ],
[ 3, $this->message ],
];

$this->message->expects($this->exactly(4))
->method('selfForRecipient')
->withConsecutive([0], [1], [2], [3])
->will($this->returnValue($this->message));
->willReturnMap($map);

$this->class->add($this->message);

Expand All @@ -87,11 +93,11 @@ public function testAddDoesNothing(): void
{
$this->message->expects($this->once())
->method('getPayLoad')
->will($this->returnValue('payload'));
->willReturn('payload');

$this->message->expects($this->once())
->method('getRecipientsNumber')
->will($this->returnValue(0));
->method('getRecipientsCount')
->willReturn(0);

$this->class->add($this->message);

Expand Down
13 changes: 5 additions & 8 deletions ApnsPHP/Tests/PushConnectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* @covers \ApnsPHP\Push
*/
class PushConnectTest extends PushTest
class PushConnectTest extends PushTestBase
{
/**
* Test that connect() connects successfully
Expand All @@ -34,11 +34,11 @@ public function testConnectSuccess(): void

$this->logger->expects($this->exactly(3))
->method('info')
->withConsecutive(
->willReturnMap([
[ 'Trying to initialize HTTP/2 backend...' ],
[ 'Initializing HTTP/2 backend with certificate.' ],
[ 'Initialized HTTP/2 backend.' ],
);
]);

$this->class->connect();

Expand All @@ -57,16 +57,13 @@ public function testConnectThrowsExceptionOnHttpInitFail(): void

$this->mock_function('curl_setopt_array', fn() => false);

$message = [
];

$this->logger->expects($this->exactly(4))
->method('error')
->with('Unable to initialize HTTP/2 backend.');

$this->logger->expects($this->exactly(11))
->method('info')
->withConsecutive(
->willReturnMap([
[ 'Trying to initialize HTTP/2 backend...' ],
[ 'Initializing HTTP/2 backend with certificate.' ],
[ 'Retry to connect (1/3)...' ],
Expand All @@ -78,7 +75,7 @@ public function testConnectThrowsExceptionOnHttpInitFail(): void
[ 'Retry to connect (3/3)...' ],
[ 'Trying to initialize HTTP/2 backend...' ],
[ 'Initializing HTTP/2 backend with certificate.' ],
);
]);

$this->expectException('ApnsPHP\Exception');
$this->expectExceptionMessage('Unable to initialize HTTP/2 backend.');
Expand Down
2 changes: 1 addition & 1 deletion ApnsPHP/Tests/PushDisconnectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @covers \ApnsPHP\Push
*/
class PushDisconnectTest extends PushTest
class PushDisconnectTest extends PushTestBase
{
/**
* Test that disconnect() disconnects successfully
Expand Down
2 changes: 1 addition & 1 deletion ApnsPHP/Tests/PushGetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @covers \ApnsPHP\Push
*/
class PushGetTest extends PushTest
class PushGetTest extends PushTestBase
{
/**
* Test that getSendRetryTimes() returns how often sends should be retried.
Expand Down
12 changes: 6 additions & 6 deletions ApnsPHP/Tests/PushHttpInitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @covers \ApnsPHP\Push
*/
class PushHttpInitTest extends PushTest
class PushHttpInitTest extends PushTestBase
{
/**
* Test that httpInit() succeeds with certificate
Expand All @@ -40,7 +40,7 @@ public function testHttpInitSucceedsWithCertificate(): void

$this->logger->expects($this->exactly(3))
->method('info')
->withConsecutive(...$message);
->willReturnMap($message);

$method = $this->get_reflection_method('httpInit');
$result = $method->invoke($this->class);
Expand Down Expand Up @@ -99,11 +99,11 @@ public function testHttpInitSucceedsWithKey(): void

$this->logger->expects($this->exactly(3))
->method('info')
->withConsecutive(
->willReturnMap([
[ 'Trying to initialize HTTP/2 backend...' ],
[ 'Initializing HTTP/2 backend with key.' ],
[ 'Initialized HTTP/2 backend.' ]
);
]);

$method = $this->get_reflection_method('httpInit');
$result = $method->invoke($this->class);
Expand Down Expand Up @@ -167,10 +167,10 @@ public function testHttpInitThrowsExceptionOnCurlSetoptFail(): void

$this->logger->expects($this->exactly(2))
->method('info')
->withConsecutive(
->willReturnMap([
[ 'Trying to initialize HTTP/2 backend...' ],
[ 'Initializing HTTP/2 backend with key.' ],
);
]);

$this->expectException('ApnsPHP\Exception');
$this->expectExceptionMessage('Unable to initialize HTTP/2 backend.');
Expand Down
Loading

0 comments on commit a844c11

Please sign in to comment.