Skip to content

Commit

Permalink
Tests: Use newer Lunr.Halo
Browse files Browse the repository at this point in the history
  • Loading branch information
SMillerDev committed Dec 3, 2024
1 parent 46aa5e7 commit 0c1e7fc
Show file tree
Hide file tree
Showing 15 changed files with 105 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function testGetPayloadDictionaryReturnsCompletePayloadWithoutLocKey(): v
'name' => 'value'
];

$result = $this->get_accessible_reflection_method('getPayloadDictionary')->invoke($this->class);
$result = $this->get_reflection_method('getPayloadDictionary')->invoke($this->class);

$this->assertEquals($payload, $result);
}
Expand Down Expand Up @@ -109,7 +109,7 @@ public function testGetPayloadDictionaryReturnsCompletePayloadWithoutBody(): voi
'name' => 'value'
];

$result = $this->get_accessible_reflection_method('getPayloadDictionary')->invoke($this->class);
$result = $this->get_reflection_method('getPayloadDictionary')->invoke($this->class);

$this->assertEquals($payload, $result);
}
Expand All @@ -123,7 +123,7 @@ public function testGetPayloadDictionaryReturnsEmptyPayload(): void
{
$payload = [ 'aps' => [ 'alert' => [] ] ];

$result = $this->get_accessible_reflection_method('getPayloadDictionary')->invoke($this->class);
$result = $this->get_reflection_method('getPayloadDictionary')->invoke($this->class);

$this->assertEquals($payload, $result);
}
Expand Down
10 changes: 8 additions & 2 deletions ApnsPHP/Message/Tests/CustomMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@
*/
abstract class CustomMessageTest extends LunrBaseTest
{
/**
* Class to test
* @var CustomMessage
*/
protected CustomMessage $class;

/**
* TestCase constructor
*/
public function setUp(): void
{
$this->reflection = new ReflectionClass('ApnsPHP\Message\CustomMessage');
$this->class = new CustomMessage();
$this->baseSetUp($this->class);
}

/**
Expand All @@ -37,6 +43,6 @@ public function setUp(): void
public function tearDown(): void
{
unset($this->class);
unset($this->reflection);
parent::tearDown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testGetPayloadDictionaryReturnsCompletePayload(): void
]
];

$result = $this->get_accessible_reflection_method('getPayloadDictionary')->invoke($this->class);
$result = $this->get_reflection_method('getPayloadDictionary')->invoke($this->class);

$this->assertEquals($payload, $result);
}
Expand All @@ -54,7 +54,7 @@ public function testGetPayloadDictionaryReturnsEmptyPayload(): void
{
$payload = [ 'aps' => [ 'alert' => [] ] ];

$result = $this->get_accessible_reflection_method('getPayloadDictionary')->invoke($this->class);
$result = $this->get_reflection_method('getPayloadDictionary')->invoke($this->class);

$this->assertEquals($payload, $result);
}
Expand Down
10 changes: 8 additions & 2 deletions ApnsPHP/Message/Tests/SafariMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@
*/
abstract class SafariMessageTest extends LunrBaseTest
{
/**
* Class to test
* @var SafariMessage
*/
protected SafariMessage $class;

/**
* TestCase constructor
*/
public function setUp(): void
{
$this->reflection = new ReflectionClass('ApnsPHP\Message\SafariMessage');
$this->class = new SafariMessage();
$this->baseSetUp($this->class);
}

/**
Expand All @@ -37,6 +43,6 @@ public function setUp(): void
public function tearDown(): void
{
unset($this->class);
unset($this->reflection);
parent::tearDown();
}
}
6 changes: 3 additions & 3 deletions ApnsPHP/Tests/MessageGetPayloadDictionaryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function testGetPayloadDictionaryReturnsCompletePayload(): void
'name' => 'value'
];

$result = $this->get_accessible_reflection_method('getPayloadDictionary')->invoke($this->class);
$result = $this->get_reflection_method('getPayloadDictionary')->invoke($this->class);

$this->assertEquals($payload, $result);
}
Expand Down Expand Up @@ -88,7 +88,7 @@ public function testGetPayloadDictionaryWithoutTitle(): void
'name' => 'value'
];

$result = $this->get_accessible_reflection_method('getPayloadDictionary')->invoke($this->class);
$result = $this->get_reflection_method('getPayloadDictionary')->invoke($this->class);

$this->assertEquals($payload, $result);
}
Expand All @@ -102,7 +102,7 @@ public function testGetPayloadDictionaryReturnsEmptyPayload(): void
{
$payload = [ 'aps' => [] ];

$result = $this->get_accessible_reflection_method('getPayloadDictionary')->invoke($this->class);
$result = $this->get_reflection_method('getPayloadDictionary')->invoke($this->class);

$this->assertEquals($payload, $result);
}
Expand Down
12 changes: 9 additions & 3 deletions ApnsPHP/Tests/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@
*/
abstract class MessageTest extends LunrBaseTest
{
/**
* Class to test
* @var Message
*/
protected Message $class;

/**
* TestCase constructor
*/
public function setUp(): void
{
$this->reflection = new ReflectionClass('ApnsPHP\Message');
$this->class = new Message();
$this->class = new Message();
$this->baseSetUp($this->class);
}

/**
Expand All @@ -38,6 +44,6 @@ public function setUp(): void
public function tearDown(): void
{
unset($this->class);
unset($this->reflection);
parent::tearDown();
}
}
6 changes: 3 additions & 3 deletions ApnsPHP/Tests/PushAddTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testAddOneMessage(): void

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

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

$this->assertEquals($this->message, $queue[1]['MESSAGE']);
}
Expand Down Expand Up @@ -73,7 +73,7 @@ public function testAddMultipleMessages(): void

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

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

$this->assertEquals($messages, $queue);
}
Expand All @@ -95,7 +95,7 @@ public function testAddDoesNothing(): void

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

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

$this->assertArrayEmpty($queue);
}
Expand Down
8 changes: 2 additions & 6 deletions ApnsPHP/Tests/PushConnectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ public function testConnectSuccess(): void
{
$this->set_reflection_property_value('logger', $this->logger);

$this->mock_function('curl_setopt_array', function () {
return true;
});
$this->mock_function('curl_setopt_array', fn() => true);

$this->logger->expects($this->exactly(3))
->method('info')
Expand All @@ -57,9 +55,7 @@ public function testConnectThrowsExceptionOnHttpInitFail(): void
$this->set_reflection_property_value('connectRetryInterval', 0);
$this->set_reflection_property_value('logger', $this->logger);

$this->mock_function('curl_setopt_array', function () {
return false;
});
$this->mock_function('curl_setopt_array', fn() => false);

$message = [
];
Expand Down
38 changes: 8 additions & 30 deletions ApnsPHP/Tests/PushHttpInitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testHttpInitSucceedsWithCertificate(): void
->method('info')
->withConsecutive(...$message);

$method = $this->get_accessible_reflection_method('httpInit');
$method = $this->get_reflection_method('httpInit');
$result = $method->invoke($this->class);

$this->assertTrue($result);
Expand Down Expand Up @@ -73,19 +73,9 @@ public function testHttpInitSucceedsWithKey(): void
new Signature('signature', 'eSignature'),
);

$this->mock_method(
[ 'Lcobucci\JWT\Signer\Key\InMemory', 'file' ],
function () use ($key) {
return $key;
}
);
$this->mock_method([ 'Lcobucci\JWT\Signer\Key\InMemory', 'file' ], fn() => $key);

$this->mock_method(
[ 'Lcobucci\JWT\Configuration', 'builder' ],
function () use ($builder) {
return $builder;
}
);
$this->mock_method([ 'Lcobucci\JWT\Configuration', 'builder' ], fn() => $builder);

$builder->expects($this->once())
->method('issuedBy')
Expand Down Expand Up @@ -115,7 +105,7 @@ function () use ($builder) {
[ 'Initialized HTTP/2 backend.' ]
);

$method = $this->get_accessible_reflection_method('httpInit');
$method = $this->get_reflection_method('httpInit');
$result = $method->invoke($this->class);

$this->assertTrue($result);
Expand All @@ -136,9 +126,7 @@ public function testHttpInitThrowsExceptionOnCurlSetoptFail(): void
$this->set_reflection_property_value('providerKeyId', 'TheKey');
$this->set_reflection_property_value('logger', $this->logger);

$this->mock_function('curl_setopt_array', function () {
return false;
});
$this->mock_function('curl_setopt_array', fn() => false);

$key = $this->getMockBuilder('Lcobucci\JWT\Signer\Key')
->disableOriginalConstructor()
Expand All @@ -153,19 +141,9 @@ public function testHttpInitThrowsExceptionOnCurlSetoptFail(): void
new Signature('signature', 'eSignature'),
);

$this->mock_method(
[ 'Lcobucci\JWT\Signer\Key\InMemory', 'file' ],
function () use ($key) {
return $key;
}
);
$this->mock_method([ 'Lcobucci\JWT\Signer\Key\InMemory', 'file' ], fn() => $key);

$this->mock_method(
[ 'Lcobucci\JWT\Configuration', 'builder' ],
function () use ($builder) {
return $builder;
}
);
$this->mock_method([ 'Lcobucci\JWT\Configuration', 'builder' ], fn() => $builder);

$builder->expects($this->once())
->method('issuedBy')
Expand Down Expand Up @@ -197,7 +175,7 @@ function () use ($builder) {
$this->expectException('ApnsPHP\Exception');
$this->expectExceptionMessage('Unable to initialize HTTP/2 backend.');

$method = $this->get_accessible_reflection_method('httpInit');
$method = $this->get_reflection_method('httpInit');

# phpstan doesn't detect the potential throw through ReflectionMethod.
# Verified that by making the method public and calling it directly
Expand Down
Loading

0 comments on commit 0c1e7fc

Please sign in to comment.