Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing PHPUnit BC break on base TestCase #701

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
vendor/
.idea/
.php-cs-fixer.cache
.phpunit.result.cache
composer.lock
43 changes: 22 additions & 21 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,31 @@
}
],
"require": {
"php": "^8.0.2 <8.4",
"illuminate/collections": "^9.0",
"illuminate/console": "^9.21.1",
"illuminate/container": "^9.0",
"illuminate/filesystem": "^9.0",
"illuminate/support": "^9.0",
"illuminate/view": "^9.8",
"php": "^8.3",
"illuminate/collections": "^11.0.7",
"illuminate/console": "^11.0.7",
"illuminate/container": "^11.0.7",
"illuminate/filesystem": "^11.0.7",
"illuminate/support": "^11.0.7",
"illuminate/view": "^11.0.7",
"league/commonmark": "^2.4",
"michelf/php-markdown": "^1.9",
"mnapoli/front-yaml": "^1.5",
"nunomaduro/collision": "^6.0",
"spatie/laravel-ignition": "^1.6",
"symfony/console": "^5.4 || ^6.0",
"symfony/error-handler": "^5.0 || ^6.0",
"symfony/finder": "^5.3.7 || ^6.0",
"symfony/process": "^5.0 || ^6.0",
"symfony/var-dumper": "^5.0 || ^6.0",
"symfony/yaml": "^5.0 || ^6.0",
"vlucas/phpdotenv": "^5.3.1"
"michelf/php-markdown": "^2.0",
"mnapoli/front-yaml": "^2.0",
"nunomaduro/collision": "^8.1",
"spatie/laravel-ignition": "^2.4",
"symfony/console": "^6.0 || ^7.0",
"symfony/error-handler": "^6.0 || ^7.0",
"symfony/finder": "^6.0 || ^7.0",
"symfony/process": "^6.0 || ^7.0",
"symfony/var-dumper": "^6.0 || ^7.0",
"symfony/yaml": "^6.0 || ^7.0",
"vlucas/phpdotenv": "^5.6",
"laravel/prompts": "^0.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.17",
"mockery/mockery": "^1.4",
"phpunit/phpunit": "^9.3.3"
"friendsofphp/php-cs-fixer": "^3.51",
"mockery/mockery": "^1.6",
"phpunit/phpunit": "^11.0.6"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 3 additions & 3 deletions src/Bootstrap/HandleExceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private function handleError($level, $message, $file = '', $line = 0, $context =
/**
* Handle a deprecation.
*
* @throws \TightenCo\Jigsaw\Exceptions\DeprecationException
* @throws DeprecationException
*/
private function handleDeprecation(Throwable $e): void
{
Expand All @@ -82,7 +82,7 @@ private function handleDeprecation(Throwable $e): void
//
}

static::$app->make(ExceptionHandler::class)->renderForConsole(new ConsoleOutput, $e);
static::$app->make(ExceptionHandler::class)->renderForConsole(new ConsoleOutput(), $e);
}

/**
Expand All @@ -102,7 +102,7 @@ private function handleException(Throwable $e): void
//
}

static::$app->make(ExceptionHandler::class)->renderForConsole(new ConsoleOutput, $e);
static::$app->make(ExceptionHandler::class)->renderForConsole(new ConsoleOutput(), $e);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Console/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

abstract class Command extends SymfonyCommand
{
protected $input;
protected $output;
protected InputInterface $input;
protected OutputInterface $output;
protected $console;

public function execute(InputInterface $input, OutputInterface $output)
public function execute(InputInterface $input, OutputInterface $output): int
{
$this->input = $input;
$this->output = $output;
Expand Down
2 changes: 1 addition & 1 deletion src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private function loadEnvironmentVariables(): void
try {
Dotenv::create(Env::getRepository(), $this->path)->safeLoad();
} catch (InvalidFileException $e) {
$output = (new ConsoleOutput)->getErrorOutput();
$output = (new ConsoleOutput())->getErrorOutput();

$output->writeln('The environment file is invalid!');
$output->writeln($e->getMessage());
Expand Down
4 changes: 2 additions & 2 deletions src/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function renderForConsole($output, Throwable $e): void
}

if ($e instanceof SymfonyConsoleExceptionInterface) {
(new ConsoleApplication)->renderThrowable($e, $output);
(new ConsoleApplication())->renderThrowable($e, $output);

return;
}
Expand All @@ -79,7 +79,7 @@ public function renderForConsole($output, Throwable $e): void

$e = $this->mapException($e);

/** @var \NunoMaduro\Collision\Provider $provider */
/** @var Provider $provider */
$provider = app(Provider::class);

$handler = $provider->register()->getHandler()->setOutput($output);
Expand Down
10 changes: 5 additions & 5 deletions src/Parsers/CommonMarkParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ public function __construct()
{
$environment = new Environment(Arr::get(app('config'), 'commonmark.config', []));

$environment->addExtension(new CommonMarkCoreExtension);
$environment->addExtension(new CommonMarkCoreExtension());

collect(Arr::get(app('config'), 'commonmark.extensions', [
new AttributesExtension,
new SmartPunctExtension,
new StrikethroughExtension,
new TableExtension,
new AttributesExtension(),
new SmartPunctExtension(),
new StrikethroughExtension(),
new TableExtension(),
]))->map(fn ($extension) => $environment->addExtension($extension));

$this->converter = new MarkdownConverter($environment);
Expand Down
4 changes: 2 additions & 2 deletions src/Parsers/MarkdownParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ class MarkdownParser implements FrontYAMLMarkdownParserInterface
{
public $parser;

public function __construct(MarkdownParserContract $parser = null)
public function __construct(?MarkdownParserContract $parser = null)
{
$this->parser = $parser ?? new JigsawMarkdownParser;
$this->parser = $parser ?? new JigsawMarkdownParser();
}

public function __get($property)
Expand Down
4 changes: 2 additions & 2 deletions src/Providers/CollectionServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CollectionServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->bind('outputPathResolver', fn () => new BasicOutputPathResolver);
$this->app->bind('outputPathResolver', fn () => new BasicOutputPathResolver());

$this->registerHandlers();
$this->registerPathResolver();
Expand Down Expand Up @@ -100,7 +100,7 @@ private function registerSiteBuilder(): void
$this->app->bind(SiteBuilder::class, function (Container $app) {
return new SiteBuilder($app['files'], $app->cachePath(), $app['outputPathResolver'], $app['consoleOutput'], [
$app[CollectionItemHandler::class],
new IgnoredHandler,
new IgnoredHandler(),
$app[PaginatedPageHandler::class],
$app[MarkdownHandler::class],
$app[BladeHandler::class],
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/CompatibilityServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public function register(): void
{
$this->app->instance('cwd', $this->app->path());

$this->app->singleton('consoleOutput', fn () => new ConsoleOutput);
$this->app->singleton('consoleOutput', fn () => new ConsoleOutput());
}
}
2 changes: 1 addition & 1 deletion src/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public function register(): void
{
$this->app->singleton('dispatcher', fn (Container $app) => new Dispatcher($app));

$this->app->singleton('events', fn (Container $app) => new EventBus);
$this->app->singleton('events', fn (Container $app) => new EventBus());
}
}
2 changes: 1 addition & 1 deletion src/Providers/FilesystemServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class FilesystemServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->singleton('files', fn () => new Filesystem);
$this->app->singleton('files', fn () => new Filesystem());
}
}
2 changes: 1 addition & 1 deletion src/Providers/MarkdownServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function register(): void
$this->app->bind(YAMLParser::class, SymfonyYAMLParser::class);

$this->app->bind(MarkdownParserContract::class, function (Container $app) {
return $app['config']->get('commonmark') ? new CommonMarkParser : new JigsawMarkdownParser;
return $app['config']->get('commonmark') ? new CommonMarkParser() : new JigsawMarkdownParser();
});

$this->app->singleton('markdownParser', fn (Container $app) => new MarkdownParser($app[MarkdownParserContract::class]));
Expand Down
4 changes: 2 additions & 2 deletions src/Providers/ViewServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function register(): void
$this->registerEngineResolvers();

(new BladeDirectivesFile($this->app->path('blade.php'), $this->app['blade.compiler']))->register();
$this->app->bind(ViewRenderer::class, fn () => new ViewRenderer);
$this->app->bind(ViewRenderer::class, fn () => new ViewRenderer());
$this->app->bind(TemporaryFilesystem::class, fn (Container $app) => new TemporaryFilesystem($app->cachePath()));

// TODO
Expand Down Expand Up @@ -74,7 +74,7 @@ private function registerBladeCompiler(): void
private function registerEngineResolvers(): void
{
$this->app->singleton('view.engine.resolver', function (Container $app) {
$resolver = new EngineResolver;
$resolver = new EngineResolver();
$compilerEngine = new CompilerEngine($app['blade.compiler'], $app['files']);

// Same as Laravel
Expand Down
6 changes: 3 additions & 3 deletions src/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
use Symfony\Component\VarDumper\VarDumper;

if (! function_exists('app')) {
function app(string $abstract = null, array $parameters = []): mixed
function app(?string $abstract = null, array $parameters = []): mixed
{
if (is_null($abstract)) {
return \TightenCo\Jigsaw\Container::getInstance();
return TightenCo\Jigsaw\Container::getInstance();
}

return \TightenCo\Jigsaw\Container::getInstance()->make($abstract, $parameters);
return TightenCo\Jigsaw\Container::getInstance()->make($abstract, $parameters);
}
}

Expand Down
4 changes: 2 additions & 2 deletions stubs/site/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use TightenCo\Jigsaw\Jigsaw;

/** @var \Illuminate\Container\Container $container */
/** @var \TightenCo\Jigsaw\Events\EventBus $events */
/** @var Illuminate\Container\Container $container */
/** @var TightenCo\Jigsaw\Events\EventBus $events */

/*
* You can run custom code at different stages of the build process by
Expand Down
4 changes: 2 additions & 2 deletions tests/CommonMarkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function replace_commonmark_extensions()
$this->buildSite($files, [
'commonmark' => [
'extensions' => [
new DescriptionListExtension,
new DescriptionListExtension(),
],
],
]);
Expand All @@ -74,7 +74,7 @@ public function override_parser_with_custom_class()
$files = $this->withContent('### Heading {.class}');

$this->app->bind(MarkdownParserContract::class, function () {
return new class implements MarkdownParserContract {
return new class() implements MarkdownParserContract {
public function parse(string $text)
{
return <<<EOT
Expand Down
2 changes: 1 addition & 1 deletion tests/EventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function multiple_event_listeners_are_fired_in_the_order_they_were_define
/** @test */
public function it_can_handle_invokable_listeners()
{
$this->app['events']->beforeBuild(new class {
$this->app['events']->beforeBuild(new class() {
private $object;

public function __construct()
Expand Down
2 changes: 1 addition & 1 deletion tests/JigsawMacroTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function jigsaw_macro_function_calls_successfully()
*/
public function jigsaw_mixin_function_calls_successfully()
{
Jigsaw::mixin(new JigsawMixinTestClass);
Jigsaw::mixin(new JigsawMixinTestClass());

$this->assertSame('Reed', Jigsaw::getNameMixin());
}
Expand Down
16 changes: 8 additions & 8 deletions tests/SnapshotsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ protected function setUp(): void
{
parent::setUp();

$this->filesystem = new Filesystem;
$this->filesystem = new Filesystem();
}

public function snapshots(): array
{
return collect((new Filesystem)->directories($this->source()))
return collect((new Filesystem())->directories($this->source()))
->map(fn ($path) => basename($path))
->reject(fn ($name) => Str::endsWith($name, '_snapshot'))
// Prepend the test command with JIGSAW_SNAPSHOTS=<snapshot-names> to run specific snapshot tests
Expand All @@ -46,7 +46,7 @@ public function snapshots(): array
public function build(string $name)
{
// Delete the contents of the output directory in the source to clean up previous builds
$this->filesystem->deleteDirectory($this->output($name), true);
$this->filesystem->deleteDirectory($this->testOutput($name), true);

$jigsaw = realpath(implode('/', array_filter([__DIR__, '..', 'jigsaw'])));
$arguments = static::$arguments[$name] ?? [];
Expand All @@ -63,19 +63,19 @@ public function build(string $name)

private function assertSnapshotMatches($name)
{
$this->assertDirectoryExists($this->output($name));
$this->assertDirectoryExists($this->testOutput($name));

$this->assertSame(
collect($this->filesystem->allFiles($this->snapshot($name), true))
->map(fn ($file) => Str::after($file->getPathname(), $this->snapshot($name)))
->toArray(),
collect($this->filesystem->allFiles($this->output($name), true))
->map(fn ($file) => Str::after($file->getPathname(), $this->output($name)))
collect($this->filesystem->allFiles($this->testOutput($name), true))
->map(fn ($file) => Str::after($file->getPathname(), $this->testOutput($name)))
->toArray(),
"Output file structure does not match snapshot in '{$name}'.",
);

collect($this->filesystem->allFiles($this->output($name), true))->map(function (SplFileInfo $file) use ($name) {
collect($this->filesystem->allFiles($this->testOutput($name), true))->map(function (SplFileInfo $file) use ($name) {
$this->assertSame(
file_get_contents(implode(DIRECTORY_SEPARATOR, array_filter([$this->snapshot($name), $file->getRelativePathname()]))),
$file->getContents(),
Expand All @@ -89,7 +89,7 @@ private function source(string $name = ''): string
return implode(DIRECTORY_SEPARATOR, array_filter([__DIR__, 'snapshots', $name]));
}

private function output(string $name): string
private function testOutput(string $name): string
{
$output = $name === 'environment-specific-config-file' ? 'build_staging' : 'build_local';

Expand Down
12 changes: 6 additions & 6 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ class TestCase extends PHPUnit
protected Filesystem $filesystem;
protected string $tmp;

public function __construct()
public function __construct(string $name = 'Jigsaw')
{
parent::__construct();
parent::__construct($name);

$this->filesystem = new Filesystem;
$this->filesystem = new Filesystem();
}

protected function setUp(): void
Expand All @@ -39,15 +39,15 @@ protected function setUp(): void

$this->createTmp();

$this->app = new Container;
$this->app = new Container();
/* @internal The '__testing' binding is for Jigsaw development only and may be removed. */
$this->app->instance('__testing', true);
$this->app->singleton(
\Illuminate\Contracts\Debug\ExceptionHandler::class,
\TightenCo\Jigsaw\Exceptions\Handler::class,
);
$this->app->bootstrapWith([
\TightenCo\Jigsaw\Bootstrap\HandleExceptions::class,
HandleExceptions::class,
]);

$this->app->buildPath = [
Expand Down Expand Up @@ -209,7 +209,7 @@ protected function fixDirectorySlashes(string $path): string
return str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path);
}

protected function assertOutputFile(string $path, string $contents, string $message = null): void
protected function assertOutputFile(string $path, string $contents, ?string $message = null): void
{
static::assertStringEqualsFile(
$this->tmpPath($path),
Expand Down
Loading