Skip to content

Commit 017eb58

Browse files
Merge pull request #8 from kennedy-osaze/upgrade-laravel-10
Add support for Laravel 10.x
2 parents c81df22 + 5be40c7 commit 017eb58

10 files changed

+46
-59
lines changed

.github/workflows/main.yml

+7-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Setup PHP
2121
uses: shivammathur/setup-php@v2
2222
with:
23-
php-version: '8.0'
23+
php-version: '8.1'
2424

2525
- name: Cache dependencies
2626
uses: actions/cache@v3
@@ -44,12 +44,13 @@ jobs:
4444
fail-fast: true
4545
matrix:
4646
os: [ubuntu-latest, windows-latest]
47-
php: [8.1, 8.0]
48-
laravel: [9.*]
47+
php: [8.2, 8.1]
48+
laravel: [10.*]
4949
stability: [prefer-lowest, prefer-stable]
5050
include:
51-
- laravel: 9.*
52-
testbench: 7.*
51+
- laravel: 10.*
52+
testbench: 8.*
53+
carbon: ^2.63
5354

5455
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
5556

@@ -78,4 +79,4 @@ jobs:
7879
run: composer check-platform-reqs --verbose
7980

8081
- name: Execute tests
81-
run: vendor/bin/phpunit --debug --verbose
82+
run: vendor/bin/phpunit

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.php-cs-fixer.cache
22
.phpunit.result.cache
3+
.phpunit.cache
34
composer.lock
45
phpunit.xml
56
vendor

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ Laravel API Response is a package that helps to provide and render a consistent
1313

1414
## Version Compatibility
1515

16-
Laravel | Laravel API Response
17-
:---------------------------|:----------------------
18-
9.x (Requires PHP >= 8.0) | 1.x
16+
Laravel | Laravel API Response
17+
:---------|:----------------------
18+
9.x | 1.x
19+
10.x | 2.x
1920

2021
## Installation
2122

composer.json

