Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update PHPUnit to latest version #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/php-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,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 @@ -54,7 +53,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 CustomMessageTestCase
{
/**
* 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 CustomMessageTestCase
{
/**
* 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 CustomMessageTestCase 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 SafariMessageTestCase
{
/**
* 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 SafariMessageTestCase
{
/**
* 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 SafariMessageTestCase extends LunrBaseTest
{
/**
* Class to test
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 MessageTestCase
{
/**
* 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 MessageTestCase
{
/**
* 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 MessageTestCase
{
/**
* 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 MessageTestCase
{
/**
* 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 MessageTestCase
{
/**
* 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 MessageTestCase
{
/**
* 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 MessageTestCase 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 PushTestCase
{
/**
* Test that add() successfully adds one message
Expand All @@ -26,16 +26,16 @@
{
$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,22 +60,28 @@

$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);

$queue = $this->get_reflection_property('messageQueue')->getValue($this->class);

$this->assertEquals($messages, $queue);

Check failure on line 84 in ApnsPHP/Tests/PushAddTest.php

View workflow job for this annotation

GitHub Actions / PHP-8.1: PHPUnit

Failed asserting that two arrays are equal.
}

/**
Expand All @@ -87,11 +93,11 @@
{
$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 PushTestCase
{
/**
* 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)...' ],
Copy link

@brianstoop brianstoop Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get that this works but what exactly does this test now? IIRC, if the ReturnMap array is empty it would also succeed, so what does this add?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

willReturnCallback maybe?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does willReturnCallback work here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 PushTestCase
{
/**
* 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 PushTestCase
{
/**
* 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 PushTestCase
{
/**
* 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
Loading