Skip to content

Commit

Permalink
Merge branch '9.x' into 9/dusk-test
Browse files Browse the repository at this point in the history
  • Loading branch information
crynobone authored Nov 19, 2024
2 parents aac5658 + a1be14a commit effb0c7
Show file tree
Hide file tree
Showing 15 changed files with 293 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: crynobone
liberapay: # crynobone
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # ["https://paypal.me/crynobone"]
2 changes: 1 addition & 1 deletion .github/workflows/analyse.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
os:
- "ubuntu-latest"
php:
- 8.2
- 8.3
dependencies:
- "highest"
experimental:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/audits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
php:
- 8.2
- 8.3
- 8.4
experimental:
- true

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coveralls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
os:
- "ubuntu-latest"
php:
- 8.2
- 8.3
dependencies:
- "highest"
experimental:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
php:
- 8.2
- 8.3
- 8.4
dependencies:
- "highest"
- "lowest"
Expand Down
19 changes: 10 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,23 @@
"php": "^8.2",
"composer-runtime-api": "^2.2",
"composer/semver": "^3.0",
"illuminate/console": "^11.21",
"illuminate/database": "^11.21",
"illuminate/filesystem": "^11.21",
"illuminate/support": "^11.21",
"illuminate/console": "^11.31",
"illuminate/database": "^11.31",
"illuminate/filesystem": "^11.31",
"illuminate/support": "^11.31",
"orchestra/canvas-core": "^9.0",
"orchestra/testbench-core": "^9.2",
"symfony/polyfill-php83": "^1.28",
"symfony/yaml": "^7.0"
"symfony/polyfill-php83": "^1.30",
"symfony/yaml": "^7.0.3"
},
"require-dev": {
"laravel/dusk": "^8.0",
"laravel/framework": "^11.21",
"laravel/framework": "^11.31",
"laravel/pint": "^1.17",
"mockery/mockery": "^1.6",
"mockery/mockery": "^1.6.10",
"phpstan/phpstan": "^1.11",
"phpunit/phpunit": "^11.0",
"phpunit/phpunit": "^11.3.6",
"spatie/laravel-ray": "^1.35"
},
"config": {
Expand Down Expand Up @@ -77,7 +78,7 @@
"@php vendor/bin/pint",
"@php vendor/bin/phpstan analyse --verbose"
],
"test": "@php vendor/bin/phpunit -c ./ --color",
"test": "@php vendor/bin/phpunit --no-configuration --color ./tests ./workbench/tests",
"ci": [
"@composer audit",
"@prepare",
Expand Down
6 changes: 3 additions & 3 deletions src/CanvasServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public function register(): void
$manager->setDefaultDriver('canvas');
});

