Skip to content

Commit 6a1e78d

Browse files
committed
Api Exception update
1 parent f15462a commit 6a1e78d

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

src/Http/Controllers/Api/Controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public function handleUpdateAction($id, $request)
262262
} catch (\Illuminate\Database\QueryException $exception) {
263263
$message = config('app.debug') ? $exception->getMessage() : 'Failed to update Record';
264264

265-
throw new ApiException($message);
265+
throw new ApiException($message, $exception->getCode(), $exception);
266266
} catch (\Exception $exception) {
267267
DB::rollback();
268268

tests/LaravelApiHelpersTest.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace Phpsa\LaravelApiController\Tests;
4+
5+
use Illuminate\Http\Request;
6+
use Orchestra\Testbench\TestCase;
7+
use Phpsa\LaravelApiController\Helpers;
8+
use Phpsa\LaravelApiController\UriParser;
9+
use Phpsa\LaravelApiController\ServiceProvider;
10+
use Phpsa\LaravelApiController\Facades\LaravelApiController;
11+
12+
class LaravelApiHelpersTest extends TestCase
13+
{
14+
protected function getPackageProviders($app)
15+
{
16+
return [ServiceProvider::class];
17+
}
18+
19+
protected function getPackageAliases($app)
20+
{
21+
return [
22+
'laravel-api-controller' => LaravelApiController::class,
23+
];
24+
}
25+
26+
public function testSnakeCasing()
27+
{
28+
$array = [
29+
'test_one' => 'test_one',
30+
'testTwo' => 'test_two'
31+
];
32+
33+
$transposed = Helpers::snakeCaseArrayKeys($array);
34+
35+
$this->assertSame(array_keys($transposed), array_values($array));
36+
}
37+
38+
public function testCamelCasing()
39+
{
40+
$array = [
41+
'test_one' => 'testOne',
42+
'testTwo' => 'testTwo'
43+
];
44+
45+
$transposed = Helpers::camelCaseArrayKeys($array);
46+
47+
$this->assertSame(array_keys($transposed), array_values($array));
48+
}
49+
50+
public function testArrayExcludes()
51+
{
52+
$data1 = [];
53+
$data2 = [];
54+
$this->markTestSkipped('Still to build');
55+
}
56+
57+
58+
/**
59+
* camelCaseArrayKeys
60+
snakeCaseArrayKeys
61+
public static function snake(string $value): string
62+
filterFieldsFromRequest
63+
excludeArrayValues
64+
*/
65+
}

0 commit comments

Comments
 (0)