Skip to content

Commit b14048f

Browse files
author
Jon Elverkilde
committed
Remove deprecated functionality
1 parent 65c82cc commit b14048f

13 files changed

+96
-199
lines changed

.github/workflows/test.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
php: [7.1, 7.2, 7.3, 7.4, 8.0]
14+
php: [7.2, 7.3, 7.4, 8.0]
1515
stability: [prefer-lowest, prefer-stable]
1616

1717
name: PHP ${{ matrix.php }} - ${{ matrix.stability }} Test
@@ -31,5 +31,16 @@ jobs:
3131
- name: Install dependencies
3232
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress
3333

34-
- name: Run test suite
35-
run: vendor/bin/phpunit --testsuite unit
34+
- name: Run lint
35+
run: ./vendor/bin/phplint ./ --exclude=vendor
36+
37+
- name: Run unit tests
38+
run: composer exec phpunit tests/unit
39+
40+
- name: Run acceptance tests
41+
env:
42+
PUSHERAPP_ID: ${{ secrets.CI_APP_ID }}
43+
PUSHERAPP_AUTHKEY: ${{ secrets.CI_APP_KEY }}
44+
PUSHERAPP_SECRET: ${{ secrets.CI_APP_SECRET }}
45+
PUSHERAPP_HOST: http://api-${{ secrets.CI_APP_CLUSTER }}.pusher.com
46+
run: composer exec phpunit tests/acceptance

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ phpunit.xml
33
tests/config.php
44
vendor
55
.phpunit.result.cache
6-
.phplint-cache
6+
.phplint-cache

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"require": {
77
"php": "^7.1|^8.0",
88
"ext-curl": "*",
9-
"guzzlehttp/guzzle": "^7.0",
9+
"guzzlehttp/guzzle": "^7.0",
1010
"psr/log": "^1.0",
1111
"paragonie/sodium_compat": "^1.6"
1212
},

src/Pusher.php

