Skip to content

Commit

Permalink
Merge branch 'master' into 9.x
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-ivanov committed Mar 12, 2022
2 parents 4639c69 + 6a9bd28 commit ec3c413
Show file tree
Hide file tree
Showing 29 changed files with 107 additions and 414 deletions.
73 changes: 13 additions & 60 deletions src/Asserts/ArtisanAsserts.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@ trait ArtisanAsserts
{
/**
* Add expectation that the given confirmation question would be shown.
*
* @param string $question
* @param string $command
* @param array $parameters
* @return void
*/
protected function willSeeConfirmation(string $question, string $command, array $parameters = [])
protected function willSeeConfirmation(string $question, string $command, array $parameters = []): void
{
$mock = Mockery::mock("{$command}[confirm]");
$mock->shouldReceive('confirm')->once()->with($question);
Expand All @@ -26,13 +21,8 @@ protected function willSeeConfirmation(string $question, string $command, array

/**
* Add expectation that the given confirmation question would not be shown.
*
* @param string $question
* @param string $command
* @param array $parameters
* @return void
*/
protected function willNotSeeConfirmation(string $question, string $command, array $parameters = [])
protected function willNotSeeConfirmation(string $question, string $command, array $parameters = []): void
{
$mock = Mockery::mock("{$command}[confirm]");
$mock->shouldNotReceive('confirm')->with($question);
Expand All @@ -42,13 +32,8 @@ protected function willNotSeeConfirmation(string $question, string $command, arr

/**
* Add expectation that the given confirmation question would be shown, and accept it.
*
* @param string $question
* @param string $command
* @param array $parameters
* @return void
*/
protected function willGiveConfirmation(string $question, string $command, array $parameters = [])
protected function willGiveConfirmation(string $question, string $command, array $parameters = []): void
{
$mock = Mockery::mock("{$command}[confirm]");
$mock->shouldReceive('confirm')->once()->with($question)->andReturn(true);
Expand All @@ -58,13 +43,8 @@ protected function willGiveConfirmation(string $question, string $command, array

/**
* Add expectation that the given confirmation question would be shown, and do not accept it.
*
* @param string $question
* @param string $command
* @param array $parameters
* @return void
*/
protected function willNotGiveConfirmation(string $question, string $command, array $parameters = [])
protected function willNotGiveConfirmation(string $question, string $command, array $parameters = []): void
{
$mock = Mockery::mock("{$command}[confirm]");
$mock->shouldReceive('confirm')->once()->with($question)->andReturn(false);
Expand All @@ -74,11 +54,8 @@ protected function willNotGiveConfirmation(string $question, string $command, ar

/**
* Assert that the given artisan output is seen.
*
* @param string $output
* @return void
*/
protected function seeArtisanOutput(string $output)
protected function seeArtisanOutput(string $output): void
{
if (File::exists($output)) {
$output = File::get($output);
Expand All @@ -91,11 +68,8 @@ protected function seeArtisanOutput(string $output)

/**
* Assert that the given artisan output is not seen.
*
* @param string $output
* @return void
*/
protected function dontSeeArtisanOutput(string $output)
protected function dontSeeArtisanOutput(string $output): void
{
if (File::exists($output)) {
$output = File::get($output);
Expand All @@ -108,11 +82,8 @@ protected function dontSeeArtisanOutput(string $output)

/**
* Assert that the given string is seen in the artisan output.
*
* @param string $needle
* @return void
*/
protected function seeInArtisanOutput(string $needle)
protected function seeInArtisanOutput(string $needle): void
{
if (File::exists($needle)) {
$needle = File::get($needle);
Expand All @@ -125,11 +96,8 @@ protected function seeInArtisanOutput(string $needle)

/**
* Assert that the given string is not seen in the artisan output.
*
* @param string $needle
* @return void
*/
protected function dontSeeInArtisanOutput(string $needle)
protected function dontSeeInArtisanOutput(string $needle): void
{
if (File::exists($needle)) {
$needle = File::get($needle);
Expand All @@ -142,47 +110,35 @@ protected function dontSeeInArtisanOutput(string $needle)

/**
* Assert that the given data is seen in the artisan table output.
*
* @param array $data
* @return void
*/
protected function seeArtisanTableOutput(array $data)
protected function seeArtisanTableOutput(array $data): void
{
$message = 'Failed asserting that artisan table output consists of expected data.';
$this->assertEquals($data, $this->parseArtisanTableOutput($this->getArtisanOutput()), $message);
}

/**
* Assert that the given data is not seen in the artisan table output.
*
* @param array $data
* @return void
*/
protected function dontSeeArtisanTableOutput(array $data)
protected function dontSeeArtisanTableOutput(array $data): void
{
$message = 'Failed asserting that artisan table output not consists of expected data.';
$this->assertNotEquals($data, $this->parseArtisanTableOutput($this->getArtisanOutput()), $message);
}

/**
* Assert that the artisan table output has the given number of data rows.
*
* @param int $count
* @return void
*/
protected function seeArtisanTableRowsCount(int $count)
protected function seeArtisanTableRowsCount(int $count): void
{
$message = "Failed asserting that artisan table rows count equals to `{$count}`.";
$this->assertCount($count, $this->parseArtisanTableOutput($this->getArtisanOutput()), $message);
}

/**
* Assert that the artisan table output doesn't have the given number of data rows.
*
* @param int $count
* @return void
*/
protected function dontSeeArtisanTableRowsCount(int $count)
protected function dontSeeArtisanTableRowsCount(int $count): void
{
$message = "Failed asserting that artisan table rows count not equals to `{$count}`.";
$this->assertNotCount($count, $this->parseArtisanTableOutput($this->getArtisanOutput()), $message);
Expand All @@ -192,11 +148,8 @@ protected function dontSeeArtisanTableRowsCount(int $count)
* Parse the artisan table output.
*
* Return data rows with headers as keys.
*
* @param string $output
* @return array
*/
private function parseArtisanTableOutput(string $output)
private function parseArtisanTableOutput(string $output): array
{
$output = explode("\n", trim($output));

Expand Down
18 changes: 4 additions & 14 deletions src/Asserts/CollectionAsserts.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,25 @@ trait CollectionAsserts
{
/**
* Assert that the given collections are equal based on the specified key.
*
* @param \Illuminate\Support\Collection $collection1
* @param \Illuminate\Support\Collection $collection2
* @param string $key
* @return void
*/
protected function assertCollectionsEqual(Collection $collection1, Collection $collection2, string $key)
protected function assertCollectionsEqual(Collection $collection1, Collection $collection2, string $key): void
{
$this->assertEquals(
$collection1->pluck($key)->sort()->values(),
$collection2->pluck($key)->sort()->values(),
'Failed asserting that collections are equal.'
'Failed asserting that collections are equal.',
);
}

/**
* Assert that the given collections are not equal based on the specified key.
*
* @param \Illuminate\Support\Collection $collection1
* @param \Illuminate\Support\Collection $collection2
* @param string $key
* @return void
*/
protected function assertCollectionsNotEqual(Collection $collection1, Collection $collection2, string $key)
protected function assertCollectionsNotEqual(Collection $collection1, Collection $collection2, string $key): void
{
$this->assertNotEquals(
$collection1->pluck($key)->sort()->values(),
$collection2->pluck($key)->sort()->values(),
'Failed asserting that collections are not equal.'
'Failed asserting that collections are not equal.',
);
}
}
26 changes: 6 additions & 20 deletions src/Asserts/DatabaseAsserts.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,30 @@ trait DatabaseAsserts
{
/**
* Assert that the database has the given table.
*
* @param string $table
* @return void
*/
protected function assertDatabaseHasTable(string $table)
protected function assertDatabaseHasTable(string $table): void
{
$this->assertTrue(
Schema::hasTable($table),
"Failed asserting that database has table `{$table}`."
"Failed asserting that database has table `{$table}`.",
);
}

/**
* Assert that the database doesn't have the given table.
*
* @param string $table
* @return void
*/
protected function assertDatabaseMissingTable(string $table)
protected function assertDatabaseMissingTable(string $table): void
{
$this->assertFalse(
Schema::hasTable($table),
"Failed asserting that database missing table `{$table}`."
"Failed asserting that database missing table `{$table}`.",
);
}

/**
* Assert that the database has all the given rows.
*
* @param string $table
* @param array $rows
* @return $this
*/
protected function assertDatabaseHasMany(string $table, array $rows)
protected function assertDatabaseHasMany(string $table, array $rows): self
{
foreach ($rows as $row) {
$this->assertDatabaseHas($table, $row);
Expand All @@ -52,12 +42,8 @@ protected function assertDatabaseHasMany(string $table, array $rows)

/**
* Assert that the database doesn't have all the given rows.
*
* @param string $table
* @param array $rows
* @return $this
*/
protected function assertDatabaseMissingMany(string $table, array $rows)
protected function assertDatabaseMissingMany(string $table, array $rows): self
{
foreach ($rows as $row) {
$this->assertDatabaseMissing($table, $row);
Expand Down
Loading

0 comments on commit ec3c413

Please sign in to comment.