Skip to content

Commit cc6f61c

Browse files
committed
test(rector): Replace usage of Pest Faker functions
- Remove old references to Pest Faker in test files - Add new implementations of faker and fake functions in Pest.php - This change updates the testing framework to ensure consistency in random data generation - Simplifies the adjustability of locales for Faker functions
1 parent afdc33d commit cc6f61c

17 files changed

Lines changed: 74 additions & 85 deletions

File tree

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
fail-fast: true
1010
matrix:
1111
os: [ ubuntu-latest ]
12-
php: [ 8.0, 8.4 ]
12+
php: [ 8.0, 8.1, 8.2, 8.3, 8.4 ]
1313
dependency-version: [ prefer-stable ]
1414

1515
name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}

benchmarks/CreateInstanceBench.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818
use Guanguans\Notify\Bark\Authenticator;
1919
use Guanguans\Notify\Bark\Client;
2020
use Guanguans\Notify\Bark\Messages\Message;
21+
use PhpBench\Attributes\BeforeMethods;
22+
use PhpBench\Attributes\Revs;
2123

22-
/**
23-
* @beforeMethods({"setUp"})
24-
*
25-
* @revs(10000)
26-
*/
24+
#[BeforeMethods('setUp')]
25+
#[Revs(10000)]
2726
final class CreateInstanceBench
2827
{
2928
private \Guanguans\Notify\Foundation\Contracts\Authenticator $authenticator;

benchmarks/SendMessageBench.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919
use Guanguans\Notify\Bark\Client;
2020
use Guanguans\Notify\Bark\Messages\Message;
2121
use GuzzleHttp\Psr7\HttpFactory;
22+
use PhpBench\Attributes\BeforeMethods;
23+
use PhpBench\Attributes\Revs;
2224

23-
/**
24-
* @beforeMethods({"setUp"})
25-
*
26-
* @revs(10000)
27-
*/
25+
#[BeforeMethods('setUp')]
26+
#[Revs(10000)]
2827
final class SendMessageBench
2928
{
3029
private \Guanguans\Notify\Foundation\Message $message;

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"illuminate/collections": "^9.52 || ^10.0 || ^11.0",
9595
"illuminate/support": "^9.52 || ^10.0 || ^11.0",
9696
"infection/extension-installer": "^0.1",
97+
"kcs/class-finder": "^0.3",
9798
"maglnet/composer-require-checker": "^3.8 || ^4.0",
9899
"mockery/mockery": "^1.6",
99100
"pestphp/pest": "^1.23 || ^2.0 || ^3.0",
@@ -193,6 +194,7 @@
193194
"@style-lint",
194195
"@test",
195196
"@psalm",
197+
"@phpstan",
196198
"@rector-dry-run",
197199
"@rector-php82-dry-run",
198200
"@infection-dirty"

monorepo-builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
// UpdateChangelogViaPhpReleaseWorker::class,
4747
CreateGithubReleaseReleaseWorker::class,
4848
// SetNextMutualDependenciesReleaseWorker::class,
49-
// UpdateBranchAliasReleaseWorker::class,
49+
UpdateBranchAliasReleaseWorker::class,
5050
// PushNextDevReleaseWorker::class,
5151
]);
5252

rector.php

