Skip to content

Commit

Permalink
Upgrade PHP requirement to ~8.1, upgrade all packages, switch CI/CD f…
Browse files Browse the repository at this point in the history
…rom Travis to GitHub actions (#19)
  • Loading branch information
TortitasT authored Sep 29, 2023
1 parent effc5f0 commit f1f6e86
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 199 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Tests

on:
push:
branches: ["1.0"]
pull_request:
branches: ["1.0"]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Setup PHP with tools
uses: shivammathur/setup-php@v2
if: ${{ env.ACT }}
with:
php-version: "8.2"
tools: phpunit

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run test suite
run: composer run-script test
25 changes: 0 additions & 25 deletions .travis.yml

This file was deleted.

66 changes: 35 additions & 31 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
{
"name": "descom/sms-php",
"description": "Build your SMS application with PHP, easy SMS sending and worldwide coverage",
"type": "library",
"license": "MIT",
"keywords": ["sms", "php", "descom"],
"homepage": "https://www.descomsms.com",
"authors": [
{
"name": "Descom Soporte",
"email": "soporte@descom.es"
}
],
"require": {
"php": "^5.6|^7.0",
"guzzlehttp/guzzle": "~6.0|~5.3.1"
},
"autoload": {
"psr-4": {
"Descom\\Sms\\": "src/"
}
},
"require-dev": {
"phpunit/phpunit": "^5.7|^7.0"
},
"autoload-dev": {
"psr-4": {
"Descom\\Sms\\Test\\": "tests"
}
},
"scripts": {
"test": "vendor/bin/phpunit"
"name": "descom/sms-php",
"description": "Build your SMS application with PHP, easy SMS sending and worldwide coverage",
"type": "library",
"license": "MIT",
"keywords": [
"sms",
"php",
"descom"
],
"homepage": "https://www.descomsms.com",
"authors": [
{
"name": "Descom Soporte",
"email": "soporte@descom.es"
}
],
"require": {
"php": "~8.1",
"guzzlehttp/guzzle": "^7.0"
},
"autoload": {
"psr-4": {
"Descom\\Sms\\": "src/"
}
},
"require-dev": {
"phpunit/phpunit": "^10.3"
},
"autoload-dev": {
"psr-4": {
"Descom\\Sms\\Test\\": "tests"
}
},
"scripts": {
"test": "vendor/bin/phpunit"
}
}
16 changes: 0 additions & 16 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="League Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<logging>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</phpunit>
52 changes: 0 additions & 52 deletions src/Http/GuzzleV5.php

This file was deleted.

51 changes: 0 additions & 51 deletions src/Http/GuzzleV6.php

This file was deleted.

32 changes: 24 additions & 8 deletions src/Http/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Descom\Sms\Http;

use GuzzleHttp\ClientInterface;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\RequestException;

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

if ($version[0] === '6') {
$sms = new GuzzleV6();
$httpData = [
'headers' => $headers,
'debug' => $this->debug,
];

return $sms->sendHttp($verb, $path, $headers, $data);
} elseif ($version[0] === '5') {
$sms = new GuzzleV5();
if (count($data) > 0) {
$httpData['json'] = $data;
}

return $sms->sendHttp($verb, $path, $headers, $data);
try {
$result = $client->request($verb, $path, $httpData);
$response->status = $result->getStatusCode();
$response->message = $result->getBody()->getContents();
} catch (ClientException $e) {
$response->status = $e->getResponse()->getStatusCode();
$response->message = $e->getResponse()->getBody(true);
} catch (RequestException $e) {
$response->status = 500;
$response->message = $e->getMessage();
}

return $response;
}
}
Loading

0 comments on commit f1f6e86

Please sign in to comment.