Lines changed: 8 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -46,62 +46,26 @@ class Pusher implements LoggerAwareInterface, PusherInterface
4646
* @param array $options [optional]
4747
* Options to configure the Pusher instance.
4848
* scheme - e.g. http or https
49-
* host - the host e.g. api.pusherapp.com. No trailing forward slash.
49+
* host - the host e.g. api-mt1.pusher.com. No trailing forward slash.
5050
* port - the http port
5151
* timeout - the http timeout
5252
* useTLS - quick option to use scheme of https and port 443.
53-
* encrypted - deprecated; renamed to `useTLS`.
5453
* cluster - cluster name to connect to.
55-
* encryption_master_key - deprecated; use `encryption_master_key_base64`
5654
* encryption_master_key_base64 - a 32 byte key, encoded as base64. This key, along with the channel name, are used to derive per-channel encryption keys. Per-channel keys are used to encrypt event data on encrypted channels.
5755
* curl_options - wrapper for curl_setopt, more here: http://php.net/manual/en/function.curl-setopt.php
58-
* @param string $host [optional] - deprecated
59-
* @param int $port [optional] - deprecated
60-
* @param int $timeout [optional] - deprecated
56+
* @param client $resource [optional] - a Guzzle client to use for all HTTP requests
6157
*
6258
* @throws PusherException Throws exception if any required dependencies are missing
6359
*/
64-
public function __construct($auth_key, $secret, $app_id, $options = array(), $host = null, $port = null, $timeout = null, $guzzle_client = null)
60+
public function __construct($auth_key, $secret, $app_id, $options = array(), $client = null)
6561
{
6662
$this->check_compatibility();
6763

68-
$this->setup_client($guzzle_client);
69-
70-
if (!is_null($host)) {
71-
$match = null;
72-
preg_match("/(http[s]?)\:\/\/(.*)/", $host, $match);
73-
74-
if (count($match) === 3) {
75-
$this->settings['scheme'] = $match[1];
76-
$host = $match[2];
77-
}
78-
79-
$this->settings['host'] = $host;
80-
$this->settings['path'] = '';
81-
82-
$this->log('Legacy $host parameter provided: {scheme} host: {host}', array(
83-
'scheme' => $this->settings['scheme'],
84-
'host' => $this->settings['host'],
85-
'path' => $this->settings['path'],
86-
));
87-
}
88-
89-
if (!is_null($port)) {
90-
$options['port'] = $port;
91-
}
92-
93-
if (!is_null($timeout)) {
94-
$options['timeout'] = $timeout;
95-
}
96-
97-
/* End backward compatibility with old constructor **/
64+
$this->setup_client($client);
9865

9966
$useTLS = false;
10067
if (isset($options['useTLS'])) {
10168
$useTLS = $options['useTLS'] === true;
102-
} elseif (isset($options['encrypted'])) {
103-
// `encrypted` deprecated in favor of `forceTLS`
104-
$useTLS = $options['encrypted'] === true;
10569
}
10670
if (
10771
$useTLS &&
@@ -138,16 +102,12 @@ public function __construct($auth_key, $secret, $app_id, $options = array(), $ho
138102
// ensure host doesn't have a scheme prefix
139103
$this->settings['host'] = preg_replace('/http[s]?\:\/\//', '', $this->settings['host'], 1);
140104

141-
if (!array_key_exists('encryption_master_key', $options)) {
142-
$options['encryption_master_key'] = '';
143-
}
144105
if (!array_key_exists('encryption_master_key_base64', $options)) {
145106
$options['encryption_master_key_base64'] = '';
146107
}
147108

148-
if ($options['encryption_master_key'] != '' or $options['encryption_master_key_base64'] != '') {
109+
if ($options['encryption_master_key_base64'] != '') {
149110
$parsedKey = PusherCrypto::parse_master_key(
150-
$options['encryption_master_key'],
151111
$options['encryption_master_key_base64']
152112
);
153113
$this->crypto = new PusherCrypto($parsedKey);
@@ -164,20 +124,6 @@ public function getSettings()
164124
return $this->settings;
165125
}
166126

167-
/**
168-
* Set a logger to be informed of internal log messages.
169-
*
170-
* @deprecated Use the PSR-3 compliant Pusher::setLogger() instead. This method will be removed in the next breaking release.
171-
*
172-
* @param object $logger A object with a public function log($message) method
173-
*
174-
* @return void
175-
*/
176-
public function set_logger($logger)
177-
{
178-
$this->logger = $logger;
179-
}
180-
181127
/**
182128
* Log a string.
183129
*
@@ -310,10 +256,10 @@ private function sign($url_prefix, $path, $request_method = 'GET', $query_params
310256

311257
private function setup_client($guzzle_client)
312258
{
313-
if (!is_resource($guzzle_client)) {
314-
$this->client = new \GuzzleHttp\Client();
259+
if (!is_null($guzzle_client)) {
260+
$this->client = $guzzle_client;
315261
} else {
316-
$this->client = $guzzle_client;
262+
$this->client = new \GuzzleHttp\Client();
317263
}
318264
}
319265

src/PusherCrypto.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,12 @@ public static function is_encrypted_channel($channel)
2121
return substr($channel, 0, strlen(self::ENCRYPTED_PREFIX)) === self::ENCRYPTED_PREFIX;
2222
}
2323

24-
public static function parse_master_key($encryption_master_key, $encryption_master_key_base64)
24+
public static function parse_master_key($encryption_master_key_base64)
2525
{
2626
if (!function_exists('sodium_crypto_secretbox')) {
2727
throw new PusherException('To use end to end encryption, you must either be using PHP 7.2 or greater or have installed the libsodium-php extension for php < 7.2.');
2828
}
2929

30-
if ($encryption_master_key != '' and $encryption_master_key_base64 != '') {
31-
throw new PusherException('Do not specify both encryption_master_key and encryption_master_key_base64. encryption_master_key is deprecated, use only encryption_master_key_base64');
32-
}
33-
34-
if ($encryption_master_key != '') {
35-
if (strlen($encryption_master_key) != SODIUM_CRYPTO_SECRETBOX_KEYBYTES) {
36-
throw new PusherException('encryption_master_key must be 32 bytes. It is also deprecated, use encryption_master_key_base64');
37-
}
38-
39-
return $encryption_master_key;
40-
}
41-
4230
if ($encryption_master_key_base64 != '') {
4331
$decoded_key = base64_decode($encryption_master_key_base64, true);
4432
if ($decoded_key === false) {

src/PusherInterface.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,6 @@ interface PusherInterface
1111
*/
1212
public function getSettings();
1313

14-
/**
15-
* Set a logger to be informed of internal log messages.
16-
*
17-
* @deprecated Use the PSR-3 compliant Pusher::setLogger() instead. This method will be removed in the next breaking release.
18-
*
19-
* @param object $logger A object with a public function log($message) method
20-
*
21-
* @return void
22-
*/
23-
public function set_logger($logger);
24-
2514
/**
2615
* Trigger an event by providing event name and payload.
2716
* Optionally provide a socket ID to exclude a client (most likely the sender).

tests/acceptance/channelQueryTest.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class channelQueryTest extends PHPUnit\Framework\TestCase
44
{
55
protected function setUp(): void
66
{
7-
$this->pusher = new Pusher\Pusher(PUSHERAPP_AUTHKEY, PUSHERAPP_SECRET, PUSHERAPP_APPID, array(), PUSHERAPP_HOST);
7+
$this->pusher = new Pusher\Pusher(PUSHERAPP_AUTHKEY, PUSHERAPP_SECRET, PUSHERAPP_APPID, ['host' => PUSHERAPP_HOST]);
88
$this->pusher->setLogger(new TestLogger());
99
}
1010

@@ -20,13 +20,6 @@ public function testChannelList()
2020
$result = $this->pusher->get_channels();
2121
$channels = $result->channels;
2222

23-
foreach ($channels as $channel_name => $channel_info) {
24-
// echo "channel_name: $channel_name\n";
25-
// echo 'channel_info: ';
26-
// print_r($channel_info);
27-
// echo "\n\n";
28-
}
29-
3023
$this->assertTrue(is_array($channels), 'channels is an array');
3124
}
3225

tests/acceptance/middlewareTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
use GuzzleHttp\Client;
4+
use GuzzleHttp\HandlerStack;
5+
use GuzzleHttp\Handler\CurlHandler;
6+
use Psr\Http\Message\RequestInterface;
7+
8+
class middlewareTest extends PHPUnit\Framework\TestCase
9+
{
10+
private $count = 0;
11+
function increment()
12+
{
13+
return function (callable $handler) {
14+
return function (RequestInterface $request, array $options) use ($handler) {
15+
$this->count++;
16+
return $handler($request, $options);
17+
};
18+
};
19+
}
20+
21+
protected function setUp(): void
22+
{
23+
if (PUSHERAPP_AUTHKEY === '' || PUSHERAPP_SECRET === '' || PUSHERAPP_APPID === '') {
24+
$this->markTestSkipped('Please set the
25+
PUSHERAPP_AUTHKEY, PUSHERAPP_SECRET and
26+
PUSHERAPP_APPID keys.');
27+
} else {
28+
$stack = new HandlerStack();
29+
$stack->setHandler(new CurlHandler());
30+
$stack->push($this->increment());
31+
$client = new Client(['handler' => $stack]);
32+
$this->pusher = new Pusher\Pusher(PUSHERAPP_AUTHKEY, PUSHERAPP_SECRET, PUSHERAPP_APPID, ['host' => PUSHERAPP_HOST], $client);
33+
}
34+
}
35+
36+
public function testStringPush()
37+
{
38+
$this->assertEquals(0, $this->count);
39+
$result = $this->pusher->trigger('test_channel', 'my_event', 'Test string');
40+
$this->assertEquals(1, $this->count);
41+
}
42+
}

tests/acceptance/triggerBatchTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ protected function setUp(): void
99
PUSHERAPP_AUTHKEY, PUSHERAPP_SECRET and
1010
PUSHERAPP_APPID keys.');
1111
} else {
12-
$this->pusher = new Pusher\Pusher(PUSHERAPP_AUTHKEY, PUSHERAPP_SECRET, PUSHERAPP_APPID, array(), PUSHERAPP_HOST);
12+
$this->pusher = new Pusher\Pusher(PUSHERAPP_AUTHKEY, PUSHERAPP_SECRET, PUSHERAPP_APPID, ['host' => PUSHERAPP_HOST]);
1313
$this->pusher->setLogger(new TestLogger());
1414
}
1515
}
@@ -138,9 +138,9 @@ public function testTriggerBatchWithMultipleCombinationsofStringAndObjectPayload
138138
public function testTriggerBatchWithWithEncryptedEventSuccess()
139139
{
140140
$options = array(
141-
'useTLS' => true,
142-
'host' => PUSHERAPP_HOST,
143-
'encryption_master_key' => 'cAzRH3W9FZM3iXqSNIGtKztwNuCz9xMV',
141+
'useTLS' => true,
142+
'host' => PUSHERAPP_HOST,
143+
'encryption_master_key_base64' => 'Y0F6UkgzVzlGWk0zaVhxU05JR3RLenR3TnVDejl4TVY=',
144144
);
145145
$pc = new Pusher\Pusher(PUSHERAPP_AUTHKEY, PUSHERAPP_SECRET, PUSHERAPP_APPID, $options);
146146
$pc->setLogger(new TestLogger());
@@ -154,9 +154,9 @@ public function testTriggerBatchWithWithEncryptedEventSuccess()
154154
public function testTriggerBatchWithMultipleEncryptedEventsSuccess()
155155
{
156156
$options = array(
157-
'useTLS' => true,
158-
'host' => PUSHERAPP_HOST,
159-
'encryption_master_key' => 'cAzRH3W9FZM3iXqSNIGtKztwNuCz9xMV',
157+
'useTLS' => true,
158+
'host' => PUSHERAPP_HOST,
159+
'encryption_master_key_base64' => 'Y0F6UkgzVzlGWk0zaVhxU05JR3RLenR3TnVDejl4TVY=',
160160
);
161161
$pc = new Pusher\Pusher(PUSHERAPP_AUTHKEY, PUSHERAPP_SECRET, PUSHERAPP_APPID, $options);
162162
$pc->setLogger(new TestLogger());
@@ -171,9 +171,9 @@ public function testTriggerBatchWithMultipleEncryptedEventsSuccess()
171171
public function testTriggerBatchWithMultipleCombinationsofStringsAndObjectsWithEncryptedEventSuccess()
172172
{
173173
$options = array(
174-
'useTLS' => true,
175-
'host' => PUSHERAPP_HOST,
176-
'encryption_master_key' => 'cAzRH3W9FZM3iXqSNIGtKztwNuCz9xMV',
174+
'useTLS' => true,
175+
'host' => PUSHERAPP_HOST,
176+
'encryption_master_key_base64' => 'Y0F6UkgzVzlGWk0zaVhxU05JR3RLenR3TnVDejl4TVY=',
177177
);
178178
$pc = new Pusher\Pusher(PUSHERAPP_AUTHKEY, PUSHERAPP_SECRET, PUSHERAPP_APPID, $options);
179179
$pc->setLogger(new TestLogger());
@@ -205,9 +205,9 @@ public function testTriggerBatchMultipleEventsWithEncryptedEventWithoutEncryptio
205205
public function testTriggerBatchWithMultipleEncryptedEventsWithEncryptionMasterKeySuccess()
206206
{
207207
$options = array(
208-
'useTLS' => true,
209-
'host' => PUSHERAPP_HOST,
210-
'encryption_master_key' => 'cAzRH3W9FZM3iXqSNIGtKztwNuCz9xMV',
208+
'useTLS' => true,
209+
'host' => PUSHERAPP_HOST,
210+
'encryption_master_key_base64' => 'Y0F6UkgzVzlGWk0zaVhxU05JR3RLenR3TnVDejl4TVY=',
211211
);
212212
$pc = new Pusher\Pusher(PUSHERAPP_AUTHKEY, PUSHERAPP_SECRET, PUSHERAPP_APPID, $options);
213213
$pc->setLogger(new TestLogger());

tests/acceptance/triggerTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ protected function setUp(): void
99
PUSHERAPP_AUTHKEY, PUSHERAPP_SECRET and
1010
PUSHERAPP_APPID keys.');
1111
} else {
12-
$this->pusher = new Pusher\Pusher(PUSHERAPP_AUTHKEY, PUSHERAPP_SECRET, PUSHERAPP_APPID, array(), PUSHERAPP_HOST);
12+
$this->pusher = new Pusher\Pusher(PUSHERAPP_AUTHKEY, PUSHERAPP_SECRET, PUSHERAPP_APPID, ['host' => PUSHERAPP_HOST]);
1313
$this->pusher->setLogger(new TestLogger());
1414
}
1515
}
@@ -98,8 +98,9 @@ public function testTriggeringEventOnMultipleChannels()
9898

9999
public function testTriggeringEventOnPrivateEncryptedChannelSuccess()
100100
{
101-
$options = array('encryption_master_key' => 'cAzRH3W9FZM3iXqSNIGtKztwNuCz9xMV');
102-
$this->pusher = new Pusher\Pusher(PUSHERAPP_AUTHKEY, PUSHERAPP_SECRET, PUSHERAPP_APPID, $options, PUSHERAPP_HOST);
101+
$options = ['encryption_master_key_base64' => 'Y0F6UkgzVzlGWk0zaVhxU05JR3RLenR3TnVDejl4TVY=',
102+
'host' => PUSHERAPP_HOST];
103+
$this->pusher = new Pusher\Pusher(PUSHERAPP_AUTHKEY, PUSHERAPP_SECRET, PUSHERAPP_APPID, $options);
103104

104105
$data = array('event_name' => 'event_data');
105106
$channels = array('private-encrypted-ceppaio');
@@ -111,8 +112,9 @@ public function testTriggeringEventOnMultipleChannelsWithEncryptedChannelPresent
111112
{
112113
$this->expectException(\Pusher\PusherException::class);
113114

114-
$options = array('encryption_master_key' => 'cAzRH3W9FZM3iXqSNIGtKztwNuCz9xMV');
115-
$this->pusher = new Pusher\Pusher(PUSHERAPP_AUTHKEY, PUSHERAPP_SECRET, PUSHERAPP_APPID, $options, PUSHERAPP_HOST);
115+
$options = ['encryption_master_key_base64' => 'Y0F6UkgzVzlGWk0zaVhxU05JR3RLenR3TnVDejl4TVY=',
116+
'host' => PUSHERAPP_HOST];
117+
$this->pusher = new Pusher\Pusher(PUSHERAPP_AUTHKEY, PUSHERAPP_SECRET, PUSHERAPP_APPID, $options);
116118

117119
$data = array('event_name' => 'event_data');
118120
$channels = array('my-chan-ceppaio', 'private-encrypted-ceppaio');

0 commit comments

Comments
 (0)