Update command unit tests to use helper functions

This commit is contained in:
Dane Everitt 2017-09-22 00:30:09 -05:00
parent 8df5d5beaf
commit 6e5b0b8027
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
13 changed files with 615 additions and 100 deletions

View file

@ -25,15 +25,14 @@
namespace Tests\Unit\Commands\User;
use Mockery as m;
use Tests\TestCase;
use Pterodactyl\Models\User;
use Tests\Unit\Commands\CommandTestCase;
use Tests\Assertions\CommandAssertionsTrait;
use Pterodactyl\Services\Users\UserDeletionService;
use Symfony\Component\Console\Tester\CommandTester;
use Pterodactyl\Console\Commands\User\DeleteUserCommand;
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
class DeleteUserCommandTest extends TestCase
class DeleteUserCommandTest extends CommandTestCase
{
use CommandAssertionsTrait;
@ -43,12 +42,12 @@ class DeleteUserCommandTest extends TestCase
protected $command;
/**
* @var \Pterodactyl\Services\Users\UserDeletionService
* @var \Pterodactyl\Services\Users\UserDeletionService|\Mockery\Mock
*/
protected $deletionService;
/**
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface|\Mockery\Mock
*/
protected $repository;
@ -80,11 +79,8 @@ class DeleteUserCommandTest extends TestCase
->shouldReceive('all')->withNoArgs()->once()->andReturn($users);
$this->deletionService->shouldReceive('handle')->with($user1->id)->once()->andReturnNull();
$response = new CommandTester($this->command);
$response->setInputs([$user1->username, $user1->id, 'yes']);
$response->execute([]);
$display = $this->runCommand($this->command, [], [$user1->username, $user1->id, 'yes']);
$display = $response->getDisplay();
$this->assertNotEmpty($display);
$this->assertTableContains($user1->id, $display);
$this->assertTableContains($user1->email, $display);
@ -107,11 +103,8 @@ class DeleteUserCommandTest extends TestCase
->shouldReceive('all')->withNoArgs()->once()->andReturn($users);
$this->deletionService->shouldReceive('handle')->with($user1->id)->once()->andReturnNull();
$response = new CommandTester($this->command);
$response->setInputs(['noResults', $user1->username, $user1->id, 'yes']);
$response->execute([]);
$display = $this->runCommand($this->command, [], ['noResults', $user1->username, $user1->id, 'yes']);
$display = $response->getDisplay();
$this->assertNotEmpty($display);
$this->assertContains(trans('command/messages.user.no_users_found'), $display);
$this->assertTableContains($user1->id, $display);
@ -133,11 +126,8 @@ class DeleteUserCommandTest extends TestCase
->shouldReceive('all')->withNoArgs()->twice()->andReturn($users);
$this->deletionService->shouldReceive('handle')->with($user1->id)->once()->andReturnNull();
$response = new CommandTester($this->command);
$response->setInputs([$user1->username, 0, $user1->username, $user1->id, 'yes']);
$response->execute([]);
$display = $this->runCommand($this->command, [], [$user1->username, 0, $user1->username, $user1->id, 'yes']);
$display = $response->getDisplay();
$this->assertNotEmpty($display);
$this->assertContains(trans('command/messages.user.select_search_user'), $display);
$this->assertTableContains($user1->id, $display);
@ -159,11 +149,8 @@ class DeleteUserCommandTest extends TestCase
->shouldReceive('all')->withNoArgs()->once()->andReturn($users);
$this->deletionService->shouldNotReceive('handle');
$response = new CommandTester($this->command);
$response->setInputs([$user1->username, $user1->id, 'no']);
$response->execute([]);
$display = $this->runCommand($this->command, [], [$user1->username, $user1->id, 'no']);
$display = $response->getDisplay();
$this->assertNotEmpty($display);
$this->assertNotContains(trans('command/messages.user.deleted'), $display);
}
@ -181,10 +168,8 @@ class DeleteUserCommandTest extends TestCase
->shouldReceive('all')->withNoArgs()->once()->andReturn($users);
$this->deletionService->shouldReceive('handle')->with($user1)->once()->andReturnNull();
$response = new CommandTester($this->command);
$response->execute(['--user' => $user1->username], ['interactive' => false]);
$display = $this->withoutInteraction()->runCommand($this->command, ['--user' => $user1->username]);
$display = $response->getDisplay();
$this->assertNotEmpty($display);
$this->assertContains(trans('command/messages.user.deleted'), $display);
}
@ -203,10 +188,8 @@ class DeleteUserCommandTest extends TestCase
->shouldReceive('all')->withNoArgs()->once()->andReturn($users);
$this->deletionService->shouldNotReceive('handle');
$response = new CommandTester($this->command);
$response->execute(['--user' => $user1->username], ['interactive' => false]);
$display = $this->withoutInteraction()->runCommand($this->command, ['--user' => $user1->username]);
$display = $response->getDisplay();
$this->assertNotEmpty($display);
$this->assertContains(trans('command/messages.user.multiple_found'), $display);
}
@ -219,10 +202,8 @@ class DeleteUserCommandTest extends TestCase
$this->repository->shouldReceive('search')->with(123456)->once()->andReturnSelf()
->shouldReceive('all')->withNoArgs()->once()->andReturn([]);
$response = new CommandTester($this->command);
$response->execute(['--user' => 123456], ['interactive' => false]);
$display = $this->withoutInteraction()->runCommand($this->command, ['--user' => 123456]);
$display = $response->getDisplay();
$this->assertNotEmpty($display);
$this->assertContains(trans('command/messages.user.no_users_found'), $display);
}