-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
213 changed files
with
5,242 additions
and
6,355 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Orchestra\Canvas\Tests\Feature\Console; | ||
|
||
use Orchestra\Canvas\Tests\Feature\TestCase; | ||
|
||
class ResourceMakeCommandTest extends TestCase | ||
{ | ||
protected $files = [ | ||
'app/Http/Resources/FooResource.php', | ||
'app/Http/Resources/FooResourceCollection.php', | ||
]; | ||
|
||
/** @test */ | ||
public function it_can_generate_resource_file() | ||
{ | ||
$this->artisan('make:resource', ['name' => 'FooResource', '--preset' => 'canvas']) | ||
->assertSuccessful(); | ||
|
||
$this->assertFileContains([ | ||
'namespace App\Http\Resources;', | ||
'use Illuminate\Http\Resources\Json\JsonResource;', | ||
'class FooResource extends JsonResource', | ||
], 'app/Http/Resources/FooResource.php'); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_generate_resource_collection_file() | ||
{ | ||
$this->artisan('make:resource', ['name' => 'FooResourceCollection', '--collection' => true, '--preset' => 'canvas']) | ||
->assertSuccessful(); | ||
|
||
$this->assertFileContains([ | ||
'namespace App\Http\Resources;', | ||
'use Illuminate\Http\Resources\Json\ResourceCollection;', | ||
'class FooResourceCollection extends ResourceCollection', | ||
], 'app/Http/Resources/FooResourceCollection.php'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,19 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
$workingPath = getcwd(); | ||
define('CANVAS_WORKING_PATH', $workingPath = getcwd()); | ||
define('TESTBENCH_WORKING_PATH', $workingPath); | ||
|
||
define('CANVAS_WORKING_PATH', $workingPath); | ||
require $_composer_autoload_path ?? __DIR__.'/vendor/autoload.php'; | ||
|
||
if (file_exists(__DIR__.'/vendor/autoload.php')) { | ||
// Development environment. | ||
require __DIR__.'/vendor/autoload.php'; | ||
} else { | ||
// Installation environment. | ||
require __DIR__.'/../../autoload.php'; | ||
} | ||
|
||
$config = ['preset' => Orchestra\Canvas\Canvas::presetFromEnvironment($workingPath)]; | ||
|
||
if (file_exists($workingPath.DIRECTORY_SEPARATOR.'canvas.yaml')) { | ||
$config = Symfony\Component\Yaml\Yaml::parseFile($workingPath.DIRECTORY_SEPARATOR.'canvas.yaml'); | ||
} | ||
|
||
$files = new Illuminate\Filesystem\Filesystem(); | ||
|
||
$preset = Orchestra\Canvas\Canvas::preset( | ||
$config, $workingPath, $files | ||
$config = Orchestra\Testbench\Foundation\Config::loadFromYaml( | ||
workingPath: $workingPath, | ||
defaults: [ | ||
'providers' => [], | ||
'dont-discover' => [], | ||
], | ||
); | ||
|
||
$app = new Symfony\Component\Console\Application('Canvas for Laravel'); | ||
|
||
if (class_exists(Composer\InstalledVersions::class)) { | ||
$app->setVersion(Composer\InstalledVersions::getPrettyVersion('orchestra/canvas')); | ||
} | ||
|
||
Illuminate\Support\Collection::make([ | ||
Orchestra\Canvas\Commands\Channel::class => true, | ||
Orchestra\Canvas\Commands\Component::class => true, | ||
Orchestra\Canvas\Commands\Console::class => true, | ||
Orchestra\Canvas\Commands\ConsoleGenerator::class => true, | ||
Orchestra\Canvas\Commands\Database\Cast::class => true, | ||
Orchestra\Canvas\Commands\Database\Eloquent::class => true, | ||
Orchestra\Canvas\Commands\Database\Factory::class => true, | ||
Orchestra\Canvas\Commands\Database\Migration::class => true, | ||
Orchestra\Canvas\Commands\Database\Observer::class => true, | ||
Orchestra\Canvas\Commands\Database\Seeder::class => $preset->is('laravel'), | ||
Orchestra\Canvas\Commands\Event::class => true, | ||
Orchestra\Canvas\Commands\Exception::class => true, | ||
Orchestra\Canvas\Commands\Job::class => true, | ||
Orchestra\Canvas\Commands\Listener::class => true, | ||
Orchestra\Canvas\Commands\Mail::class => true, | ||
Orchestra\Canvas\Commands\Notification::class => true, | ||
Orchestra\Canvas\Commands\Policy::class => true, | ||
Orchestra\Canvas\Commands\Preset::class => ! file_exists("{$workingPath}/canvas.yaml"), | ||
Orchestra\Canvas\Commands\Provider::class => true, | ||
Orchestra\Canvas\Commands\Request::class => true, | ||
Orchestra\Canvas\Commands\Resource::class => true, | ||
Orchestra\Canvas\Commands\Routing\Controller::class => true, | ||
Orchestra\Canvas\Commands\Routing\Middleware::class => true, | ||
Orchestra\Canvas\Commands\Rule::class => true, | ||
Orchestra\Canvas\Commands\Testing::class => true, | ||
Orchestra\Canvas\Commands\StubPublish::class => true, | ||
])->filter(fn ($value) => $value === true) | ||
->keys() | ||
->each(fn ($command) => $app->add(new $command($preset))); | ||
|
||
$preset->addAdditionalCommands($app); | ||
$commander = new Orchestra\Canvas\Console\Commander($config->getAttributes(), $workingPath); | ||
|
||
$app->run(); | ||
$commander->handle(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
parameters: | ||
ignoreErrors: | ||
- | ||
message: "#^Unable to resolve the template type TMakeKey in call to method static method Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\),mixed\\>\\:\\:make\\(\\)$#" | ||
count: 1 | ||
path: src/Console/Commander.php | ||
|
||
- | ||
message: "#^Unable to resolve the template type TMakeValue in call to method static method Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\),mixed\\>\\:\\:make\\(\\)$#" | ||
count: 1 | ||
path: src/Console/Commander.php | ||
|
||
- | ||
message: "#^Parameter \\#1 \\$model of method Illuminate\\\\Routing\\\\Console\\\\ControllerMakeCommand\\:\\:parseModel\\(\\) expects string, array\\|bool\\|string\\|null given\\.$#" | ||
count: 2 | ||
path: src/Console/ControllerMakeCommand.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
includes: | ||
- phpstan-baseline.neon | ||
|
||
parameters: | ||
|
||
paths: | ||
- src | ||
|
||
excludePaths: | ||
- ./src/Commands/*.php | ||
- ./src/Commands/Database/*.php | ||
- ./src/Commands/Routing/*.php | ||
|
||
# The level 8 is the highest level | ||
level: 7 | ||
|
||
ignoreErrors: | ||
- '#Method [a-zA-Z\\\<\>]+::handle\(\) should return bool\|null but returns int.#' | ||
|
||
checkGenericClassInNonGenericObjectType: false | ||
checkMissingIterableValueType: false | ||
treatPhpDocTypesAsCertain: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertDeprecationsToExceptions="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
verbose="true"> | ||
<coverage includeUncoveredFiles="false"> | ||
<include> | ||
<directory suffix=".php">src/</directory> | ||
</include> | ||
</coverage> | ||
<testsuites> | ||
<testsuite name="Canvas Test Suite"> | ||
<directory suffix="Test.php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
<php> | ||
<ini name="memory_limit" value="256M"/> | ||
<env name="CANVAS_FOR_LARAVEL" value="(true)"/> | ||
</php> | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertDeprecationsToExceptions="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
verbose="true"> | ||
<coverage includeUncoveredFiles="false"> | ||
<include> | ||
<directory suffix=".php">src/</directory> | ||
</include> | ||
</coverage> | ||
<testsuites> | ||
<testsuite name="Canvas Test Suite"> | ||
<directory suffix="Test.php">tests/Feature/</directory> | ||
<directory suffix="Test.php">tests/Unit/</directory> | ||
<directory suffix="Test.php">workbench/tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
<php> | ||
<ini name="memory_limit" value="256M"/> | ||
<env name="CANVAS_FOR_LARAVEL" value="(true)"/> | ||
</php> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace Orchestra\Canvas; | ||
|
||
use Illuminate\Contracts\Foundation\Application; | ||
use Illuminate\Contracts\Support\DeferrableProvider; | ||
use Illuminate\Support\Arr; | ||
use Illuminate\Support\ServiceProvider; | ||
use Orchestra\Canvas\Core\PresetManager; | ||
use Symfony\Component\Yaml\Yaml; | ||
|
||
class CanvasServiceProvider extends ServiceProvider implements DeferrableProvider | ||
{ | ||
/** | ||
* Register services. | ||
* | ||
* @return void | ||
*/ | ||
public function register(): void | ||
{ | ||
$this->callAfterResolving(PresetManager::class, function ($manager, $app) { | ||
$manager->extend('canvas', function ($app) { | ||
return new GeneratorPreset($app); | ||
}); | ||
|
||
$manager->setDefaultDriver('canvas'); | ||
}); | ||
|
||
$this->app->singleton('orchestra.canvas', function (Application $app) { | ||
$workingPath = \defined('CANVAS_WORKING_PATH') ? CANVAS_WORKING_PATH : $this->app->basePath(); | ||
|
||
$filesystem = $app->make('files'); | ||
|
||
$config = ['preset' => 'laravel']; | ||
|
||
if (file_exists($workingPath.DIRECTORY_SEPARATOR.'canvas.yaml')) { | ||
$config = Yaml::parseFile($workingPath.DIRECTORY_SEPARATOR.'canvas.yaml'); | ||
} else { | ||
Arr::set($config, 'testing.extends', [ | ||
'unit' => 'PHPUnit\Framework\TestCase', | ||
'feature' => 'Tests\TestCase', | ||
]); | ||
|
||
$config['namespace'] = rescue(fn () => rtrim($this->app->getNamespace(), '\\'), null, false); | ||
} | ||
|
||
return Canvas::preset($config, $workingPath); | ||
}); | ||
} | ||
|
||
/** | ||
* Bootstrap services. | ||
*/ | ||
public function boot(): void | ||
{ | ||
if ($this->app->runningInConsole()) { | ||
$this->commands([ | ||
Console\CodeMakeCommand::class, | ||
Console\GeneratorMakeCommand::class, | ||
Console\PresetMakeCommand::class, | ||
]); | ||
} | ||
} | ||
|
||
/** | ||
* Get the services provided by the provider. | ||
* | ||
* @return array<int, string> | ||
*/ | ||
public function provides() | ||
{ | ||
return [ | ||
'orchestra.canvas', | ||
]; | ||
} | ||
} |
Oops, something went wrong.