Skip to content

Commit 06b8d04

Browse files
sonologicoJon Elverkilde
andauthored
Use pusher cli in CI to have a subscriber active (#349)
Some of our acceptance tests require a channel to have subscriber. We're now using the pusher cli tool to automate tha t in the CI. Co-authored-by: Jon Elverkilde <[email protected]>
1 parent 7ed4a62 commit 06b8d04

File tree

9 files changed

+33
-13
lines changed

9 files changed

+33
-13
lines changed

.github/workflows/test.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,24 @@ jobs:
3737
- name: Run unit tests
3838
run: composer exec phpunit tests/unit
3939

40+
- uses: actions/checkout@v2
41+
with:
42+
repository: pusher/public_actions
43+
path: .github/actions
44+
45+
- uses: ./.github/actions/install-pusher-cli
46+
4047
- name: Run acceptance tests
4148
env:
4249
PUSHERAPP_APPID: ${{ secrets.CI_APP_ID }}
4350
PUSHERAPP_AUTHKEY: ${{ secrets.CI_APP_KEY }}
4451
PUSHERAPP_SECRET: ${{ secrets.CI_APP_SECRET }}
4552
PUSHERAPP_CLUSTER: ${{ secrets.CI_APP_CLUSTER }}
46-
run: composer exec phpunit tests/acceptance
53+
PUSHER_API_KEY: ${{ secrets.CI_API_KEY }}
54+
run: |
55+
echo "$PUSHER_API_KEY" | pusher login
56+
export TEST_CHANNEL="test-${RANDOM}-${RANDOM}"
57+
echo $TEST_CHANNEL
58+
pusher channels apps subscribe --app-id "$PUSHERAPP_APPID" --channel $TEST_CHANNEL &
59+
sleep 5
60+
composer exec phpunit tests/acceptance

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"paragonie/sodium_compat": "^1.6"
1313
},
1414
"require-dev": {
15-
"phpunit/phpunit": "^8.5|^9.3",
15+
"phpunit/phpunit": "^9.3",
1616
"overtrue/phplint": "^2.3"
1717
},
1818
"autoload": {

tests/acceptance/ChannelQueryTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ public function testFilterByPrefixNoChannels(): void
5353

5454
public function testFilterByPrefixOneChannel(): void
5555
{
56+
$channel_prefix = substr(TEST_CHANNEL, 0, 10);
5657
$options = [
57-
'filter_by_prefix' => 'my-',
58+
'filter_by_prefix' => $channel_prefix,
5859
];
5960
$result = $this->pusher->get_channels($options);
6061

@@ -88,24 +89,25 @@ public function testChannelListUsingGenericGet(): void
8889

8990
$channels = $result['channels'];
9091

91-
self::assertCount(1, $channels,
92+
self::assertGreaterThanOrEqual(1, $channels,
9293
'channels have a single my-channel present. For this test to pass you must have the "Getting Started" page open on the dashboard for the app you are testing against');
9394

94-
$my_channel = $channels['my-channel'];
95+
$my_channel = $channels[TEST_CHANNEL];
9596

9697
self::assertCount(0, $my_channel);
9798
}
9899

99100
public function testChannelListUsingGenericGetAndPrefixParam(): void
100101
{
101-
$result = $this->pusher->get('/channels', ['filter_by_prefix' => 'my-'], true);
102+
$channel_prefix = substr(TEST_CHANNEL, 0, 10);
103+
$result = $this->pusher->get('/channels', ['filter_by_prefix' => $channel_prefix], true);
102104

103105
$channels = $result['channels'];
104106

105107
self::assertCount(1, $channels,
106108
'channels have a single my-channel present. For this test to pass you must have the "Getting Started" page open on the dashboard for the app you are testing against');
107109

108-
$my_channel = $channels['my-channel'];
110+
$my_channel = $channels[TEST_CHANNEL];
109111

110112
self::assertCount(0, $my_channel);
111113
}

tests/acceptance/TriggerAsyncTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ public function testPushWithInfo(): void
5656
$expectedPresenceMyChannel->subscription_count = 0;
5757
$expectedResult = new stdClass();
5858
$expectedResult->channels = [
59-
"my-channel" => $expectedMyChannel,
59+
TEST_CHANNEL => $expectedMyChannel,
6060
"presence-my-channel" => $expectedPresenceMyChannel,
6161
];
6262

63-
$result = $this->pusher->triggerAsync(['my-channel', 'presence-my-channel'], 'my_event', ['test' => 1], ['info' => 'user_count,subscription_count'])->wait();
63+
$result = $this->pusher->triggerAsync([TEST_CHANNEL, 'presence-my-channel'], 'my_event', ['test' => 1], ['info' => 'user_count,subscription_count'])->wait();
6464
self::assertEquals($expectedResult, $result);
6565
}
6666

tests/acceptance/TriggerBatchAsyncTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function testTriggerBatchWithInfo(): void
103103
];
104104

