Skip to content

Commit

Permalink
Merge pull request #46 from tarfin-labs/laravel-12
Browse files Browse the repository at this point in the history
Laravel 12
  • Loading branch information
frkcn authored Feb 24, 2025
2 parents 5b3d3ad + cee7eb2 commit 2b66889
Show file tree
Hide file tree
Showing 15 changed files with 139 additions and 122 deletions.
65 changes: 30 additions & 35 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,41 @@
name: tests

on: [push, pull_request]
on:
push:
branches:
- master
- '*.x'
pull_request:

jobs:
test:

runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
php: [7.4, '8.0', 8.1, 8.2, 8.3]
laravel: [8, 9, 10, 11]
exclude:
- php: 7.4
laravel: 9
- php: 7.4
laravel: 10
- php: 7.4
laravel: 11
- php: '8.0'
laravel: 10
- php: '8.0'
laravel: 11
- php: 8.1
laravel: 11
- php: 8.2
laravel: 8

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}

steps:
- name: Checkout the code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: simplexml
php: [8.2, 8.3, 8.4]
laravel: [11, 12]
stability: [prefer-lowest, prefer-stable]

- name: Install dependencies
run: composer install --no-progress --no-ansi --profile --no-interaction --no-scripts --prefer-dist
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - Stability ${{ matrix.stability }}

- name: Execute tests
run: vendor/bin/phpunit --testdox --colors=always --exclude-group skipped
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip
ini-values: error_reporting=E_ALL
tools: composer:v2
coverage: none

- name: Install dependencies
run: |
composer update --prefer-dist --no-interaction --no-progress --${{ matrix.stability }}
- name: Execute tests
run: vendor/bin/phpunit --testdox --colors=always --exclude-group skipped
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ coverage
/.idea
/phpunit.xml
.phpunit.result.cache
.phpunit.cache
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to `netgsm` will be documented in this file

## Unreleased

## [5.0.0] - 2025-02-20
- Laravel 12 support added.
- PHP 8.4 support added.
- Laravel 10 and below versions are no longer supported.
- PHP 8.1 and below versions are no longer supported.

## [4.6.0] - 2024-04-08

- Laravel 11 and PHP 8.3 support added.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
With this package, you can send easily [Netgsm notifications](https://www.netgsm.com.tr/dokuman/#api-dok%C3%BCman%C4%B1) with Laravel `^8.0`.
This package also provides some simple reporting.

> This package requires PHP `7.3` or higher and Laravel `8.0` or higher.
> For older versions of Laravel, please use version `^2.0.0` of this package!
> This package requires PHP `8.2` or higher and Laravel `11.0` or higher.
> For older versions of Laravel, please use version `^4.0.0` of this package!
## Contents

Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@
}
],
"require": {
"php": "^7.4|^8.0|^8.1|^8.2|^8.3",
"php": "^8.2|^8.3|^8.4",
"guzzlehttp/guzzle": "^7.1",
"illuminate/support": "^8.0|^9.0|^10.0|^11.0",
"illuminate/notifications": "^8.0|^9.0|^10.0|^11.0",
"illuminate/translation": "^8.0|^9.0|^10.0|^11.0",
"nesbot/carbon": "^2.0",
"illuminate/support": "^11.0|^12.0",
"illuminate/notifications": "^11.0|^12.0",
"illuminate/translation": "^11.0|^12.0",
"nesbot/carbon": "^3.8.5",
"ext-simplexml": "*"
},
"require-dev": {
"fakerphp/faker": "^1.14",
"phpunit/phpunit": "^9.4",
"phpunit/phpunit": "^10.0|^11.0",
"mockery/mockery": "^1.4",
"orchestra/testbench": "^6.0|^7.0|^8.0|^9.0"
"orchestra/testbench": "^9.0|^10.0"
},
"autoload": {
"psr-4": {
Expand Down
34 changes: 15 additions & 19 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
</report>
</coverage>
<testsuites>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
2 changes: 1 addition & 1 deletion src/Report/NetgsmSmsDetailReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function processRow($line): array
public function parseResponse(string $response): Collection
{
$this->validateResponse($response);
$response = utf8_encode(html_entity_decode($response));
$response = mb_convert_encoding(html_entity_decode($response), 'UTF-8', 'ISO-8859-9');
$xml = new SimpleXMLElement($response);

$collection = new Collection();
Expand Down
3 changes: 2 additions & 1 deletion tests/NetGsmChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use GuzzleHttp\Client;
use Mockery;
use PHPUnit\Framework\Attributes\Test;
use TarfinLabs\Netgsm\Netgsm;
use TarfinLabs\Netgsm\NetgsmChannel;
use TarfinLabs\Netgsm\Tests\notification\TestNotifiable;
Expand Down Expand Up @@ -50,7 +51,7 @@ public function setUp(): void
$this->channel = new NetGsmChannel($this->netgsm);
}

/** @test */
#[Test]
public function test_it_shares_message(): void
{
$this->netgsm->shouldReceive('sendSms')->once();
Expand Down
54 changes: 47 additions & 7 deletions tests/NetGsmIysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
use Mockery;
use PHPUnit\Framework\Attributes\Test;
use Psr\Http\Message\ResponseInterface;
use TarfinLabs\Netgsm\Iys\Requests\Add;
use TarfinLabs\Netgsm\Iys\Requests\Search;
Expand Down Expand Up @@ -32,7 +33,7 @@ public function setUp(): void
]);
}