+7-8
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,15 @@
1717
}
1818
],
1919
"require": {
20-
"php": "^8.0",
21-
"illuminate/contracts": "^9.10",
22-
"illuminate/http": "^9.10",
23-
"illuminate/translation": "^9.10"
20+
"php": "^8.1",
21+
"illuminate/contracts": "^10.0",
22+
"illuminate/translation": "^10.0"
2423
},
2524
"require-dev": {
26-
"kennedy-osaze/php-cs-fixer-config": "^2.0",
27-
"nunomaduro/collision": "^6.2",
28-
"orchestra/testbench": "^7.4",
29-
"phpunit/phpunit": "^9.5"
25+
"kennedy-osaze/php-cs-fixer-config": "^2.0.1",
26+
"nunomaduro/collision": "^7.0",
27+
"orchestra/testbench": "^8.0",
28+
"phpunit/phpunit": "^10.0"
3029
},
3130
"autoload": {
3231
"psr-4": {

phpunit.xml.dist

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
55
backupGlobals="false"
6-
backupStaticAttributes="false"
6+
beStrictAboutTestsThatDoNotTestAnything="false"
77
bootstrap="vendor/autoload.php"
88
colors="true"
9-
convertDeprecationsToExceptions="true"
10-
convertErrorsToExceptions="true"
11-
convertNoticesToExceptions="true"
12-
convertWarningsToExceptions="true"
139
processIsolation="false"
1410
stopOnFailure="false"
15-
beStrictAboutOutputDuringTests="true"
16-
verbose="true"
11+
cacheDirectory=".phpunit.cache"
12+
backupStaticProperties="false"
1713
>
1814
<testsuites>
1915
<testsuite name="Laravel API Response Test Suite">
20-
<directory suffix=".php">./tests/</directory>
16+
<directory suffix="Test.php">./tests/</directory>
2117
</testsuite>
2218
</testsuites>
2319
</phpunit>

tests/ApiResponseTest.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use KennedyOsaze\LaravelApiResponse\Tests\Fakes\DummyModel;
1616
use KennedyOsaze\LaravelApiResponse\Tests\Fakes\DummyResource;
1717
use KennedyOsaze\LaravelApiResponse\Tests\Fakes\DummyResourceCollection;
18+
use PHPUnit\Framework\Attributes\DataProvider;
1819

1920
class ApiResponseTest extends TestCase
2021
{
@@ -161,9 +162,7 @@ public function testCorrectResponseReturnedOnJsonResource()
161162
DummyModel::migrate();
162163

163164
$model = DummyModel::create(['name' => 'Kennedy']);
164-
DummyModel::insert(Collection::times(5, fn ($number) => [
165-
'name' => "Kennedy:{$number}", 'created_at' => now(), 'updated_at' => now(),
166-
])->toArray());
165+
Collection::times(5)->each(fn ($number) => DummyModel::create(['name' => 'Kennedy:'.$number]));
167166

168167
$resource = new DummyResource($model);
169168
$collection = DummyResource::collection(DummyModel::all());
@@ -225,17 +224,15 @@ public function testCorrectResponseReturnedOnResourceCollection()
225224
$this->assertSame($collectionE->collection->map->resolve()->toArray(), $responseDataE['data']['data']['data']);
226225
}
227226

228-
/**
229-
* @dataProvider getRandomDataTypeProvider
230-
*/
227+
#[DataProvider('getRandomDataTypeProvider')]
231228
public function testResponseWithRandomDataTypeContent($input, $result)
232229
{
233230
$responseData = ApiResponse::create(200, 'A dummy message', $input)->getData(true);
234231

235232
$this->assertSame($result, $responseData['data']);
236233
}
237234

238-
public function getRandomDataTypeProvider()
235+
public static function getRandomDataTypeProvider()
239236
{
240237
return [
241238
'test object' => [(object) ['type' => 'string'], ['type' => 'string']],

tests/ExceptionsHandlerTest.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Support\Facades\Validator;
1010
use Illuminate\Validation\ValidationException;
1111
use KennedyOsaze\LaravelApiResponse\Tests\Fakes\ExceptionHandler;
12+
use PHPUnit\Framework\Attributes\DataProvider;
1213
use Symfony\Component\HttpFoundation\Response;
1314
use Symfony\Component\HttpKernel\Exception\HttpException;
1415
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@@ -130,17 +131,15 @@ public function testHttpExceptionWithTranslationMessageReturnsCorrectResponseDat
130131
$this->assertSame(__('api-response::errors.example_code'), $response->getData(true)['message']);
131132
}
132133

133-
/**
134-
* @dataProvider getHttpResponseExceptionProvider
135-
*/
134+
#[DataProvider('getHttpResponseExceptionProvider')]
136135
public function testHttpResponseExceptionReturnsResponseDataCorrectly($exception, $responseData)
137136
{
138137
$response = $this->handler->renderApiResponse($exception, $this->app->request);
139138

140139
$this->assertSame($responseData, $response->getData(true));
141140
}
142141

143-
public function getHttpResponseExceptionProvider()
142+
public static function getHttpResponseExceptionProvider()
144143
{
145144
return [
146145
[

tests/RendersApiResponseTraitTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ public function testResourceCollectionResponse()
6666
{
6767
DummyModel::migrate();
6868

69-
DummyModel::insert(Collection::times(5, fn ($number) => [
69+
Collection::times(3)->each(fn ($number) => DummyModel::create([
7070
'name' => "Kennedy:{$number}", 'created_at' => now(), 'updated_at' => now(),
71-
])->toArray());
71+
]));
7272

7373
$message = 'Dummy message';
7474

@@ -80,8 +80,8 @@ public function testResourceCollectionResponse()
8080
$response2 = $this->controller->resourceCollectionResponse($data2, $message);
8181
$response3 = $this->controller->resourceCollectionResponse($data3, $message, false);
8282

83-
collect([$response1, $response2, $response3])->each(fn ($response) => $this->assertSame('Dummy message', $response->getData(true)['message'])
84-
);
83+
collect([$response1, $response2, $response3])
84+
->each(fn ($response) => $this->assertSame('Dummy message', $response->getData(true)['message']));
8585

8686
$this->assertSame(DummyModel::all(['id', 'name'])->toArray(), $response1->getData(true)['data']);
8787
$this->assertTrue(Arr::has($response2->getData(true), ['data.data', 'data.links', 'data.meta']));

tests/TestCase.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
use Illuminate\Database\Eloquent\Model;
66
use Illuminate\Foundation\Testing\RefreshDatabase;
77
use KennedyOsaze\LaravelApiResponse\LaravelApiResponseServiceProvider;
8-
use Orchestra\Testbench\TestCase as OrchestraTestCase;
8+
use Orchestra\Testbench\TestCase as Orchestra;
99

10-
abstract class TestCase extends OrchestraTestCase
10+
class TestCase extends Orchestra
1111
{
1212
use RefreshDatabase;
1313

tests/TranslatableTraitTest.php

+9-16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace KennedyOsaze\LaravelApiResponse\Tests;
44

55
use KennedyOsaze\LaravelApiResponse\Tests\Fakes\TranslatableDummyClass;
6+
use PHPUnit\Framework\Attributes\DataProvider;
67

78
class TranslatableTraitTest extends TestCase
89
{
@@ -15,17 +16,15 @@ protected function setUp(): void
1516
$this->class = new TranslatableDummyClass();
1617
}
1718

18-
/**
19-
* @dataProvider getTranslatableStringProvider
20-
*/
19+
#[DataProvider('getTranslatableStringProvider')]
2120
public function testStringCanBeParsedAndTranslatableToParameterArray($input, $output)
2221
{
2322
$result = $this->class->parseStringToTranslationParameters($input);
2423

2524
$this->assertSame($output, $result);
2625
}
2726

28-
public function getTranslatableStringProvider()
27+
public static function getTranslatableStringProvider()
2928
{
3029
return [
3130
['', ['name' => '', 'attributes' => []]],
@@ -40,17 +39,15 @@ public function getTranslatableStringProvider()
4039
];
4140
}
4241

43-
/**
44-
* @dataProvider getTranslatableArrayProvider
45-
*/
42+
#[DataProvider('getTranslatableArrayProvider')]
4643
public function testTranslatableParameterArrayCanBeConvertedToString($string, $attributes, $output)
4744
{
4845
$result = $this->class->transformToTranslatableString($string, $attributes);
4946

5047
$this->assertSame($output, $result);
5148
}
5249

53-
public function getTranslatableArrayProvider()
50+
public static function getTranslatableArrayProvider()
5451
{
5552
return [
5653
['', [], ''],
@@ -61,9 +58,7 @@ public function getTranslatableArrayProvider()
6158
];
6259
}
6360

64-
/**
65-
* @dataProvider getTranslationProvider
66-
*/
61+
#[DataProvider('getTranslationProvider')]
6762
public function testGetTranslatedStringArray($key, $attributes, $prefix, $output)
6863
{
6964
$prefix = $prefix ? 'api-response::'.$prefix : $prefix;
@@ -73,7 +68,7 @@ public function testGetTranslatedStringArray($key, $attributes, $prefix, $output
7368
$this->assertSame($output, $result);
7469
}
7570

76-
public function getTranslationProvider()
71+
public static function getTranslationProvider()
7772
{
7873
return [
7974
['', [], null, ['key' => '', 'message' => '']],
@@ -83,17 +78,15 @@ public function getTranslationProvider()
8378
];
8479
}
8580

86-
/**
87-
* @dataProvider getIsTranslationKeyProvider
88-
*/
81+
#[DataProvider('getIsTranslationKeyProvider')]
8982
public function testIsTranslationKeyReturnsOutputCorrectly($input, $output)
9083
{
9184
$result = $this->class->isTranslationKey($input);
9285

9386
$this->assertSame($output, $result);
9487
}
9588

96-
public function getIsTranslationKeyProvider()
89+
public static function getIsTranslationKeyProvider()
9790
{
9891
return [
9992
['', false],

0 commit comments

Comments
 (0)