Skip to content

Commit 2bb3d61

Browse files
authored
Apply fixes from StyleCI (#126)
1 parent 4f219da commit 2bb3d61

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

src/LaravelNotionApiServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace FiveamCode\LaravelNotionApi;
44

5-
use Illuminate\Support\ServiceProvider;
65
use FiveamCode\LaravelNotionApi\Tests\Plugins\PestPluginHttpRecorder;
6+
use Illuminate\Support\ServiceProvider;
77

88
/**
99
* Class LaravelNotionApiServiceProvider.

tests/Pest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Illuminate\Support\Facades\Config;
66

77
uses(NotionApiTest::class)->beforeEach(function () {
8-
$dotenv = Dotenv::createImmutable(__DIR__ . '/..', '.env.testing');
8+
$dotenv = Dotenv::createImmutable(__DIR__.'/..', '.env.testing');
99
$dotenv->load();
1010
Config::set('laravel-notion-api.notion-api-token', env('NOTION_API_TOKEN'));
1111
})->in(__DIR__);

tests/RecordedEndpointCommentsTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
<?php
22

33
use Carbon\Carbon;
4-
use Dotenv\Dotenv;
54
use FiveamCode\LaravelNotionApi\Entities\Collections\CommentCollection;
65
use FiveamCode\LaravelNotionApi\Entities\Comment;
76
use FiveamCode\LaravelNotionApi\Entities\PropertyItems\RichText;
87
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
9-
use Illuminate\Support\Facades\Config;
108
use Illuminate\Support\Facades\Http;
11-
use YourVendor\YourPackage\Middleware\InterceptRequestesForRecording;
129

1310
beforeEach(function () {
1411
Http::recordAndFakeLater('https://api.notion.com/v1/comments*')
@@ -49,4 +46,4 @@
4946
$this->expectExceptionCode(404);
5047

5148
\Notion::comments()->ofBlock('cbf6b0af-6eaa-45ca-9715-9fa147ef6b17')->list();
52-
});
49+
});

tests/plugins/PestPluginHttpRecorder.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@
33
namespace FiveamCode\LaravelNotionApi\Tests\Plugins;
44

55
use GuzzleHttp\Client;
6-
use Illuminate\Support\Str;
76
use Illuminate\Http\Client\Request;
87
use Illuminate\Support\Facades\File;
98
use Illuminate\Support\Facades\Http;
9+
use Illuminate\Support\Str;
1010

1111
class PestPluginHttpRecorder
1212
{
1313
public static function register()
1414
{
1515
Http::macro('recordAndFakeLater', function (array|string $urls = ['*']) {
16-
17-
if (!is_array($urls)) {
16+
if (! is_array($urls)) {
1817
$urls = [$urls];
1918
}
2019

@@ -26,12 +25,12 @@ public static function register()
2625
},
2726
]);
2827
}
28+
2929
return $recorder;
3030
});
3131
}
3232
}
3333

34-
3534
class HttpRecorder
3635
{
3736
private $stubsFolder = '__recorded_stubs__';
@@ -41,12 +40,14 @@ class HttpRecorder
4140
public function storeIn($directory)
4241
{
4342
$this->stubsFolder = $directory;
43+
4444
return $this;
4545
}
4646

4747
public function minifyJson()
4848
{
4949
$this->usePrettyJson = false;
50+
5051
return $this;
5152
}
5253

@@ -57,34 +58,36 @@ public function handle(Request $request)
5758
$urlInfo = parse_url($request->url());
5859

5960
//create specific filename for storing stubs
60-
$filename = Str::lower($request->method()) . '_';
61+
$filename = Str::lower($request->method()).'_';
6162
$filename .= Str::slug(Str::replace('/', '-', $urlInfo['path']));
62-
$filename .= '_' . Str::slug(Str::replace('&', '_', Str::replace('=', '-', $urlInfo['query'])));
63+
$filename .= '_'.Str::slug(Str::replace('&', '_', Str::replace('=', '-', $urlInfo['query'])));
6364
$filename .= '.json';
6465

65-
if ($forceRecording || !File::exists('tests/' . $this->stubsFolder . '/' . $filename)) {
66-
File::makeDirectory('tests/' . $this->stubsFolder, 0777, true, true);
66+
if ($forceRecording || ! File::exists('tests/'.$this->stubsFolder.'/'.$filename)) {
67+
File::makeDirectory('tests/'.$this->stubsFolder, 0777, true, true);
6768

6869
$client = new Client();
6970
$response = $client->request($request->method(), $request->url(), [
7071
'headers' => $request->headers(),
7172
'body' => $request->body(),
72-
'http_errors' => false
73+
'http_errors' => false,
7374
]);
7475

7576
$recordedResponse = [
7677
'status' => $response->getStatusCode(),
77-
'data' => json_decode($response->getBody()->getContents(), true)
78+
'data' => json_decode($response->getBody()->getContents(), true),
7879
];
7980

8081
file_put_contents(
81-
'tests/' . $this->stubsFolder . '/' . $filename,
82+
'tests/'.$this->stubsFolder.'/'.$filename,
8283
json_encode($recordedResponse, $this->usePrettyJson ? JSON_PRETTY_PRINT : 0)
8384
);
85+
8486
return Http::response($recordedResponse['data'], $response->getStatusCode());
8587
}
8688

87-
$preRecordedData = json_decode(file_get_contents('tests/' . $this->stubsFolder . '/' . $filename), true);
89+
$preRecordedData = json_decode(file_get_contents('tests/'.$this->stubsFolder.'/'.$filename), true);
90+
8891
return Http::response($preRecordedData['data'], $preRecordedData['status']);
8992
}
9093
}

0 commit comments

Comments
 (0)