/** @test */
#[Test]
public function it_makes_add_requests_for_iys_addresses()
{
$data = [
Expand Down Expand Up @@ -80,16 +81,27 @@ public function it_makes_add_requests_for_iys_addresses()
$iysAddress = new Add();
$iysAddress->setDefaults($data['json']['body']['data'][0]);

$successResponse = [
'code' => '0',
'error' => 'false',
'uid' => '73113cb9-dff0-415b-9491-xxxxxxxxxx',
];

$this->httpClient
->shouldReceive('request')
->withSomeOfArgs('POST', 'iys/add', $data)
->once()
->andReturn(new Response());
->andReturn(new Response(200, [], json_encode($successResponse)));

$this->netgsm->iys()->addAddress($iysAddress)->send();
$response = $this->netgsm->iys()->addAddress($iysAddress)->send();
$decodedResponse = json_decode($response, true);

$this->assertEquals('0', $decodedResponse['code']);
$this->assertEquals('false', $decodedResponse['error']);
$this->assertEquals('73113cb9-dff0-415b-9491-xxxxxxxxxx', $decodedResponse['uid']);
}

/** @test */
#[Test]
public function it_makes_search_requests_for_iys_addresses()
{
$data = [
Expand Down Expand Up @@ -118,12 +130,40 @@ public function it_makes_search_requests_for_iys_addresses()
$iysSearch = new Search();
$iysSearch->setDefaults($data['json']['body']['data'][0]);

$searchResponse = [
'code' => '0',
'error' => 'false',
'query' => [
'consentDate' => '2020-11-06 11:22:34',
'source' => 'HS_FIZIKSEL_ORTAM',
'recipient' => '+905XXXXXXXXX',
'recipientType' => 'BIREYSEL',
'type' => 'MESAJ',
'status' => 'ONAY',
'creationDate' => '2020-11-06 11:23:49',
'retailerAccessCount' => 0,
],
];

$this->httpClient
->shouldReceive('request')
->withSomeOfArgs('POST', 'iys/search', $data)
->once()
->andReturn(new Response());

$this->netgsm->iys()->searchAddress($iysSearch)->send();
->andReturn(new Response(200, [], json_encode($searchResponse)));

$response = $this->netgsm->iys()->searchAddress($iysSearch)->send();
$decodedResponse = json_decode($response, true);

$this->assertEquals('0', $decodedResponse['code']);
$this->assertEquals('false', $decodedResponse['error']);
$this->assertArrayHasKey('query', $decodedResponse);
$this->assertEquals('ONAY', $decodedResponse['query']['status']);
$this->assertEquals('MESAJ', $decodedResponse['query']['type']);
$this->assertEquals('HS_FIZIKSEL_ORTAM', $decodedResponse['query']['source']);
$this->assertEquals('BIREYSEL', $decodedResponse['query']['recipientType']);
$this->assertEquals('+905XXXXXXXXX', $decodedResponse['query']['recipient']);
$this->assertEquals('2020-11-06 11:22:34', $decodedResponse['query']['consentDate']);
$this->assertEquals('2020-11-06 11:23:49', $decodedResponse['query']['creationDate']);
$this->assertEquals(0, $decodedResponse['query']['retailerAccessCount']);
}
}
17 changes: 9 additions & 8 deletions tests/NetGsmMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

namespace TarfinLabs\Netgsm\Tests;

use PHPUnit\Framework\Attributes\Test;
use TarfinLabs\Netgsm\Sms\NetgsmSmsMessage;

class NetGsmMessageTest extends BaseTestCase
{
/** @test */
#[Test]
public function it_supports_create_method()
{
$content = $this->faker->sentence;
Expand All @@ -17,7 +18,7 @@ public function it_supports_create_method()
$this->assertEquals($content, $message->getMessage());
}

/** @test */
#[Test]
public function it_can_set_body()
{
$content = $this->faker->sentence;
Expand All @@ -27,7 +28,7 @@ public function it_can_set_body()
$this->assertEquals($content, $message->getMessage());
}

/** @test */
#[Test]
public function it_can_set_header()
{
$name = $this->faker->company;
Expand All @@ -37,7 +38,7 @@ public function it_can_set_header()
$this->assertEquals($name, $message->getHeader());
}

/** @test */
#[Test]
public function it_can_set_send_method()
{
$method = $this->faker->randomElement(['xml', 'get']);
Expand All @@ -47,7 +48,7 @@ public function it_can_set_send_method()
$this->assertEquals($method, $message->getSendMethod());
}

/** @test */
#[Test]
public function it_can_set_needs_authorized_data()
{
$authorizedData = $this->faker->boolean;
Expand All @@ -57,23 +58,23 @@ public function it_can_set_needs_authorized_data()
$this->assertEquals($authorizedData, $message->isAuthorizedData());
}

/** @test */
#[Test]
public function it_can_set_recipients_from_array()
{
$message = (new NetgsmSmsMessage)->setRecipients([31650520659, 31599858770]);

$this->assertEquals(['31650520659', '31599858770'], $message->getRecipients());
}

/** @test */
#[Test]
public function it_can_set_recipients_from_integer()
{
$message = (new NetgsmSmsMessage)->setRecipients(31650520659);

$this->assertEquals([31650520659], $message->getRecipients());
}

/** @test */
#[Test]
public function it_can_set_recipients_from_string()
{
$message = (new NetgsmSmsMessage)->setRecipients('31650520659');
Expand Down
Loading

0 comments on commit 2b66889

Please sign in to comment.