Skip to content

Commit

Permalink
Uses pint
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Sep 18, 2022
1 parent b2109a0 commit c874066
Show file tree
Hide file tree
Showing 21 changed files with 140 additions and 111 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ jobs:
run: composer update --${{ matrix.dependency-version }} --no-interaction --no-progress --ansi

- name: Unit Tests
run: composer test:unit
run: composer test:unit
if: false # Waiting for "orchestra/testbench" to support PHPUnit 10.x
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
},
"require-dev": {
"laravel/dusk": "^7.0.1",
"orchestra/testbench": "^7.7.0",
"pestphp/pest-dev-tools": "^2.0.0"
},
"minimum-stability": "dev",
Expand Down
2 changes: 1 addition & 1 deletion src/Autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
];

foreach ($files as $file) {
require_once __DIR__ . "/{$file}";
require_once __DIR__."/{$file}";
}
})();
15 changes: 8 additions & 7 deletions src/Commands/PestDatasetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,28 @@ final class PestDatasetCommand extends Command
*/
public function handle(): void
{
/* @phpstan-ignore-next-line */
TestSuite::getInstance(base_path(), $this->option('test-directory'));
/** @var string $testDirectory */
$testDirectory = $this->option('test-directory');

TestSuite::getInstance(base_path(), $testDirectory);

/** @var string $name */
$name = $this->argument('name');

$relativePath = sprintf(testDirectory('DatasetsRepository/%s.php'), ucfirst($name));

/* @phpstan-ignore-next-line */
$target = base_path($relativePath);

if (File::exists($target)) {
throw new InvalidConsoleArgument(sprintf('%s already exist', $target));
throw new InvalidConsoleArgument(sprintf('[%s] already exist', $target));
}

if (! File::exists(dirname($relativePath))) {
File::makeDirectory(dirname($relativePath));
}

$contents = File::get(implode(DIRECTORY_SEPARATOR, [
dirname(__DIR__, 3),
dirname(__DIR__, 2),
'stubs',
'Dataset.php',
]));
Expand All @@ -67,8 +68,8 @@ public function handle(): void
$element = Str::singular($name);
$contents = str_replace('{dataset_element}', $element, $contents);
File::put($target, str_replace('{dataset_name}', $name, $contents));
$message = sprintf('`%s` created successfully.', $relativePath);
$message = sprintf('[%s] created successfully.', $relativePath);

$this->output->success($message);
$this->components->info($message);
}
}
26 changes: 13 additions & 13 deletions src/Commands/PestInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Pest\Console\Thanks;
use Pest\Exceptions\InvalidConsoleArgument;
use function Pest\testDirectory;
use Pest\TestSuite;

Expand Down Expand Up @@ -40,23 +39,24 @@ final class PestInstallCommand extends Command
*/
public function handle(): void
{
/* @phpstan-ignore-next-line */
TestSuite::getInstance(base_path(), $this->option('test-directory'));
/** @var string $testDirectory */
$testDirectory = $this->option('test-directory');

TestSuite::getInstance(base_path(), $testDirectory);

/* @phpstan-ignore-next-line */
$pest = base_path(testDirectory('Pest.php'));

if (File::exists($pest)) {
throw new InvalidConsoleArgument(sprintf('%s already exist', $pest));
}
$this->components->info('[tests/Pest.php] already exists.');
} else {
File::copy(implode(DIRECTORY_SEPARATOR, [
dirname(__DIR__, 2),
self::STUBS,
'Pest.php',
]), $pest);

File::copy(implode(DIRECTORY_SEPARATOR, [
dirname(__DIR__, 3),
self::STUBS,
'Pest.php',
]), $pest);

$this->output->success('`tests/Pest.php` created successfully.');
$this->components->info('[tests/Pest.php] created successfully.');
}

if (! (bool) $this->option('no-interaction')) {
(new Thanks($this->output))();
Expand Down
20 changes: 12 additions & 8 deletions src/Commands/PestTestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Pest\Exceptions\InvalidConsoleArgument;
use Pest\Support\Str;
use function Pest\testDirectory;
use Pest\TestSuite;
Expand All @@ -33,10 +32,12 @@ final class PestTestCommand extends Command
/**
* Execute the console command.
*/
public function handle(): void
public function handle(): int
{
/* @phpstan-ignore-next-line */
TestSuite::getInstance(base_path(), $this->option('test-directory'));
/** @var string $testDirectory */
$testDirectory = $this->option('test-directory');

TestSuite::getInstance(base_path(), $testDirectory);

/** @var string $name */
$name = $this->argument('name');
Expand All @@ -49,19 +50,20 @@ public function handle(): void
ucfirst($name)
);

/* @phpstan-ignore-next-line */
$target = base_path($relativePath);

if (! File::isDirectory(dirname((string) $target))) {
File::makeDirectory(dirname((string) $target), 0777, true, true);
}

if (File::exists($target) && ! (bool) $this->option('force')) {
throw new InvalidConsoleArgument(sprintf('%s already exist', $target));
$this->components->error(sprintf('[%s] already exist', $target));

return 1;
}

$contents = File::get(implode(DIRECTORY_SEPARATOR, [
dirname(__DIR__, 3),
dirname(__DIR__, 2),
'stubs',
sprintf('%s.php', $type),
]));
Expand All @@ -70,8 +72,10 @@ public function handle(): void
$name = Str::endsWith($name, 'test') ? mb_substr($name, 0, -4) : $name;

File::put($target, str_replace('{name}', $name, $contents));
$message = sprintf('`%s` created successfully.', $relativePath);
$message = sprintf('[%s] created successfully.', $relativePath);

$this->output->success($message);

return 0;
}
}
6 changes: 3 additions & 3 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ function instance(string $abstract, object $instance): object
/**
* Mock an instance of an object in the container.
*/
function mock(string $abstract, Closure $mock = null): MockInterface
function mock(string $abstract, Closure $mock = null): MockInterface // @phpstan-ignore-line
{
return test()->mock(...func_get_args());
}

