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 Sep 9, 2023
1 parent 648f980 commit 007de95
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 10 deletions.
10 changes: 10 additions & 0 deletions src/Commands/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,14 @@ protected function resolveCommand($command)
: $command
);
}

/**
* Get the Laravel application instance.
*
* @return \Illuminate\Contracts\Foundation\Application
*/
public function getLaravel()
{
return $this->laravel;
}
}
7 changes: 4 additions & 3 deletions src/Commands/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public function generatingCode(string $stub, string $className): string
*/
public function codeAlreadyExists(string $className): int
{
$this->error($this->type.' already exists!');
$this->components->error(sprintf('%s [%s] already exists!', $this->type, $className));

return 1;
}
Expand All @@ -209,7 +209,7 @@ public function codeAlreadyExists(string $className): int
*/
public function codeHasBeenGenerated(string $className): int
{
$this->info($this->type.' created successfully.');
$this->components->info(sprintf('%s [%s] created successfully.', $this->type, $className));

return 0;
}
Expand Down Expand Up @@ -240,7 +240,8 @@ public function getPublishedStubFileName(): ?string
*/
public function generatorName(): string
{
return transform($this->argument('name'), function (string $name) {
return transform($this->argument('name'), function ($name) {
/** @var string $name */
return trim($name);
});
}
Expand Down
6 changes: 2 additions & 4 deletions src/LaravelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ class LaravelServiceProvider extends ServiceProvider implements DeferrableProvid
*/
public function register()
{
$this->app->singleton(Presets\Preset::class, function (Container $app) {
return $this->presetForLaravel($app);
});
$this->app->singleton(Presets\Preset::class, fn (Container $app) => $this->presetForLaravel($app));
}

/**
* Get the services provided by the provider.
*
* @return array
* @return array<int, class-string|string>
*/
public function provides()
{
Expand Down
8 changes: 8 additions & 0 deletions src/Presets/Laravel.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ public function name(): string
return 'laravel';
}

/**
* Get the path to the base working directory.
*/
public function laravelPath(): string
{
return $this->basePath();
}

/**
* Get the path to the source directory.
*/
Expand Down
10 changes: 9 additions & 1 deletion src/Presets/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ public function name(): string
return 'package';
}

/**
* Get the path to the base working directory.
*/
public function laravelPath(): string
{
return sprintf('%s/orchestra/testbench-core/laravel', $this->vendorPath());
}

/**
* Get the path to the source directory.
*/
Expand Down Expand Up @@ -80,7 +88,7 @@ public function providerNamespace(): string
*/
public function getCustomStubPath(): ?string
{
return null;
return sprintf('%s/stubs', $this->basePath());
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/Presets/Preset.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function __construct(
protected string $basePath,
protected Filesystem $files
) {
//
}

/**
Expand Down Expand Up @@ -156,6 +157,11 @@ public function hasCustomStubPath(): bool
*/
abstract public function name(): string;

/**
* Get the path to the base working directory.
*/
abstract public function laravelPath(): string;

/**
* Get the path to the source directory.
*/
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Presets/PackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public function it_has_proper_signatures()
$this->assertSame("{$directory}/database/migrations", $preset->migrationPath());
$this->assertSame("{$directory}/database/seeders", $preset->seederPath());

$this->assertFalse($preset->hasCustomStubPath());
$this->assertNull($preset->getCustomStubPath());
$this->assertTrue($preset->hasCustomStubPath());
$this->assertSame("{$directory}/stubs", $preset->getCustomStubPath());

$this->assertSame($files, $preset->filesystem());
}
Expand Down

0 comments on commit 007de95

Please sign in to comment.