$this->app->singleton('orchestra.canvas', function (Application $app) {
$workingPath = \defined('CANVAS_WORKING_PATH') ? CANVAS_WORKING_PATH : $this->app->basePath();
$this->app->singleton('orchestra.canvas', static function (Application $app) {
$workingPath = \defined('CANVAS_WORKING_PATH') ? CANVAS_WORKING_PATH : $app->basePath();

$filesystem = $app->make('files');

Expand All @@ -40,7 +40,7 @@ public function register(): void
'browser' => 'Tests\DuskTestCase',
]);

$config['namespace'] = rescue(fn () => rtrim($this->app->getNamespace(), '\\'), null, false);
$config['namespace'] = rescue(fn () => rtrim($app->getNamespace(), '\\'), null, false);
}

return Canvas::preset($config, $workingPath);
Expand Down
69 changes: 69 additions & 0 deletions src/Console/JobMiddlewareMakeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace Orchestra\Canvas\Console;

use Orchestra\Canvas\Core\Concerns\CodeGenerator;
use Orchestra\Canvas\Core\Concerns\TestGenerator;
use Orchestra\Canvas\Core\Concerns\UsesGeneratorOverrides;
use Symfony\Component\Console\Attribute\AsCommand;

/**
* @see https://github.com/laravel/framework/blob/11.x/src/Illuminate/Foundation/Console/JobMiddlewareMakeCommand.php
*/
#[AsCommand(name: 'make:job-middleware', description: 'Create a new job middleware class')]
class JobMiddlewareMakeCommand extends \Illuminate\Foundation\Console\JobMiddlewareMakeCommand
{
use CodeGenerator;
use TestGenerator;
use UsesGeneratorOverrides;

/**
* Configures the current command.
*
* @return void
*/
#[\Override]
protected function configure()
{
parent::configure();

$this->addGeneratorPresetOptions();
}

/**
* Execute the console command.
*
* @return bool|null
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
#[\Override]
public function handle()
{
/** @phpstan-ignore return.type */
return $this->generateCode() ? self::SUCCESS : self::FAILURE;
}

/**
* Get the destination class path.
*
* @param string $name
* @return string
*/
#[\Override]
protected function getPath($name)
{
return $this->getPathUsingCanvas($name);
}

/**
* Get the root namespace for the class.
*
* @return string
*/
#[\Override]
protected function rootNamespace()
{
return $this->rootNamespaceUsingCanvas();
}
}
16 changes: 16 additions & 0 deletions src/LaravelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Illuminate\Foundation\Console\ExceptionMakeCommand;
use Illuminate\Foundation\Console\InterfaceMakeCommand;
use Illuminate\Foundation\Console\JobMakeCommand;
use Illuminate\Foundation\Console\JobMiddlewareMakeCommand;
use Illuminate\Foundation\Console\ListenerMakeCommand;
use Illuminate\Foundation\Console\MailMakeCommand;
use Illuminate\Foundation\Console\ModelMakeCommand;
Expand Down Expand Up @@ -59,6 +60,7 @@ public function boot(): void
$this->registerExceptionMakeCommand();
$this->registerFactoryMakeCommand();
$this->registerJobMakeCommand();
$this->registerJobMiddlewareMakeCommand();
$this->registerInterfaceMakeCommand();
$this->registerListenerMakeCommand();
$this->registerMailMakeCommand();
Expand Down Expand Up @@ -239,6 +241,18 @@ protected function registerJobMakeCommand(): void
);
}

/**
* Register the command.
*
* @return void
*/
protected function registerJobMiddlewareMakeCommand()
{
$this->app->singleton(
JobMiddlewareMakeCommand::class, static fn ($app) => new Console\JobMiddlewareMakeCommand($app['files'])
);
}

/**
* Register the command.
*/
Expand Down Expand Up @@ -528,6 +542,8 @@ public function provides()
Console\InterfaceMakeCommand::class,
JobMakeCommand::class,
Console\JobMakeCommand::class,
JobMiddlewareMakeCommand::class,
Console\JobMiddlewareMakeCommand::class,
ListenerMakeCommand::class,
Console\ListenerMakeCommand::class,
MailMakeCommand::class,
Expand Down
3 changes: 0 additions & 3 deletions tests/Feature/Console/JobMakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ public function it_can_generate_job_file()
$this->assertFileContains([
'namespace App\Jobs;',
'use Illuminate\Contracts\Queue\ShouldQueue;',
'use Illuminate\Foundation\Bus\Dispatchable;',
'use Illuminate\Foundation\Queue\Queueable;',
'use Illuminate\Queue\InteractsWithQueue;',
'use Illuminate\Queue\SerializesModels;',
'class FooCreated implements ShouldQueue',
' use Queueable;',
], 'app/Jobs/FooCreated.php');
Expand Down
38 changes: 38 additions & 0 deletions tests/Feature/Console/JobMiddlewareMakeCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Orchestra\Canvas\Tests\Feature\Console;

use Orchestra\Canvas\Tests\Feature\TestCase;
use PHPUnit\Framework\Attributes\Test;

