Skip to content

Commit

Permalink
Merge branch '8.x' into 9.x
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 4, 2024
2 parents 7a9644e + 3af8fb6 commit 4c7d43e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 13 deletions.
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Call to an undefined method Illuminate\\\\Contracts\\\\Foundation\\\\Application\\:\\:joinPaths\\(\\)\\.$#"
count: 1
path: src/Commands/MigrationGeneratorCommand.php

-
message: "#^Cannot access offset 'migration\\.creator' on Illuminate\\\\Contracts\\\\Foundation\\\\Application\\.$#"
count: 1
Expand Down
4 changes: 3 additions & 1 deletion src/Concerns/MigrationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Orchestra\Canvas\Core\Concerns;

use function Illuminate\Filesystem\join_paths;

trait MigrationGenerator
{
use CreatesUsingGeneratorPreset;
Expand All @@ -22,7 +24,7 @@ protected function createBaseMigrationUsingCanvas(string $table): string
protected function migrationExistsUsingCanvas(string $table): bool
{
return \count($this->files->glob(
$this->laravel->joinPaths($this->generatorPreset()->migrationPath(), '*_*_*_*_create_'.$table.'_table.php')
join_paths($this->generatorPreset()->migrationPath(), '*_*_*_*_create_'.$table.'_table.php')
)) !== 0;
}
}
4 changes: 3 additions & 1 deletion src/Concerns/ResolvesPresetStubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Orchestra\Canvas\Core\Concerns;

use function Illuminate\Filesystem\join_paths;

trait ResolvesPresetStubs
{
/**
Expand All @@ -14,7 +16,7 @@ protected function resolveStubPath($stub)
{
$preset = $this->generatorPreset();

return $preset->hasCustomStubPath() && file_exists($customPath = implode('/', [$preset->basePath(), trim($stub, '/')]))
return $preset->hasCustomStubPath() && file_exists($customPath = join_paths($preset->basePath(), trim($stub, '/')))
? $customPath
: $this->resolveDefaultStubPath($stub);
}
Expand Down
10 changes: 6 additions & 4 deletions src/Concerns/UsesGeneratorOverrides.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Orchestra\Canvas\Core\Presets\Preset;
use Symfony\Component\Finder\Finder;

use function Illuminate\Filesystem\join_paths;

trait UsesGeneratorOverrides
{
/**
Expand All @@ -31,7 +33,7 @@ protected function getPathUsingCanvas(string $name): string
{
$name = Str::replaceFirst($this->rootNamespace(), '', $name);

return $this->getGeneratorSourcePath().'/'.str_replace('\\', '/', $name).'.php';
return join_paths($this->getGeneratorSourcePath(), str_replace('\\', '/', $name).'.php');
}

/**
Expand All @@ -57,7 +59,7 @@ protected function viewPathUsingCanvas(string $path = ''): string
{
$views = $this->generatorPreset()->viewPath();

return $views.($path ? DIRECTORY_SEPARATOR.$path : $path);
return join_paths($views, $path);
}

/**
Expand All @@ -69,7 +71,7 @@ protected function possibleModelsUsingCanvas(): array
{
$sourcePath = $this->generatorPreset()->sourcePath();

$modelPath = is_dir("{$sourcePath}/Models") ? "{$sourcePath}/Models" : $sourcePath;
$modelPath = is_dir(join_paths($sourcePath, 'Models')) ? join_paths($sourcePath, 'Models') : $sourcePath;

return collect((new Finder)->files()->depth(0)->in($modelPath))
->map(fn ($file) => $file->getBasename('.php'))
Expand All @@ -85,7 +87,7 @@ protected function possibleModelsUsingCanvas(): array
*/
protected function possibleEventsUsingCanvas(): array
{
$eventPath = sprintf('%s/Events', $this->generatorPreset()->sourcePath());
$eventPath = join_paths($this->generatorPreset()->sourcePath(), 'Events');

if (! is_dir($eventPath)) {
return [];
Expand Down
4 changes: 3 additions & 1 deletion src/Presets/Laravel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Orchestra\Canvas\Core\Presets;

use function Illuminate\Filesystem\join_paths;

class Laravel extends Preset
{
/**
Expand Down Expand Up @@ -123,7 +125,7 @@ public function commandNamespace()
*/
public function modelNamespace()
{
return is_dir("{$this->sourcePath()}/Models") ? "{$this->rootNamespace()}Models\\" : $this->rootNamespace();
return is_dir(join_paths($this->sourcePath(), 'Models')) ? "{$this->rootNamespace()}Models\\" : $this->rootNamespace();
}

/**
Expand Down
17 changes: 16 additions & 1 deletion tests/Commands/GeneratorCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
use Orchestra\Testbench\Concerns\InteractsWithPublishedFiles;
use Orchestra\Testbench\Concerns\WithWorkbench;
use Orchestra\Testbench\TestCase;
use PHPUnit\Framework\Attributes\RequiresOperatingSystem;
use PHPUnit\Framework\Attributes\Test;

use function Illuminate\Filesystem\join_paths;

class GeneratorCommandTest extends TestCase
{
use InteractsWithPublishedFiles;
Expand Down Expand Up @@ -88,12 +91,24 @@ public function it_cannot_generate_class_file_given_reserved_name()
}

#[Test]
#[RequiresOperatingSystem('Linux|DAR')]
public function it_cannot_generate_class_file_when_file_already_exist()
{
file_put_contents(base_path('app/Value/Foo.php'), '<?php '.PHP_EOL);
file_put_contents(base_path(join_paths('app', 'Value', 'Foo.php')), '<?php '.PHP_EOL);

$this->artisan('make:code', ['name' => 'Value/Foo'])
->expectsOutputToContain('class [app/Value/Foo.php] already exists!')
->assertFailed();
}

#[Test]
#[RequiresOperatingSystem('Windows')]
public function it_cannot_generate_class_file_when_file_already_exist_on_windows()
{
file_put_contents(base_path(join_paths('app', 'Value', 'Foo.php')), '<?php '.PHP_EOL);

$this->artisan('make:code', ['name' => 'Value/Foo'])
->expectsOutputToContain('class [app\Value\Foo.php] already exists!')
->assertFailed();
}
}

0 comments on commit 4c7d43e

Please sign in to comment.