105105
$batch = [];
106-
$batch[] = ['channel' => 'my-channel', 'name' => 'my_event', 'data' => 'test-string', 'info' => 'subscription_count'];
106+
$batch[] = ['channel' => TEST_CHANNEL, 'name' => 'my_event', 'data' => 'test-string', 'info' => 'subscription_count'];
107107
$batch[] = ['channel' => 'my-channel-2', 'name' => 'my_event', 'data' => 'test-string'];
108108
$batch[] = ['channel' => 'presence-my-channel', 'name' => 'my_event', 'data' => 'test-string', 'info' => 'user_count,subscription_count'];
109109
$result = $pc->triggerBatchAsync($batch)->wait();

tests/acceptance/TriggerBatchTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function testTriggerBatchWithInfo(): void
104104
];
105105

106106
$batch = [];
107-
$batch[] = ['channel' => 'my-channel', 'name' => 'my_event', 'data' => 'test-string', 'info' => 'subscription_count'];
107+
$batch[] = ['channel' => TEST_CHANNEL, 'name' => 'my_event', 'data' => 'test-string', 'info' => 'subscription_count'];
108108
$batch[] = ['channel' => 'my-channel-2', 'name' => 'my_event', 'data' => 'test-string'];
109109
$batch[] = ['channel' => 'presence-my-channel', 'name' => 'my_event', 'data' => 'test-string', 'info' => 'user_count,subscription_count'];
110110
$result = $pc->triggerBatch($batch);

tests/acceptance/TriggerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ public function testPushWithInfo(): void
5858
$expectedPresenceMyChannel->subscription_count = 0;
5959
$expectedResult = new stdClass();
6060
$expectedResult->channels = [
61-
"my-channel" => $expectedMyChannel,
61+
TEST_CHANNEL => $expectedMyChannel,
6262
"presence-my-channel" => $expectedPresenceMyChannel,
6363
];
6464

65-
$result = $this->pusher->trigger(['my-channel', 'presence-my-channel'], 'my_event', ['test' => 1], ['info' => 'user_count,subscription_count']);
65+
$result = $this->pusher->trigger([TEST_CHANNEL, 'presence-my-channel'], 'my_event', ['test' => 1], ['info' => 'user_count,subscription_count']);
6666
self::assertEquals($expectedResult, $result);
6767
}
6868

tests/bootstrap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@
1010
define('PUSHERAPP_APPID', getenv('PUSHERAPP_APPID'));
1111

1212
define('PUSHERAPP_CLUSTER', getenv('PUSHERAPP_CLUSTER'));
13+
14+
define('TEST_CHANNEL', getenv('TEST_CHANNEL'));
1315
}

tests/config.example.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
const PUSHERAPP_AUTHKEY = '';
55
const PUSHERAPP_SECRET = '';
66
const PUSHERAPP_CLUSTER = 'eu';
7+
const TEST_CHANNEL = 'my-channel';
8+
const CHANNEL_PREFIX = 'my-';

0 commit comments

Comments
 (0)