Skip to content

Commit 8752744

Browse files
committed
Updated to ably-php 0.9
Added library flavour string test
1 parent d128d5b commit 8752744

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
],
1313
"require": {
1414
"php": ">=5.4",
15-
"ably/ably-php": "~0.8",
15+
"ably/ably-php": "~0.9",
1616
"laravel/framework": ">=5.1.0"
1717
},
1818
"require-dev": {

src/AblyFactory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public function make($clientOptions = null)
3434
*/
3535
protected function createInstance($clientOptions)
3636
{
37+
AblyRest::setLibraryFlavourString('laravel');
38+
3739
return new AblyRest($clientOptions);
3840
}
39-
}
41+
}

src/AblyServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public function boot()
3333
public function register()
3434
{
3535
$this->app->singleton('ably', function($app) {
36+
AblyRest::setLibraryFlavourString('laravel');
37+
3638
return new AblyRest(config('ably'));
3739
});
3840
}

tests/AblyLaravelTest.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
use Ably\Http;
3+
24
class AblyLaravelTest extends Orchestra\Testbench\TestCase
35
{
46
const TEST_KEY = 'unit.test:key';
@@ -128,4 +130,35 @@ public function testInstances()
128130
$this->assertInstanceOf(\Ably\Auth::class, $factoryInstanceAuth);
129131
$this->assertInstanceOf(\Ably\Auth::class, $factoryInstanceAuth2);
130132
}
131-
}
133+
134+
public function testAblyFlavourString()
135+
{
136+
$ablyFactory = App::make('\Ably\Laravel\AblyFactory');
137+
$ably = $ablyFactory->make([
138+
'key' => self::TEST_KEY,
139+
'httpClass' => 'HttpMock',
140+
]);
141+
142+
$ably->time();
143+
$this->assertRegExp('/php-laravel-[0-9]+\.[0-9]+\.[0-9]+/', $ably->http->lastHeaders['X-Ably-Lib']);
144+
}
145+
}
146+
147+
148+
class HttpMock extends Http
149+
{
150+
public $lastUrl;
151+
public $lastHeaders;
152+
153+
public function request($method, $url, $headers = array(), $params = array())
154+
{
155+
$this->lastUrl = $url;
156+
$this->lastHeaders = $headers;
157+
158+
// mock response to /time
159+
return array(
160+
'headers' => "HTTP/1.1 200 OK\n",
161+
'body' => array(round(microtime(true) * 1000 ), 0),
162+
);
163+
}
164+
}

0 commit comments

Comments
 (0)