/**
* Mock a partial instance of an object in the container.
*/
function partialMock(string $abstract, Closure $mock = null): MockInterface
function partialMock(string $abstract, Closure $mock = null): MockInterface // @phpstan-ignore-line
{
return test()->partialMock(...func_get_args());
}

/**
* Spy an instance of an object in the container.
*/
function spy(string $abstract, Closure $mock = null): MockInterface
function spy(string $abstract, Closure $mock = null): MockInterface // @phpstan-ignore-line
{
return test()->spy(...func_get_args());
}
Expand Down
14 changes: 5 additions & 9 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ function assertDatabaseCount(string $table, int $count, string $connection = nul
/**
* Assert the given record has been deleted.
*
* @param Model|string $table
*
* @param Model|string $table
* @return TestCase
*/
function assertDeleted($table, array $data = [], string $connection = null)
Expand All @@ -73,8 +72,7 @@ function assertDeleted($table, array $data = [], string $connection = null)
/**
* Assert the given record has been "soft deleted".
*
* @param Model|string $table
*
* @param Model|string $table
* @return TestCase
*/
function assertSoftDeleted($table, array $data = [], string $connection = null, string $deletedAtColumn = 'deleted_at')
Expand All @@ -85,8 +83,7 @@ function assertSoftDeleted($table, array $data = [], string $connection = null,
/**
* Assert the given record has not been "soft deleted".
*
* @param Model|string $table
*
* @param Model|string $table
* @return TestCase
*/
function assertNotSoftDeleted($table, array $data = [], string $connection = null, string $deletedAtColumn = 'deleted_at')
Expand All @@ -97,7 +94,7 @@ function assertNotSoftDeleted($table, array $data = [], string $connection = nul
/**
* Determine if the argument is a soft deletable model.
*
* @param mixed $model
* @param mixed $model
*/
function isSoftDeletableModel($model): bool
{
Expand All @@ -115,8 +112,7 @@ function getConnection(string $connection = null): Connection
/**
* Seed a given database connection.
*
* @param array|string $class
*
* @param array|string $class
* @return TestCase
*/
function seed($class = 'Database\\Seeders\\DatabaseSeeder')
Expand Down
21 changes: 9 additions & 12 deletions src/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ function withServerVariables(array $server)
/**
* Disable middleware for the test.
*
* @param string|array|null $middleware
*
* @param string|array|null $middleware
* @return TestCase
*/
function withoutMiddleware($middleware = null)
Expand All @@ -62,8 +61,7 @@ function withoutMiddleware($middleware = null)
/**
* Enable the given middleware for the test.
*
* @param string|array|null $middleware
*
* @param string|array|null $middleware
* @return TestCase
*/
function withMiddleware($middleware = null)
Expand Down Expand Up @@ -274,14 +272,13 @@ function json(string $method, string $uri, array $data = [], array $headers = []
/**
* Call the given URI and return the Response.
*
* @param string $method
* @param string $uri
* @param array $parameters
* @param array $cookies
* @param array $files
* @param array $server
* @param string|null $content
*
* @param string $method
* @param string $uri
* @param array $parameters
* @param array $cookies
* @param array $files
* @param array $server
* @param string|null $content
* @return TestResponse
*/
function call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
Expand Down
15 changes: 5 additions & 10 deletions src/MocksApplicationServices.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
*
* These events will be mocked, so that handlers will not actually be executed.
*
* @param array|string $events
*
* @param array|string $events
* @return TestCase
*
* @throws \Exception
Expand All @@ -27,8 +26,7 @@ function expectsEvents($events)
*
* These events will be mocked, so that handlers will not actually be executed.
*
* @param array|string $events
*
* @param array|string $events
* @return TestCase
*/
function doesntExpectEvents($events)
Expand Down Expand Up @@ -59,8 +57,7 @@ function getFiredEvents(array $events): array
*
* These jobs will be mocked, so that handlers will not actually be executed.
*
* @param array|string $jobs
*
* @param array|string $jobs
* @return TestCase
*/
function expectsJobs($jobs)
Expand All @@ -73,8 +70,7 @@ function expectsJobs($jobs)
*
* These jobs will be mocked, so that handlers will not actually be executed.
*
* @param array|string $jobs
*
* @param array|string $jobs
* @return TestCase
*/
function doesntExpectJobs($jobs)
Expand Down Expand Up @@ -129,8 +125,7 @@ function withoutNotifications()
/**
* Specify a notification that is expected to be dispatched.
*
* @param mixed $notifiable
*
* @param mixed $notifiable
* @return TestCase
*/
function expectsNotification($notifiable, string $notification)
Expand Down
6 changes: 2 additions & 4 deletions src/Time.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
/**
* Begin travelling to another time.
*
* @param int $value
*
* @param int $value
* @return \Illuminate\Foundation\Testing\Wormhole
*/
function travel($value)
Expand All @@ -21,8 +20,7 @@ function travel($value)
/**
* Travel to another time.
*
* @param callable|null $callback
*
* @param callable|null $callback
* @return mixed
*/
function travelTo(DateTimeInterface $date, $callback = null)
Expand Down
Loading

0 comments on commit c874066

Please sign in to comment.