Skip to content

Commit 04aaa2c

Browse files
authored
Merge pull request #17 from ably/feature/laravel-agent-header
Php-Laravel Ably Agent Header
2 parents 3269fa9 + e3f564a commit 04aaa2c

File tree

5 files changed

+55
-10
lines changed

5 files changed

+55
-10
lines changed

.github/workflows/check.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Loosely based upon:
2+
# https://github.com/actions/starter-workflows/blob/main/ci/php.yml
3+
4+
on:
5+
pull_request:
6+
push:
7+
branches:
8+
- main
9+
10+
jobs:
11+
check:
12+
13+
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
php-version: [7.2, 7.3, 7.4, 8.0]
18+
19+
steps:
20+
- uses: actions/checkout@v2
21+
with:
22+
submodules: 'recursive'
23+
24+
- name: Set up PHP ${{ matrix.php-version }}
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: ${{ matrix.php-version }}
28+
29+
- name: Validate composer.json and composer.lock
30+
run: composer validate
31+
32+
- name: Install dependencies
33+
run: composer install --prefer-dist --no-progress --no-suggest
34+
35+
# the test script is configured in composer.json.
36+
# see: https://getcomposer.org/doc/articles/scripts.md
37+
- name: Run test suite
38+
run: composer run-script test

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
],
1313
"require": {
1414
"php": "^7.2 || ^8.0",
15-
"ably/ably-php": "~1.1.5",
16-
"laravel/framework": ">=5.1.0"
15+
"ably/ably-php": "~1.1.6",
16+
"laravel/framework": ">=6.0.0"
1717
},
1818
"require-dev": {
19-
"phpunit/phpunit": ">=4.5",
20-
"orchestra/testbench": "~3.2"
19+
"phpunit/phpunit": "^8.0.0",
20+
"orchestra/testbench": "4.13.0"
2121
},
2222
"autoload": {
2323
"psr-4": {

src/AblyFactory.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace Ably\Laravel;
33

44
use Ably\AblyRest;
5+
use Ably\Utils\Miscellaneous;
56

67
/**
78
* Instantiates AblyRest objects
@@ -31,11 +32,12 @@ public function make($clientOptions = null)
3132
* @param array|null $clientOptions
3233
*
3334
* @return \Ably\AblyRest
35+
* @throws \Ably\Exceptions\AblyException
3436
*/
3537
protected function createInstance($clientOptions)
3638
{
37-
AblyRest::setLibraryFlavourString('laravel');
38-
39+
$laravelVersion = Miscellaneous::getNumeric(app()->version());
40+
AblyRest::setAblyAgentHeader('laravel', $laravelVersion);
3941
return new AblyRest($clientOptions);
4042
}
4143
}

src/AblyServiceProvider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace Ably\Laravel;
33

44
use Ably\AblyRest;
5+
use Ably\Utils\Miscellaneous;
56
use Illuminate\Support\ServiceProvider;
67

78
class AblyServiceProvider extends ServiceProvider
@@ -33,8 +34,8 @@ public function boot()
3334
public function register()
3435
{
3536
$this->app->singleton('ably', function($app) {
36-
AblyRest::setLibraryFlavourString('laravel');
37-
37+
$laravelVersion = Miscellaneous::getNumeric(app()->version());
38+
AblyRest::setAblyAgentHeader('laravel', $laravelVersion);
3839
return new AblyRest(config('ably'));
3940
});
4041
}

tests/AblyLaravelTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
2+
3+
use Ably\AblyRest;
24
use Ably\Http;
5+
use Ably\Utils\Miscellaneous;
36

47
class AblyLaravelTest extends Orchestra\Testbench\TestCase
58
{
@@ -131,7 +134,7 @@ public function testInstances()
131134
$this->assertInstanceOf(\Ably\Auth::class, $factoryInstanceAuth2);
132135
}
133136

134-
public function testAblyFlavourString()
137+
public function testLaravelAblyAgentHeader()
135138
{
136139
$ablyFactory = App::make('\Ably\Laravel\AblyFactory');
137140
$ably = $ablyFactory->make([
@@ -140,7 +143,8 @@ public function testAblyFlavourString()
140143
]);
141144

142145
$ably->time();
143-
$this->assertRegExp('/php-laravel-[0-9]+\.[0-9]+\.[0-9]+/', $ably->http->lastHeaders['X-Ably-Lib']);
146+
$expectedLaravelHeader = 'ably-php/'.AblyRest::LIB_VERSION.' '.'php/'.Miscellaneous::getNumeric(phpversion()).' laravel/'.app()->version();
147+
$this->assertcontains( 'Ably-Agent: '.$expectedLaravelHeader, $ably->http->lastHeaders, 'Expected PHP laravel header in HTTP request' );
144148
}
145149
}
146150

0 commit comments

Comments
 (0)