Skip to content

Commit 5736fd6

Browse files
Merge pull request #260 from MarcinOrlowski/dev
Release v12.0.1
2 parents e63f774 + 9a80230 commit 5736fd6

File tree

8 files changed

+46
-9
lines changed

8 files changed

+46
-9
lines changed

.github/workflows/phpunit.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ jobs:
2828
matrix:
2929
# quotes are needed it is treated as a number and zero at decimal part is gone
3030
# at runtime i.e. 8.10 -> 8.1, while "8.10" => "8.10".
31-
laravel: ["11.0"]
32-
php: ["8.2"]
31+
laravel: ["12.0"]
32+
php: ["8.2", "8.3", "8.4"]
3333

3434
runs-on: ubuntu-latest
3535

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ vendor/
55
*.swp
66
*~
77
*.bak
8+
9+
.roo
10+
.roomodes

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2016-2020 Marcin Orlowski <mail (#) marcinorlowski (.) com>
3+
Copyright (c) 2016-2025 Marcin Orlowski <mail (#) marcinorlowski (.) com>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
66
files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,5 @@ Development branch:
6767

6868
## License ##
6969

70-
* Written and copyrighted &copy;2016-2024 by Marcin Orlowski <mail (#) marcinorlowski (.) com>
70+
* Written and copyrighted &copy;2016-2025 by Marcin Orlowski <mail (#) marcinorlowski (.) com>
7171
* ResponseBuilder is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "marcin-orlowski/laravel-api-response-builder",
33
"description": "Helps building nice, normalized and easy to consume Laravel REST API.",
44
"homepage": "https://github.com/MarcinOrlowski/laravel-api-response-builder",
5-
"version": "12.0.0",
5+
"version": "12.0.1",
66
"keywords": [
77
"laravel",
88
"laravel10",

docs/CHANGES.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,19 @@ should be able to easily backport future new features to older versions rather e
1818

1919
## CHANGE LOG ##
2020

21+
* v12.0.1 (2025-04-16)
22+
* [RB-255] Fixed `ToArrayConverter` using a new Request instance instead of the actual request.
23+
* [BR-256] Fixed `ToArrayConverter` potentially causing fatal error if object lacks `toArray` method.
24+
* [GH-261] Updated GitHub Actions workflow to test against Laravel 12, PHP 8.3, and PHP 8.4.
25+
2126
* v12.0.0 (2025-04-16)
2227
* Added support for Laravel v12.
2328

2429
* v11.0.0 (2024-05-06)
25-
* **BACKWARD INCOMPATIBLE CHANGES** ([more info](compatibility.md)).
2630
* Added support for Laravel v11.
2731
* Corrected documentation (thanks to Ehsan Soleimanian)
2832

2933
* v10.0.0 (2023-02-20)
30-
* **BACKWARD INCOMPATIBLE CHANGES** ([more info](compatibility.md)).
3134
* Added support for Laravel v10.
3235

3336
* v9.4.0 (2023-02-18)

src/Converters/ToArrayConverter.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
* @link https://github.com/MarcinOrlowski/laravel-api-response-builder
1313
*/
1414

15-
use Illuminate\Contracts\Support\Arrayable;
1615
use Illuminate\Http\Resources\Json\JsonResource;
1716
use MarcinOrlowski\ResponseBuilder\Contracts\ConverterContract;
1817
use MarcinOrlowski\ResponseBuilder\Exceptions as Ex;
@@ -38,8 +37,15 @@ public function convert(object $obj, array $config): array
3837
{
3938
Validator::assertIsObject('obj', $obj);
4039

40+
if (!\method_exists($obj, 'toArray')) {
41+
$cls = \get_class($obj);
42+
throw new \InvalidArgumentException(
43+
"Object of class '{$cls}' does not have a 'toArray' method."
44+
);
45+
}
46+
4147
/** @var JsonResource $obj */
42-
$request = new \Illuminate\Http\Request();
48+
$request = \request();
4349
return (array)$obj->toArray($request);
4450
}
4551

tests/phpunit/Converter/ConverterTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,29 @@ public function testSubclassOfConfiguredClassConversion(): void
8080
$this->assertEquals($child_val, $result[ TestModel::FIELD_NAME ]);
8181
}
8282

83+
/**
84+
* Checks if ToArrayConverter throws exception for object without toArray method.
85+
*/
86+
public function testToArrayConverterThrowsExceptionForObjectWithoutToArrayMethod(): void
87+
{
88+
// GIVEN an object without a toArray method
89+
$obj = new \stdClass();
90+
$obj->foo = Generator::getRandomString('foo');
91+
92+
// HAVING configuration mapping stdClass to ToArrayConverter
93+
$key = Generator::getRandomString('key');
94+
Config::set(RB::CONF_KEY_CONVERTER_CLASSES, [
95+
\get_class($obj) => [
96+
RB::KEY_HANDLER => ToArrayConverter::class,
97+
RB::KEY_KEY => $key,
98+
],
99+
]);
100+
101+
// THEN we expect an exception
102+
$this->expectException(\InvalidArgumentException::class);
103+
104+
// WHEN we try to convert the object
105+
(new Converter())->convert($obj);
106+
}
107+
83108
} // end of class

0 commit comments

Comments
 (0)