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

[PHP-8] Make compatible with PHP 8.2 #87

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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
composer.lock
phpunit.xml
vendor/

.phpunit.result.cache
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"homepage": "http://github.com/sailthru/sailthru-php5-client",
"license": "MIT",
"require-dev": {
"phpunit/phpunit": "~4.8"
"phpunit/phpunit": "9.x"
},
"autoload": {
"classmap": ["sailthru/"]
Expand Down
2 changes: 1 addition & 1 deletion examples/user.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?
<?php
require('_autoload.php');

$api_key = "SAILTHRU-API-KEY";
Expand Down
2 changes: 0 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="true"
strict="true"
verbose="false">
<testsuites>
<testsuite name="Sailthru Unit Test Suite">
Expand Down
20 changes: 9 additions & 11 deletions tests/Sailthru_ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
require(__DIR__ . '/../sailthru/Sailthru_Client_Exception.php');
require(__DIR__ . '/../sailthru/Sailthru_Util.php');

class Sailthru_ClientTest extends PHPUnit_Framework_TestCase {
class Sailthru_ClientTest extends \PHPUnit\Framework\TestCase {
private $api_key = "my_api_key";
private $api_secret = 'my_secret';
private $api_url = 'https://api.sailthru.com';
private $sailthru_client;

public function testDefaultTimeoutParameter() {
$sailthru_client = new Sailthru_Client($this->api_key, $this->api_secret, $this->api_url);
Expand All @@ -25,7 +26,7 @@ public function testSendWhenTemplateNameIsInvalid() {
$template_name = 'invalid_template';
$email = '[email protected]';
$json_response = json_encode(array('error' => 14, 'errormsg' => 'Unknown template: ' . $template_name));
$mock = $this->getMock('Sailthru_Client', array('send'), array($this->api_key, $this->api_secret, $this->api_url));
$mock = $this->createMock('Sailthru_Client', array('send'), array($this->api_key, $this->api_secret, $this->api_url));
$mock->expects($this->once())
->method('send')
->will($this->returnValue($json_response));
Expand All @@ -36,15 +37,15 @@ public function testSendWhenTemplateIsValid() {
$template_name = 'my_template';
$email = '[email protected]';
$json_response = json_encode(array('email' => $email, 'send_id' => 'some_unique_id', 'template' => $template_name, 'status' => 'unknown'));
$mock = $this->getMock('Sailthru_Client', array('send'), array($this->api_key, $this->api_secret, $this->api_url));
$mock = $this->createMock('Sailthru_Client', array('send'), array($this->api_key, $this->api_secret, $this->api_url));
$mock->expects($this->once())
->method('send')
->will($this->returnvalue($json_response));
$this->assertEquals($json_response, $mock->send($template_name, $email));
}

public function testApiPostWithValidJsonResponse() {
$mock = $this->getMock('Sailthru_Client', array('apiPost'), array($this->api_key, $this->api_secret, $this->api_url));
$mock = $this->createMock('Sailthru_Client', array('apiPost'), array($this->api_key, $this->api_secret, $this->api_url));
$json_response = array(
'email' => '[email protected]',
'profile_id' => '4f284c28a3a627b6389bfb4c',
Expand All @@ -59,17 +60,14 @@ public function testApiPostWithValidJsonResponse() {
$this->assertTrue(is_array($mock->apiPost('email', $json_response)));
}


/**
* @expectedException Sailthru_Client_Exception
*/
public function testApiPostWithInvalidJsonResponse() {
$mock = $this->getMock('Sailthru_Client', array('apiPost'), array($this->api_key, $this->api_secret, $this->api_url));
$mock = $this->createMock('Sailthru_Client', array('apiPost'), array($this->api_key, $this->api_secret, $this->api_url));
$mock->expects($this->once())
->method('apiPost')
->will($this->throwException(new Sailthru_Client_Exception()));
->will($this->throwException(new Sailthru_Client_Exception));
$this->expectException(Sailthru_Client_Exception::class);
$response = $mock->apiPost('email', array('email' => '[email protected]'));
$this->assertTrue(is_array($response)); // this will never be called
$this->assertTrue(is_array($response)); // this will never be called
}

public function testPrepareJsonPayload() {
Expand Down
8 changes: 3 additions & 5 deletions tests/Sailthru_Client_ExceptionTest.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<?php

class Sailthru_Client_ExceptionTest extends PHPUnit_Framework_TestCase {
/**
* @expectedException Sailthru_Client_Exception
*/
class Sailthru_Client_ExceptionTest extends \PHPUnit\Framework\TestCase {
public function testSailthru_Client_Exception() {
$api_key = "invalid_key";
$api_secret = "invalid_secret";
$api_url = "https://api.invalid_url.com";
$sailthruClient = new Sailthru_Client($api_key, $api_secret, $api_url);
$sailthruClient->getEmail("[email protected]");
$this->expectException(Sailthru_Client_Exception::class);
$sailthruClient->getEmail("[email protected]");
}
}
10 changes: 6 additions & 4 deletions tests/Sailthru_UtilTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

class Sailthru_UtilTest extends PHPUnit_Framework_TestCase {
class Sailthru_UtilTest extends \PHPUnit\Framework\TestCase {

public function setUp() {
private $params;

public function setUp(): void {
$this->params = array(
'item1' => 'value1',
'item2' => 'value2',
Expand All @@ -12,14 +14,14 @@ public function setUp() {
);
}

public function testExtractParamValues() {
public function testExtractParamValues(): void {
$expected = array('value1', 'value2', 'value3', 'value4', 0, 1);
$actual = array();
Sailthru_Util::extractParamValues($this->params, $actual);
$this->assertEquals(array_values($expected), $actual);
}

public function testGetSignatureString() {
public function testGetSignatureString(): void {
$expected_arr = array('value1', 'value2', 'value3', 'value4', 0, 1);
$secret = "ABCXYZ";
$expected_str = $secret;
Expand Down