Skip to content

Commit

Permalink
Merge branch '7.x' into 8.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 Nov 6, 2024
2 parents c084658 + dc6d4cf commit a9edfc4
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<file>src/Exceptions/PHPUnitErrorException.php</file>
<file>src/Foundation/Console/Concerns/InteractsWithIO.php</file>
<file>src/Foundation/Console/Kernel.php</file>
<file>src/Foundation/Console/DevToolCommand.php</file>
<file>src/Foundation/Console/PurgeSkeletonCommand.php</file>
<file>src/Foundation/Console/ServeCommand.php</file>
<file>src/Foundation/Console/TestFallbackCommand.php</file>
Expand Down
22 changes: 20 additions & 2 deletions src/Foundation/Console/CreateSqliteDbCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;
use Symfony\Component\Console\Attribute\AsCommand;

use function Orchestra\Testbench\join_paths;
Expand All @@ -16,7 +17,9 @@ class CreateSqliteDbCommand extends Command
*
* @var string
*/
protected $signature = 'package:create-sqlite-db {--force : Overwrite the database file}';
protected $signature = 'package:create-sqlite-db
{--database=database.sqlite : Set the database name}
{--force : Overwrite the database file}';

/**
* Execute the console command.
Expand All @@ -37,7 +40,7 @@ public function handle(Filesystem $filesystem)
? join_paths($databasePath, 'database.sqlite.example')
: (string) realpath(join_paths(__DIR__, 'stubs', 'database.sqlite.example'));

$to = join_paths($databasePath, 'database.sqlite');
$to = join_paths($databasePath, $this->databaseName());

(new Actions\GeneratesFile(
filesystem: $filesystem,
Expand All @@ -48,4 +51,19 @@ public function handle(Filesystem $filesystem)

return Command::SUCCESS;
}

/**
* Resolve the database name.
*
* @return string
*/
protected function databaseName(): string
{
if (empty($database = $this->option('database'))) {
$database = 'database';
}

/** @var string $database */
return \sprintf('%s.sqlite', Str::before((string) $database, '.sqlite'));
}
}
31 changes: 29 additions & 2 deletions src/Foundation/Console/DropSqliteDbCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;
use Symfony\Component\Console\Attribute\AsCommand;

use function Orchestra\Testbench\join_paths;

#[AsCommand(name: 'package:drop-sqlite-db', description: 'Drop sqlite database file')]
class DropSqliteDbCommand extends Command
{
Expand All @@ -14,7 +17,9 @@ class DropSqliteDbCommand extends Command
*
* @var string
*/
protected $signature = 'package:drop-sqlite-db';
protected $signature = 'package:drop-sqlite-db
{--database=database.sqlite : Set the database name}
{--all : Delete all SQLite databases}';

/**
* Execute the console command.
Expand All @@ -24,12 +29,34 @@ class DropSqliteDbCommand extends Command
*/
public function handle(Filesystem $filesystem)
{
$databasePath = $this->laravel->databasePath();

(new Actions\DeleteFiles(
filesystem: $filesystem,
components: $this->components,
workingPath: $this->laravel->basePath(),
))->handle([$this->laravel->databasePath('database.sqlite')]);
))->handle(
match ($this->option('all')) {
true => [...$filesystem->glob(join_paths($databasePath, '*.sqlite'))],
default => [join_paths($databasePath, $this->databaseName())],
}
);

return Command::SUCCESS;
}

/**
* Resolve the database name.
*
* @return string
*/
protected function databaseName(): string
{
if (empty($database = $this->option('database'))) {
$database = 'database';
}

/** @var string $database */
return \sprintf('%s.sqlite', Str::before((string) $database, '.sqlite'));
}
}
4 changes: 4 additions & 0 deletions tests/Concerns/HandlesAssertionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class HandlesAssertionsTest extends TestCase
/** @test */
public function it_should_mark_the_tests_as_skipped_when_condition_is_true()
{
$this->expectOutputString('Successfully skipped current test');

$this->markTestSkippedWhen(true, 'Successfully skipped current test');

$this->assertTrue(false, 'Test incorrectly executed.');
Expand All @@ -30,6 +32,8 @@ public function it_should_mark_the_tests_as_skipped_when_condition_is_false()
/** @test */
public function it_should_mark_the_tests_as_skipped_unless_condition_is_false()
{
$this->expectOutputString('Successfully skipped current test');

$this->markTestSkippedUnless(false, 'Successfully skipped current test');

$this->assertTrue(false, 'Test incorrectly executed.');
Expand Down

0 comments on commit a9edfc4

Please sign in to comment.