Skip to content

Commit ecdbf95

Browse files
committed
API Settings
1 parent b6e664c commit ecdbf95

File tree

4 files changed

+124
-12
lines changed

4 files changed

+124
-12
lines changed

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "api-clients/pusher",
3+
"homepage": "https://php-api-clients.org/clients/pusher",
34
"license": "MIT",
45
"minimum-stability": "dev",
56
"prefer-stable": true,
@@ -12,6 +13,7 @@
1213
"require": {
1314
"php": "^7.0",
1415
"clue/block-react": "^1.1",
16+
"ocramius/package-versions": "^1.1",
1517
"rx/websocket": "^0.9.2"
1618
},
1719
"require-dev": {

composer.lock

Lines changed: 59 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ApiSettings.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Pusher;
4+
5+
use PackageVersions\Versions;
6+
7+
final class ApiSettings
8+
{
9+
/**
10+
* @param string $version
11+
* @return string
12+
*/
13+
public static function getVersion(string $version = ''): string
14+
{
15+
if ($version === '') {
16+
$version = Versions::getVersion('api-clients/pusher');
17+
}
18+
19+
list($version, $hash) = explode('@', $version);
20+
21+
if (substr($version, -4) === '-dev') {
22+
return '0.0.1-' . $hash;
23+
}
24+
25+
return $version;
26+
}
27+
}

tests/ApiSettingsTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace ApiClients\Tests\Pusher;
5+
6+
use ApiClients\Pusher\ApiSettings;
7+
use ApiClients\Tools\TestUtilities\TestCase;
8+
9+
class ApiSettingsTest extends TestCase
10+
{
11+
public function getVersionProvider()
12+
{
13+
yield [
14+
'9999999-dev@abcdefghijklopqrstuwxyz',
15+
'0.0.1-abcdefghijklopqrstuwxyz',
16+
];
17+
18+
yield [
19+
'1.0.0@abcdefghijklopqrstuwxyz',
20+
'1.0.0',
21+
];
22+
}
23+
24+
/**
25+
* @dataProvider getVersionProvider
26+
*/
27+
public function testGetVersion(string $input, string $output)
28+
{
29+
$this->assertSame($output, ApiSettings::getVersion($input));
30+
}
31+
32+
public function testGetVersionDefault()
33+
{
34+
$this->assertTrue(strlen(ApiSettings::getVersion()) > 0);
35+
}
36+
}

0 commit comments

Comments
 (0)