Skip to content

Commit f1f6e86

Browse files
authored
Upgrade PHP requirement to ~8.1, upgrade all packages, switch CI/CD from Travis to GitHub actions (#19)
1 parent effc5f0 commit f1f6e86

File tree

8 files changed

+116
-199
lines changed

8 files changed

+116
-199
lines changed

.github/workflows/test.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: ["1.0"]
6+
pull_request:
7+
branches: ["1.0"]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Setup PHP with tools
20+
uses: shivammathur/setup-php@v2
21+
if: ${{ env.ACT }}
22+
with:
23+
php-version: "8.2"
24+
tools: phpunit
25+
26+
- name: Validate composer.json and composer.lock
27+
run: composer validate --strict
28+
29+
- name: Cache Composer packages
30+
id: composer-cache
31+
uses: actions/cache@v3
32+
with:
33+
path: vendor
34+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
35+
restore-keys: |
36+
${{ runner.os }}-php-
37+
38+
- name: Install dependencies
39+
run: composer install --prefer-dist --no-progress
40+
41+
- name: Run test suite
42+
run: composer run-script test

.travis.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

composer.json

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
11
{
2-
"name": "descom/sms-php",
3-
"description": "Build your SMS application with PHP, easy SMS sending and worldwide coverage",
4-
"type": "library",
5-
"license": "MIT",
6-
"keywords": ["sms", "php", "descom"],
7-
"homepage": "https://www.descomsms.com",
8-
"authors": [
9-
{
10-
"name": "Descom Soporte",
11-
"email": "soporte@descom.es"
12-
}
13-
],
14-
"require": {
15-
"php": "^5.6|^7.0",
16-
"guzzlehttp/guzzle": "~6.0|~5.3.1"
17-
},
18-
"autoload": {
19-
"psr-4": {
20-
"Descom\\Sms\\": "src/"
21-
}
22-
},
23-
"require-dev": {
24-
"phpunit/phpunit": "^5.7|^7.0"
25-
},
26-
"autoload-dev": {
27-
"psr-4": {
28-
"Descom\\Sms\\Test\\": "tests"
29-
}
30-
},
31-
"scripts": {
32-
"test": "vendor/bin/phpunit"
2+
"name": "descom/sms-php",
3+
"description": "Build your SMS application with PHP, easy SMS sending and worldwide coverage",
4+
"type": "library",
5+
"license": "MIT",
6+
"keywords": [
7+
"sms",
8+
"php",
9+
"descom"
10+
],
11+
"homepage": "https://www.descomsms.com",
12+
"authors": [
13+
{
14+
"name": "Descom Soporte",
15+
"email": "soporte@descom.es"
3316
}
17+
],
18+
"require": {
19+
"php": "~8.1",
20+
"guzzlehttp/guzzle": "^7.0"
21+
},
22+
"autoload": {
23+
"psr-4": {
24+
"Descom\\Sms\\": "src/"
25+
}
26+
},
27+
"require-dev": {
28+
"phpunit/phpunit": "^10.3"
29+
},
30+
"autoload-dev": {
31+
"psr-4": {
32+
"Descom\\Sms\\Test\\": "tests"
33+
}
34+
},
35+
"scripts": {
36+
"test": "vendor/bin/phpunit"
37+
}
3438
}

phpunit.xml.dist

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,12 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit bootstrap="vendor/autoload.php"
33
backupGlobals="false"
4-
backupStaticAttributes="false"
54
colors="true"
6-
verbose="true"
7-
convertErrorsToExceptions="true"
8-
convertNoticesToExceptions="true"
9-
convertWarningsToExceptions="true"
105
processIsolation="false"
116
stopOnFailure="false">
127
<testsuites>
138
<testsuite name="League Test Suite">
149
<directory>tests</directory>
1510
</testsuite>
1611
</testsuites>
17-
<filter>
18-
<whitelist>
19-
<directory suffix=".php">src/</directory>
20-
</whitelist>
21-
</filter>
22-
<logging>
23-
<log type="junit" target="build/report.junit.xml"/>
24-
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
25-
<log type="coverage-text" target="build/coverage.txt"/>
26-
<log type="coverage-clover" target="build/logs/clover.xml"/>
27-
</logging>
2812
</phpunit>

src/Http/GuzzleV5.php

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/Http/GuzzleV6.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/Http/Http.php

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace Descom\Sms\Http;
44

5-
use GuzzleHttp\ClientInterface;
5+
use GuzzleHttp\Client;
6+
use GuzzleHttp\Exception\ClientException;
7+
use GuzzleHttp\Exception\RequestException;
68

79
class Http
810
{
@@ -20,16 +22,30 @@ class Http
2022
*/
2123
public function sendHttp($verb, $path, array $headers, array $data = [])
2224
{
23-
$version = (string) ClientInterface::VERSION;
25+
$client = new Client(['base_uri' => 'https://api.descomsms.com/api/']);
26+
$response = new Response();
2427

25-
if ($version[0] === '6') {
26-
$sms = new GuzzleV6();
28+
$httpData = [
29+
'headers' => $headers,
30+
'debug' => $this->debug,
31+
];
2732

28-
return $sms->sendHttp($verb, $path, $headers, $data);
29-
} elseif ($version[0] === '5') {
30-
$sms = new GuzzleV5();
33+
if (count($data) > 0) {
34+
$httpData['json'] = $data;
35+
}
3136

32-
return $sms->sendHttp($verb, $path, $headers, $data);
37+
try {
38+
$result = $client->request($verb, $path, $httpData);
39+
$response->status = $result->getStatusCode();
40+
$response->message = $result->getBody()->getContents();
41+
} catch (ClientException $e) {
42+
$response->status = $e->getResponse()->getStatusCode();
43+
$response->message = $e->getResponse()->getBody(true);
44+
} catch (RequestException $e) {
45+
$response->status = 500;
46+
$response->message = $e->getMessage();
3347
}
48+
49+
return $response;
3450
}
3551
}

0 commit comments

Comments
 (0)