class JobMiddlewareMakeCommandTest extends TestCase
{
protected $files = [
'app/Jobs/Middleware/Foo.php',
'tests/Feature/Jobs/Middleware/FooTest.php',
];

#[Test]
public function it_can_generate_job_file()
{
$this->artisan('make:job-middleware', ['name' => 'Foo'])
->assertExitCode(0);

$this->assertFileContains([
'namespace App\Jobs\Middleware;',
'class Foo',
], 'app/Jobs/Middleware/Foo.php');

$this->assertFilenameNotExists('tests/Feature/Jobs/Middleware/FooTest.php');
}

#[Test]
public function it_can_generate_job_file_with_tests()
{
$this->artisan('make:job-middleware', ['name' => 'Foo', '--test' => true])
->assertExitCode(0);

$this->assertFilenameExists('app/Jobs/Middleware/Foo.php');
$this->assertFilenameExists('tests/Feature/Jobs/Middleware/FooTest.php');
}
}
3 changes: 0 additions & 3 deletions workbench/tests/JobMakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ public function testItCanGenerateJobFile()
$this->assertFileContains([
'namespace App\Jobs;',
'use Illuminate\Contracts\Queue\ShouldQueue;',
'use Illuminate\Foundation\Bus\Dispatchable;',
'use Illuminate\Foundation\Queue\Queueable;',
'use Illuminate\Queue\InteractsWithQueue;',
'use Illuminate\Queue\SerializesModels;',
'class FooCreated implements ShouldQueue',
'use Queueable;',
], 'app/Jobs/FooCreated.php');
Expand Down
33 changes: 33 additions & 0 deletions workbench/tests/JobMiddlewareMakeCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Illuminate\Tests\Integration\Generators;

class JobMiddlewareMakeCommandTest extends TestCase
{
protected $files = [
'app/Jobs/Middleware/Foo.php',
'tests/Feature/Jobs/Middleware/FooTest.php',
];

public function testItCanGenerateJobFile()
{
$this->artisan('make:job-middleware', ['name' => 'Foo'])
->assertExitCode(0);

$this->assertFileContains([
'namespace App\Jobs\Middleware;',
'class Foo',
], 'app/Jobs/Middleware/Foo.php');

$this->assertFilenameNotExists('tests/Feature/Jobs/Middleware/FooTest.php');
}

public function testItCanGenerateJobFileWithTest()
{
$this->artisan('make:job-middleware', ['name' => 'Foo', '--test' => true])
->assertExitCode(0);

$this->assertFilenameExists('app/Jobs/Middleware/Foo.php');
$this->assertFilenameExists('tests/Feature/Jobs/Middleware/FooTest.php');
}
}
51 changes: 51 additions & 0 deletions workbench/tests/MailMakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,32 @@ public function testItCanGenerateMailFileWithMarkdownOption()
], 'resources/views/foo-mail.blade.php');
}

public function testErrorsWillBeDisplayedWhenMarkdownsAlreadyExist()
{
$existingMarkdownPath = 'resources/views/existing-markdown.blade.php';
$this->app['files']
->put(
$this->app->basePath($existingMarkdownPath),
'<x-mail::message>My existing markdown</x-mail::message>'
);
$this->artisan('make:mail', ['name' => 'FooMail', '--markdown' => 'existing-markdown'])
->expectsOutputToContain('already exists.')
->assertExitCode(0);

$this->assertFileContains([
'namespace App\Mail;',
'use Illuminate\Mail\Mailable;',
'class FooMail extends Mailable',
'return new Content(',
"markdown: 'existing-markdown',",
], 'app/Mail/FooMail.php');
$this->assertFileContains([
'<x-mail::message>',
'My existing markdown',
'</x-mail::message>',
], $existingMarkdownPath);
}

public function testItCanGenerateMailFileWithViewOption()
{
$this->artisan('make:mail', ['name' => 'FooMail', '--view' => 'foo-mail'])
Expand All @@ -63,6 +89,31 @@ public function testItCanGenerateMailFileWithViewOption()
$this->assertFilenameExists('resources/views/foo-mail.blade.php');
}

public function testErrorsWillBeDisplayedWhenViewsAlreadyExist()
{
$existingViewPath = 'resources/views/existing-template.blade.php';
$this->app['files']
->put(
$this->app->basePath($existingViewPath),
'<div>My existing template</div>'
);
$this->artisan('make:mail', ['name' => 'FooMail', '--view' => 'existing-template'])
->expectsOutputToContain('already exists.')
->assertExitCode(0);

$this->assertFileContains([
'namespace App\Mail;',
'use Illuminate\Mail\Mailable;',
'class FooMail extends Mailable',
'return new Content(',
"view: 'existing-template',",
], 'app/Mail/FooMail.php');
$this->assertFilenameExists($existingViewPath);
$this->assertFileContains([
'<div>My existing template</div>',
], $existingViewPath);
}

public function testItCanGenerateMailFileWithTest()
{
$this->artisan('make:mail', ['name' => 'FooMail', '--test' => true])
Expand Down
Loading

0 comments on commit effb0c7

Please sign in to comment.