Skip to content

Commit c000247

Browse files
committed
替換棄用字串助手與斷言
1 parent 08396de commit c000247

11 files changed

Lines changed: 24 additions & 16 deletions

app/Http/Controllers/Auth/RegisterController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Mail;
99
use Illuminate\Support\Facades\Validator;
1010
use Illuminate\Foundation\Auth\RegistersUsers;
11+
use Illuminate\Support\Str;
1112
use Naux\Mail\SendCloudTemplate;
1213

1314
class RegisterController extends Controller
@@ -83,7 +84,7 @@ protected function create(array $data)
8384
'email' => $data['email'],
8485
'institution' => $data['institution'],
8586
'avatar' => 'avatar5.png',
86-
'confirmation_token' => str_random(40),
87+
'confirmation_token' => Str::random(40),
8788
'settings' => [
8889
'registration_ip' => $ip,
8990
'last_login_ip' => $ip,

app/Http/Controllers/EmailController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\User;
66
use Carbon\Carbon;
77
use Illuminate\Http\Request;
8+
use Illuminate\Support\Str;
89
use Auth;
910

1011
class EmailController extends Controller
@@ -17,7 +18,7 @@ public function verify($token)
1718
return route('/');
1819
}
1920
// $user->is_active = 2;
20-
$user->confirmation_token = str_random(40);
21+
$user->confirmation_token = Str::random(40);
2122
$user->save();
2223
Auth::login($user);
2324
flash('用户激活成功 '.Carbon::now(), 'success');

database/factories/ModelFactory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use Illuminate\Support\Str;
4+
35
/*
46
|--------------------------------------------------------------------------
57
| Model Factories
@@ -19,6 +21,6 @@
1921
'name' => $faker->name,
2022
'email' => $faker->unique()->safeEmail,
2123
'password' => $password ?: $password = bcrypt('secret'),
22-
'remember_token' => str_random(10),
24+
'remember_token' => Str::random(10),
2325
];
2426
});

tests/Feature/AdminBatchLoadBookTitlesTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Database\Schema\Blueprint;
77
use Illuminate\Support\Facades\DB;
88
use Illuminate\Support\Facades\Schema;
9+
use Illuminate\Support\Str;
910
use Tests\TestCase;
1011

1112
class AdminBatchLoadBookTitlesTest extends TestCase
@@ -83,7 +84,7 @@ protected function makeUser(array $attributes = []): User
8384
'email' => uniqid('admin', true).'@example.com',
8485
'password' => bcrypt('secret'),
8586
'avatar' => 'avatar5.png',
86-
'confirmation_token' => str_random(10),
87+
'confirmation_token' => Str::random(10),
8788
]);
8889

8990
foreach ($attributes as $key => $value) {

tests/Feature/AdminBatchLoadOfficesTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Database\Schema\Blueprint;
77
use Illuminate\Support\Facades\DB;
88
use Illuminate\Support\Facades\Schema;
9+
use Illuminate\Support\Str;
910
use Tests\TestCase;
1011

1112
class AdminBatchLoadOfficesTest extends TestCase
@@ -95,7 +96,7 @@ protected function makeUser(array $attributes = []): User
9596
'email' => uniqid('admin', true).'@example.com',
9697
'password' => bcrypt('secret'),
9798
'avatar' => 'avatar5.png',
98-
'confirmation_token' => str_random(10),
99+
'confirmation_token' => Str::random(10),
99100
]);
100101

101102
foreach ($attributes as $key => $value) {

tests/Feature/AdminBatchLoadSocialInstitutesTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Database\Schema\Blueprint;
77
use Illuminate\Support\Facades\DB;
88
use Illuminate\Support\Facades\Schema;
9+
use Illuminate\Support\Str;
910
use Tests\TestCase;
1011

1112
class AdminBatchLoadSocialInstitutesTest extends TestCase
@@ -113,7 +114,7 @@ protected function makeUser(array $attributes = []): User
113114
'email' => uniqid('admin', true).'@example.com',
114115
'password' => bcrypt('secret'),
115116
'avatar' => 'avatar5.png',
116-
'confirmation_token' => str_random(10),
117+
'confirmation_token' => Str::random(10),
117118
]);
118119

119120
foreach ($attributes as $key => $value) {

tests/Feature/AdminExplainSqlTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Database\Schema\Blueprint;
77
use Illuminate\Support\Facades\DB;
88
use Illuminate\Support\Facades\Schema;
9+
use Illuminate\Support\Str;
910
use Tests\TestCase;
1011

1112
class AdminExplainSqlTest extends TestCase
@@ -46,7 +47,7 @@ protected function makeUser(array $attributes = []): User
4647
'email' => uniqid().'@example.com',
4748
'password' => bcrypt('secret'),
4849
'avatar' => 'avatar5.png',
49-
'confirmation_token' => str_random(10),
50+
'confirmation_token' => Str::random(10),
5051
]);
5152

5253
foreach ($attributes as $key => $value) {

tests/Feature/BiogMainNameSearchTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,10 @@ public function test_empty_query_returns_paginated_list(): void
320320
$result = BiogMainRepository::namesByQuery($request, 20);
321321

322322
// 空查詢應該返回 JSON 字串(原有邏輯)
323-
$this->assertInternalType('string', $result);
323+
$this->assertIsString($result);
324324

325325
$decoded = json_decode($result, true);
326-
$this->assertInternalType('array', $decoded);
326+
$this->assertIsArray($decoded);
327327
$this->assertArrayHasKey('data', $decoded);
328328
$this->assertGreaterThanOrEqual(3, count($decoded['data']));
329329
}

tests/Feature/OperationsProposalControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function testApproveCreateProposalInsertsRow()
126126

127127
$flash = session('flash_notification', collect())->toArray();
128128
$this->assertNotEmpty($flash);
129-
$this->assertContains('已核准', $flash[0]['message'] ?? '');
129+
$this->assertStringContainsString('已核准', $flash[0]['message'] ?? '');
130130

131131
$operation->refresh();
132132
$payload = json_decode($operation->resource_data, true);

tests/Unit/MergePreviewControllerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ public function testCalculateMergedPersonCombinesAttributesAndNotes()
6565
$this->assertSame('Active', $values['c_status']);
6666
$this->assertSame('MergeAdmin', $values['c_modified_by']);
6767
$this->assertSame('20250102', $values['c_modified_date']);
68-
$this->assertContains('Primary note', $values['c_notes']);
69-
$this->assertContains('Secondary note', $values['c_notes']);
70-
$this->assertContains('[merged #123 and #456 on 20250102 with reason] duplicate record', $values['c_notes']);
68+
$this->assertStringContainsString('Primary note', $values['c_notes']);
69+
$this->assertStringContainsString('Secondary note', $values['c_notes']);
70+
$this->assertStringContainsString('[merged #123 and #456 on 20250102 with reason] duplicate record', $values['c_notes']);
7171

7272
$this->assertArrayHasKey('c_notes', $updates);
7373
$this->assertArrayHasKey('c_modified_by', $updates);

0 commit comments

Comments
 (0)