Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Jan 10, 2024
1 parent c6d0d85 commit 32d1408
Show file tree
Hide file tree
Showing 25 changed files with 85 additions and 145 deletions.
4 changes: 1 addition & 3 deletions src/Attributes/WithMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ public function __construct()
public function __invoke($app): void
{
$types = Collection::make($this->types)
->transform(static function ($type) {
return laravel_migration_path($type !== 'laravel' ? $type : null);
});
->transform(static fn ($type) => laravel_migration_path($type !== 'laravel' ? $type : null));

after_resolving($app, 'migrator', static function ($migrator) use ($types) {
/** @var \Illuminate\Database\Migrations\Migrator $migrator */
Expand Down
2 changes: 1 addition & 1 deletion src/Bootstrap/LoadConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private function loadConfigurationFiles(Application $app, RepositoryContract $co
LazyCollection::make(static function () use ($app) {
$path = is_dir($app->basePath('config'))
? $app->basePath('config')
: realpath(join_paths(__DIR__, '..', '..', 'laravel', 'config'));
: join_paths((string) realpath(__DIR__), '..', '..', 'laravel', 'config');

if (\is_string($path)) {
foreach (Finder::create()->files()->name('*.php')->in($path) as $file) {
Expand Down
5 changes: 2 additions & 3 deletions src/Bootstrap/LoadConfigurationWithWorkbench.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ protected function extendsLoadedConfiguration(Collection $configurations): Colle
foreach (Finder::create()->files()->name('*.php')->in(workbench_path('config')) as $file) {
yield basename($file->getRealPath(), '.php') => $file->getRealPath();
}
})->reject(static function ($path, $key) use ($configurations) {
return $configurations->has($key);
})->each(static function ($path, $key) use ($configurations) {
})->reject(static fn ($path, $key) => $configurations->has($key))
->each(static function ($path, $key) use ($configurations) {
$configurations->put($key, $path);
});

Expand Down
2 changes: 1 addition & 1 deletion src/Bootstrap/LoadEnvironmentVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected function createDotenv($app)
{
if (! file_exists(join_paths($app->environmentPath(), $app->environmentFile()))) {
return Dotenv::create(
Env::getRepository(), (string) realpath(join_paths(__DIR__, 'stubs')), '.env.testbench'
Env::getRepository(), join_paths((string) realpath(__DIR__), 'stubs'), '.env.testbench'
);
}

Expand Down
26 changes: 9 additions & 17 deletions src/Concerns/CreatesApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ trait CreatesApplication
*/
public static function applicationBasePath()
{
return static::applicationBasePathUsingWorkbench() ?? (string) realpath(join_paths(__DIR__, '..', '..', 'laravel'));
return static::applicationBasePathUsingWorkbench() ?? join_paths((string) realpath(__DIR__), '..', '..', 'laravel');
}

/**
Expand Down Expand Up @@ -122,9 +122,7 @@ final protected function resolveApplicationAliases($app): array
$overrides = $this->overrideApplicationAliases($app);

if (! empty($overrides)) {
$aliases->transform(static function ($alias, $name) use ($overrides) {
return $overrides[$name] ?? $alias;
});
$aliases->transform(static fn ($alias, $name) => $overrides[$name] ?? $alias);
}

return $aliases->merge($this->getPackageAliases($app))->all();
Expand Down Expand Up @@ -188,9 +186,7 @@ final protected function resolveApplicationProviders($app): array
$overrides = $this->overrideApplicationProviders($app);

if (! empty($overrides)) {
$providers->transform(static function ($provider) use ($overrides) {
return $overrides[$provider] ?? $provider;
});
$providers->transform(static fn ($provider) => $overrides[$provider] ?? $provider);
}

return $providers->merge($this->getPackageProviders($app))->all();
Expand Down Expand Up @@ -316,9 +312,7 @@ protected function resolveApplicationConfiguration($app)

tap($app['config'], function ($config) use ($app) {
if (! $app->bound('env')) {
$app->detectEnvironment(static function () use ($config) {
return $config->get('app.env', 'workbench');
});
$app->detectEnvironment(static fn () => $config->get('app.env', 'workbench'));
}

$config->set([
Expand All @@ -345,9 +339,7 @@ protected function resolveApplicationCore($app)
Facade::setFacadeApplication($app);

if ($this->isRunningTestCase()) {
$app->detectEnvironment(static function () {
return 'testing';
});
$app->detectEnvironment(static fn () => 'testing');
}
}

Expand Down Expand Up @@ -459,7 +451,7 @@ final protected function refreshApplicationRouteNameLookups($app)

$refreshNameLookups($app);

$app->resolving('url', fn () => $refreshNameLookups($app));
$app->resolving('url', static fn () => $refreshNameLookups($app));
}

/**
Expand All @@ -470,9 +462,9 @@ final protected function refreshApplicationRouteNameLookups($app)
*/
protected function resolveApplicationRateLimiting($app)
{
RateLimiter::for('api', static function (Request $request) {
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
});
RateLimiter::for(
'api', static fn (Request $request) => Limit::perMinute(60)->by($request->user()?->id ?: $request->ip())
);
}

/**
Expand Down
5 changes: 2 additions & 3 deletions src/Concerns/HandlesAnnotations.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ protected function parseTestMethodAnnotations($app, string $name, ?Closure $call
{
$this->resolvePhpUnitAnnotations()
->lazy()
->filter(static function ($actions, string $key) use ($name) {
return $key === $name && ! empty($actions);
})->flatten()
->filter(static fn ($actions, string $key) => $key === $name && ! empty($actions))
->flatten()
->filter(fn ($method) => \is_string($method) && method_exists($this, $method))
->each($callback ?? function ($method) use ($app) {
$this->{$method}($app);
Expand Down
5 changes: 2 additions & 3 deletions src/Concerns/HandlesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ protected function parseTestMethodAttributes($app, string $attribute): Collectio
{
/** @var \Illuminate\Support\Collection<int, mixed> $attributes */
$attributes = $this->resolvePhpUnitAttributes()
->filter(static function ($attributes, string $key) use ($attribute) {
return $key === $attribute && ! empty($attributes);
})->flatten()
->filter(static fn ($attributes, string $key) => $key === $attribute && ! empty($attributes))
->flatten()
->map(function ($instance) use ($app) {
if ($instance instanceof InvokableContract) {
return $instance($app);
Expand Down
12 changes: 6 additions & 6 deletions src/Concerns/InteractsWithPHPUnit.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ protected function resolvePhpUnitAttributes(): Collection
protected static function resolvePhpUnitAttributesForMethod(string $className, ?string $methodName = null): Collection
{
if (! isset(static::$cachedTestCaseClassAttributes[$className])) {
static::$cachedTestCaseClassAttributes[$className] = rescue(static function () use ($className) {
return AttributeParser::forClass($className);
}, [], false);
static::$cachedTestCaseClassAttributes[$className] = rescue(
static fn () => AttributeParser::forClass($className), [], false
);
}

if (! \is_null($methodName) && ! isset(static::$cachedTestCaseMethodAttributes["{$className}:{$methodName}"])) {
static::$cachedTestCaseMethodAttributes["{$className}:{$methodName}"] = rescue(static function () use ($className, $methodName) {
return AttributeParser::forMethod($className, $methodName);
}, [], false);
static::$cachedTestCaseMethodAttributes["{$className}:{$methodName}"] = rescue(
static fn () => AttributeParser::forMethod($className, $methodName), [], false
);
}

/** @var \Illuminate\Support\Collection<class-string<TTestingFeature>, array<int, TTestingFeature>> $attributes */
Expand Down
10 changes: 4 additions & 6 deletions src/Concerns/InteractsWithPublishedFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,8 @@ protected function cleanUpPublishedFiles(): void
->map(fn ($file) => str_contains($file, '*') ? [...$this->app['files']->glob($file)] : $file)
->flatten()
->filter(fn ($file) => $this->app['files']->exists($file))
->reject(static function ($file) {
return str_ends_with($file, '.gitkeep') || str_ends_with($file, '.gitignore');
})->all()
->reject(static fn ($file) => str_ends_with($file, '.gitkeep') || str_ends_with($file, '.gitignore'))
->all()
);
}

Expand All @@ -224,9 +223,8 @@ protected function cleanUpPublishedMigrationFiles(): void
{
$this->app['files']->delete(
Collection::make($this->app['files']->files($this->app->databasePath('migrations')))
->filter(static function ($file) {
return str_ends_with($file, '.php');
})->all()
->filter(static fn ($file) => str_ends_with($file, '.php'))
->all()
);
}
}
20 changes: 8 additions & 12 deletions src/Concerns/InteractsWithTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,8 @@ protected function setUpTheTestEnvironmentUsingTestCase(): void

$this->resolvePhpUnitAttributes()
->flatten()
->filter(static function ($instance) {
return $instance instanceof BeforeEachContract;
})->map(function ($instance) use ($app) {
->filter(static fn ($instance) => $instance instanceof BeforeEachContract)
->map(static function ($instance) use ($app) {
$instance->beforeEach($app);
});
}
Expand All @@ -138,9 +137,8 @@ protected function tearDownTheTestEnvironmentUsingTestCase(): void

$this->resolvePhpUnitAttributes()
->flatten()
->filter(static function ($instance) {
return $instance instanceof AfterEachContract;
})->map(static function ($instance) use ($app) {
->filter(static fn ($instance) => $instance instanceof AfterEachContract)
->map(static function ($instance) use ($app) {
$instance->afterEach($app);
});
}
Expand All @@ -156,9 +154,8 @@ public static function setUpBeforeClassUsingTestCase(): void
{
static::resolvePhpUnitAttributesForMethod(static::class)
->flatten()
->filter(static function ($instance) {
return $instance instanceof BeforeAllContract;
})->map(static function ($instance) {
->filter(static fn ($instance) => $instance instanceof BeforeAllContract)
->map(static function ($instance) {
$instance->beforeAll();
});
}
Expand All @@ -174,9 +171,8 @@ public static function tearDownAfterClassUsingTestCase(): void
{
static::resolvePhpUnitAttributesForMethod(static::class)
->flatten()
->filter(static function ($instance) {
return $instance instanceof AfterAllContract;
})->map(static function ($instance) {
->filter(static fn ($instance) => $instance instanceof AfterAllContract)
->map(static function ($instance) {
$instance->afterAll();
});

Expand Down
4 changes: 1 addition & 3 deletions src/Console/Commander.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,7 @@ protected function handleException(OutputInterface $output, Throwable $error)
*/
protected function prepareCommandSignals(): void
{
Signals::resolveAvailabilityUsing(static function () {
return \extension_loaded('pcntl');
});
Signals::resolveAvailabilityUsing(static fn () => \extension_loaded('pcntl'));

Signals::whenAvailable(function () {
$this->signals ??= new Signals(new SignalRegistry());
Expand Down
5 changes: 2 additions & 3 deletions src/Foundation/Bootstrap/EnsuresDefaultConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ public function bootstrap(Application $app): void
'APP_DEBUG' => ['app.debug' => true],
'DB_CONNECTION' => \defined('TESTBENCH_DUSK') ? ['database.default' => 'testing'] : null,
])->filter()
->reject(static function ($config, $key) {
return ! \is_null(Env::get($key));
})->values()
->reject(static fn ($config, $key) => ! \is_null(Env::get($key)))
->values()
->all(),
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Orchestra\Testbench\Foundation\Bootstrap;

use Dotenv\Parser\Entry;
use Dotenv\Parser\Parser;
use Dotenv\Store\StringStore;
use Illuminate\Contracts\Foundation\Application;
Expand Down Expand Up @@ -42,10 +43,8 @@ public function bootstrap(Application $app): void
$parser = new Parser();

Collection::make($parser->parse($store->read()))
->filter(static function ($entry) {
/** @var \Dotenv\Parser\Entry $entry */
return $entry->getValue()->isDefined();
})->each(static function ($entry) {
->filter(static fn (Entry $entry) => $entry->getValue()->isDefined())
->each(static function (Entry $entry) {
/** @var \Dotenv\Parser\Entry $entry */
Env::set($entry->getName(), $entry->getValue()->get()->getChars());
});
Expand Down
11 changes: 4 additions & 7 deletions src/Foundation/Bootstrap/LoadMigrationsFromArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,10 @@ protected function bootstrapMigrations(Application $app): void
{
$paths = Collection::make(
! \is_bool($this->migrations) ? Arr::wrap($this->migrations) : []
)->when($this->includesDefaultMigrations($app), static function ($migrations) {
return $migrations->push(laravel_migration_path());
})->filter(static function ($migration) {
return \is_string($migration);
})->transform(static function ($migration) use ($app) {
return transform_relative_path($migration, $app->basePath());
})->all();
)->when($this->includesDefaultMigrations($app), static fn ($migrations) => $migrations->push(laravel_migration_path()))
->filter(static fn ($migration) => \is_string($migration))
->transform(static fn ($migration) => transform_relative_path($migration, $app->basePath()))
->all();

after_resolving($app, 'migrator', static function ($migrator) use ($paths) {
foreach ((array) $paths as $path) {
Expand Down
11 changes: 3 additions & 8 deletions src/Foundation/Concerns/HandlesDatabaseConnections.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,14 @@ final protected function usesDatabaseConnectionsEnvironmentVariables(Repository

$config->set(
Collection::make($options)
->when($driver === 'pgsql', static function ($options) {
return $options->put('schema', 'SCHEMA');
})
->when($driver === 'pgsql', static fn ($options) => $options->put('schema', 'SCHEMA'))
->mapWithKeys(static function ($value, $key) use ($driver, $keyword, $config) {
$name = "database.connections.{$driver}.{$key}";

/** @var mixed $configuration */
$configuration = Collection::make(Arr::wrap($value))
->transform(static function ($value) use ($keyword) {
return Env::get("{$keyword}_{$value}");
})->first(static function ($value) {
return ! \is_null($value);
}) ?? $config->get($name);
->transform(static fn ($value) => Env::get("{$keyword}_{$value}"))
->first(static fn ($value) => ! \is_null($value)) ?? $config->get($name);

return [
"{$name}" => $configuration,
Expand Down
11 changes: 5 additions & 6 deletions src/Foundation/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,8 @@ public static function loadFromYaml(string $workingPath, ?string $filename = 'te
yield $filename;
yield "{$filename}.example";
yield "{$filename}.dist";
})->filter(static function ($file) use ($workingPath) {
return file_exists(join_paths($workingPath, $file));
})->first();
})->filter(static fn ($file) => file_exists(join_paths($workingPath, $file)))
->first();

if (! \is_null($filename)) {
/**
Expand All @@ -207,9 +206,9 @@ public static function loadFromYaml(string $workingPath, ?string $filename = 'te
*/
$config = Yaml::parseFile(join_paths($workingPath, $filename));

$config['laravel'] = transform(Arr::get($config, 'laravel'), static function ($path) use ($workingPath) {
return transform_relative_path($path, $workingPath);
});
$config['laravel'] = transform(
Arr::get($config, 'laravel'), static fn ($path) => transform_relative_path($path, $workingPath)
);

if (isset($config['env']) && \is_array($config['env']) && Arr::isAssoc($config['env'])) {
$config['env'] = parse_environment_variables($config['env']);
Expand Down
5 changes: 2 additions & 3 deletions src/Foundation/Console/Actions/DeleteFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ public function __construct(
public function handle(iterable $files): void
{
LazyCollection::make($files)
->reject(static function ($file) {
return str_ends_with($file, '.gitkeep') || str_ends_with($file, '.gitignore');
})->each(function ($file) {
->reject(static fn ($file) => str_ends_with($file, '.gitkeep') || str_ends_with($file, '.gitignore'))
->each(function ($file) {
if ($this->filesystem->exists($file)) {
$this->filesystem->delete($file);

Expand Down
20 changes: 6 additions & 14 deletions src/Foundation/Console/PurgeSkeletonCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,9 @@ public function handle(Filesystem $filesystem, ConfigContract $config)
))->handle(
LazyCollection::make($files)
->map(fn ($file) => $this->laravel->basePath($file))
->map(static function ($file) use ($filesystem) {
return str_contains($file, '*')
? [...$filesystem->glob($file)]
: $file;
})->flatten()
->reject(fn ($file) => str_contains($file, '*'))
->map(static fn ($file) => str_contains($file, '*') ? [...$filesystem->glob($file)] : $file)
->flatten()
->reject(static fn ($file) => str_contains($file, '*'))
);

(new Actions\DeleteDirectories(
Expand All @@ -83,14 +80,9 @@ public function handle(Filesystem $filesystem, ConfigContract $config)
))->handle(
Collection::make($directories)
->map(fn ($directory) => $this->laravel->basePath($directory))
->map(static function ($directory) use ($filesystem) {
return str_contains($directory, '*')
? [...$filesystem->glob($directory)]
: $directory;
})->flatten()
->reject(static function ($directory) {
return str_contains($directory, '*');
})
->map(static fn ($directory) => str_contains($directory, '*') ? [...$filesystem->glob($directory)] : $directory)
->flatten()
->reject(static fn ($directory) => str_contains($directory, '*'))
);

return Command::SUCCESS;
Expand Down
Loading

0 comments on commit 32d1408

Please sign in to comment.