Lines changed: 50 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Guanguans\Notify\Foundation\Rectors\ToInternalExceptionRector;
2424
use Guanguans\Notify\Foundation\Response;
2525
use GuzzleHttp\RequestOptions;
26+
use Kcs\ClassFinder\Finder\ComposerFinder;
2627
use PhpParser\Node\Expr\ClassConstFetch;
2728
use PhpParser\Node\Identifier;
2829
use PhpParser\Node\Name\FullyQualified;
@@ -41,6 +42,8 @@
4142
use Rector\EarlyReturn\Rector\Return_\ReturnBinaryOrToEarlyReturnRector;
4243
use Rector\Naming\Rector\ClassMethod\RenameParamToMatchTypeRector;
4344
use Rector\Php73\Rector\String_\SensitiveHereNowDocRector;
45+
use Rector\Php80\Rector\Class_\AnnotationToAttributeRector;
46+
use Rector\Php80\ValueObject\AnnotationToAttribute;
4447
use Rector\Php82\Rector\Param\AddSensitiveParameterAttributeRector;
4548
use Rector\PHPUnit\Set\PHPUnitSetList;
4649
use Rector\Removing\Rector\Class_\RemoveTraitUseRector;
@@ -60,6 +63,7 @@
6063
return RectorConfig::configure()
6164
->withRootFiles()
6265
->withPaths([
66+
__DIR__.'/benchmarks',
6367
__DIR__.'/src',
6468
__DIR__.'/tests',
6569
__DIR__.'/composer-updater',
@@ -120,6 +124,14 @@
120124
new ClassMethodReference(HasOptions::class, 'offsetGet'),
121125
new ClassMethodReference(Response::class, 'offsetGet'),
122126
])
127+
->withConfiguredRule(AnnotationToAttributeRector::class, array_map(
128+
static fn (string $class) => new AnnotationToAttribute(class_basename($class), $class, [], true),
129+
array_keys(iterator_to_array(
130+
(new ComposerFinder)
131+
->inNamespace('PhpBench\Attributes')
132+
->filter(static fn (ReflectionClass $reflectionClass): bool => $reflectionClass->isInstantiable())
133+
))
134+
))
123135
->withConfiguredRule(AddSensitiveParameterAttributeRector::class, [
124136
AddSensitiveParameterAttributeRector::SENSITIVE_PARAMETERS => [
125137
'accessToken',
@@ -134,48 +146,45 @@
134146
'webHook',
135147
],
136148
])
137-
->withConfiguredRule(
138-
StringToClassConstantRector::class,
139-
array_reduce(
140-
[
141-
Guanguans\Notify\Foundation\Method::class,
142-
RequestOptions::class,
143-
],
144-
static fn (array $carry, string $class): array => array_merge(
145-
$carry,
146-
array_map(
147-
static fn (string $string, string $constant): StringToClassConstant => new StringToClassConstant(
148-
$string,
149-
$class,
150-
$constant,
151-
),
152-
$constants = (new ReflectionClass($class))->getConstants(),
153-
array_keys($constants),
149+
->withConfiguredRule(RenameFunctionRector::class, [
150+
'test' => 'it',
151+
'Pest\Faker\faker' => 'faker',
152+
'Pest\Faker\fake' => 'fake',
153+
// 'faker' => 'fake',
154+
] + array_reduce(
155+
[
156+
'error_silencer',
157+
'value',
158+
'base64_encode_file',
159+
'tap',
160+
],
161+
static function (array $carry, string $func): array {
162+
/** @see https://github.com/laravel/framework/blob/11.x/src/Illuminate/Support/functions.php */
163+
$carry[$func] = "Guanguans\\Notify\\Foundation\\Support\\$func";
164+
165+
return $carry;
166+
},
167+
[]
168+
))
169+
->withConfiguredRule(StringToClassConstantRector::class, array_reduce(
170+
[
171+
Guanguans\Notify\Foundation\Method::class,
172+
RequestOptions::class,
173+
],
174+
static fn (array $carry, string $class): array => array_merge(
175+
$carry,
176+
array_map(
177+
static fn (string $string, string $constant): StringToClassConstant => new StringToClassConstant(
178+
$string,
179+
$class,
180+
$constant,
154181
),
182+
$constants = (new ReflectionClass($class))->getConstants(),
183+
array_keys($constants),
155184
),
156-
[],
157185
),
158-
)
159-
->withConfiguredRule(
160-
RenameFunctionRector::class,
161-
[
162-
'test' => 'it',
163-
] + array_reduce(
164-
[
165-
'error_silencer',
166-
'value',
167-
'base64_encode_file',
168-
'tap',
169-
],
170-
static function (array $carry, string $func): array {
171-
/** @see https://github.com/laravel/framework/blob/11.x/src/Illuminate/Support/functions.php */
172-
$carry[$func] = "Guanguans\\Notify\\Foundation\\Support\\$func";
173-
174-
return $carry;
175-
},
176-
[]
177-
)
178-
)
186+
[],
187+
))
179188
->withConfiguredRule(ScalarValueToConstFetchRector::class, array_map(
180189
static fn (int $value, string $constant): ScalarValueToConstFetch => new ScalarValueToConstFetch(
181190
new LNumber($value),
@@ -214,13 +223,15 @@ static function (array $carry, string $func): array {
214223
],
215224
StaticClosureRector::class => $staticArrowFunctionPaths,
216225
StringToClassConstantRector::class => [
226+
__DIR__.'/benchmarks',
217227
__DIR__.'/src/Foundation/Rfc',
218228
__DIR__.'/src/*/Messages/*.php',
219229
__DIR__.'/tests',
220230
__DIR__.'/src/Foundation/Support/Utils.php',
221231
__DIR__.'/src/Foundation/Response.php',
222232
],
223233
SortAssociativeArrayByKeyRector::class => [
234+
__DIR__.'/benchmarks',
224235
__DIR__.'/src',
225236
__DIR__.'/tests',
226237
],

tests/Foundation/Authenticators/AuthenticatorTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use Guanguans\Notify\Foundation\Authenticators\WsseAuthenticator;
2121
use GuzzleHttp\Psr7\Request;
2222
use Psr\Http\Message\RequestInterface;
23-
use function Pest\Faker\faker;
2423

2524
it('can apply the certificate to options', function (): void {
2625
expect(new CertificateAuthenticator(fixtures_path('cert.pem'), faker()->password))

tests/Foundation/ResponseTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
use Illuminate\Support\Collection;
2828
use Illuminate\Support\Fluent;
2929
use Psr\Http\Message\RequestInterface;
30-
use function Pest\Faker\faker;
3130

3231
it('can dump debug info', function (): void {
3332
expect(Response::fromPsrResponse(new \GuzzleHttp\Psr7\Response))

tests/Gitter/ClientTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Guanguans\Notify\Gitter\Authenticator;
2020
use Guanguans\Notify\Gitter\Client;
2121
use Guanguans\Notify\Gitter\Messages\Message;
22-
use function Pest\Faker\faker;
2322

2423
it('can send message', function (): void {
2524
$authenticator = new Authenticator(

tests/GoogleChat/ClientTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Guanguans\Notify\GoogleChat\Authenticator;
2020
use Guanguans\Notify\GoogleChat\Client;
2121
use Guanguans\Notify\GoogleChat\Messages\Message;
22-
use function Pest\Faker\faker;
2322

2423
it('can send message', function (): void {
2524
$authenticator = new Authenticator('spaceId', 'key', 'token', 'threadKey');

0 commit comments

Comments
 (0)