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

@ -31,6 +31,23 @@ use Symfony\Component\Console\Tester\CommandTester;
abstract class CommandTestCase extends TestCase
{
/**
* @var bool
*/
protected $commandIsInteractive = true;
/**
* Set a command to be non-interactive for testing purposes.
*
* @return $this
*/
public function withoutInteraction()
{
$this->commandIsInteractive = false;
return $this;
}
/**
* Return the display from running a command.
*
@ -48,6 +65,8 @@ abstract class CommandTestCase extends TestCase
$response = new CommandTester($command);
$response->setInputs($inputs);
$opts = array_merge($opts, ['interactive' => $this->commandIsInteractive]);
$response->execute($args, $opts);
return $response->getDisplay();

View file

@ -0,0 +1,296 @@
<?php
/*
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Tests\Unit\Commands\Environment;
use Mockery as m;
use Tests\Unit\Commands\CommandTestCase;
use Illuminate\Contracts\Config\Repository;
use Pterodactyl\Console\Commands\Environment\EmailSettingsCommand;
class EmailSettingsCommandTest extends CommandTestCase
{
/**
* @var \Pterodactyl\Console\Commands\Environment\EmailSettingsCommand|\Mockery\Mock
*/
protected $command;
/**
* @var \Illuminate\Contracts\Config\Repository|\Mockery\Mock
*/
protected $config;
/**
* Setup tests.
*/
public function setUp()
{
parent::setUp();
$this->config = m::mock(Repository::class);
$this->command = m::mock(EmailSettingsCommand::class . '[call, writeToEnvironment]', [$this->config]);
$this->command->setLaravel($this->app);
}
/**
* Test selection of the SMTP driver with no options passed.
*/
public function testSmtpDriverSelection()
{
$data = [
'MAIL_DRIVER' => 'smtp',
'MAIL_HOST' => 'mail.test.com',
'MAIL_PORT' => '567',
'MAIL_USERNAME' => 'username',
'MAIL_PASSWORD' => 'password',
'MAIL_FROM' => 'mail@from.com',
'MAIL_FROM_NAME' => 'MailName',
'MAIL_ENCRYPTION' => 'tls',
];
$this->setupCoreFunctions($data);
$display = $this->runCommand($this->command, [], array_values($data));
$this->assertNotEmpty($display);
$this->assertContains('Updating stored environment configuration file.', $display);
}
/**
* Test that the command can run when all variables are passed in as options.
*/
public function testSmtpDriverSelectionWithOptionsPassed()
{
$data = [
'MAIL_DRIVER' => 'smtp',
'MAIL_HOST' => 'mail.test.com',
'MAIL_PORT' => '567',
'MAIL_USERNAME' => 'username',
'MAIL_PASSWORD' => 'password',
'MAIL_FROM' => 'mail@from.com',
'MAIL_FROM_NAME' => 'MailName',
'MAIL_ENCRYPTION' => 'tls',
];
$this->setupCoreFunctions($data);
$display = $this->withoutInteraction()->runCommand($this->command, [
'--driver' => $data['MAIL_DRIVER'],
'--email' => $data['MAIL_FROM'],
'--from' => $data['MAIL_FROM_NAME'],
'--encryption' => $data['MAIL_ENCRYPTION'],
'--host' => $data['MAIL_HOST'],
'--port' => $data['MAIL_PORT'],
'--username' => $data['MAIL_USERNAME'],
'--password' => $data['MAIL_PASSWORD'],
]);
$this->assertNotEmpty($display);
$this->assertContains('Updating stored environment configuration file.', $display);
}
/**
* Test selection of PHP mail() as the driver.
*/
public function testPHPMailDriverSelection()
{
$data = [
'MAIL_DRIVER' => 'mail',
'MAIL_FROM' => 'mail@from.com',
'MAIL_FROM_NAME' => 'MailName',
'MAIL_ENCRYPTION' => 'tls',
];
$this->setupCoreFunctions($data);
// The driver flag is passed because there seems to be some issue with the command tester
// when using a choice() method when two keys start with the same letters.
//
// In this case, mail and mailgun.
unset($data['MAIL_DRIVER']);
$display = $this->runCommand($this->command, ['--driver' => 'mail'], array_values($data));
$this->assertNotEmpty($display);
$this->assertContains('Updating stored environment configuration file.', $display);
}
/**
* Test selection of the Mailgun driver with no options passed.
*/
public function testMailgunDriverSelection()
{
$data = [
'MAIL_DRIVER' => 'mailgun',
'MAILGUN_DOMAIN' => 'domain.com',
'MAILGUN_KEY' => '123456',
'MAIL_FROM' => 'mail@from.com',
'MAIL_FROM_NAME' => 'MailName',
'MAIL_ENCRYPTION' => 'tls',
];
$this->setupCoreFunctions($data);
$display = $this->runCommand($this->command, [], array_values($data));
$this->assertNotEmpty($display);
$this->assertContains('Updating stored environment configuration file.', $display);
}
/**
* Test mailgun driver selection when variables are passed as options.
*/
public function testMailgunDriverSelectionWithOptionsPassed()
{
$data = [
'MAIL_DRIVER' => 'mailgun',
'MAILGUN_DOMAIN' => 'domain.com',
'MAILGUN_KEY' => '123456',
'MAIL_FROM' => 'mail@from.com',
'MAIL_FROM_NAME' => 'MailName',
'MAIL_ENCRYPTION' => 'tls',
];
$this->setupCoreFunctions($data);
$display = $this->withoutInteraction()->runCommand($this->command, [
'--driver' => $data['MAIL_DRIVER'],
'--email' => $data['MAIL_FROM'],
'--from' => $data['MAIL_FROM_NAME'],
'--encryption' => $data['MAIL_ENCRYPTION'],
'--host' => $data['MAILGUN_DOMAIN'],
'--password' => $data['MAILGUN_KEY'],
]);
$this->assertNotEmpty($display);
$this->assertContains('Updating stored environment configuration file.', $display);
}
/**
* Test selection of the Mandrill driver with no options passed.
*/
public function testMandrillDriverSelection()
{
$data = [
'MAIL_DRIVER' => 'mandrill',
'MANDRILL_SECRET' => '123456',
'MAIL_FROM' => 'mail@from.com',
'MAIL_FROM_NAME' => 'MailName',
'MAIL_ENCRYPTION' => 'tls',
];
$this->setupCoreFunctions($data);
$display = $this->runCommand($this->command, [], array_values($data));
$this->assertNotEmpty($display);
$this->assertContains('Updating stored environment configuration file.', $display);
}
/**
* Test mandrill driver selection when variables are passed as options.
*/
public function testMandrillDriverSelectionWithOptionsPassed()
{
$data = [
'MAIL_DRIVER' => 'mandrill',
'MANDRILL_SECRET' => '123456',
'MAIL_FROM' => 'mail@from.com',
'MAIL_FROM_NAME' => 'MailName',
'MAIL_ENCRYPTION' => 'tls',
];
$this->setupCoreFunctions($data);
$display = $this->withoutInteraction()->runCommand($this->command, [
'--driver' => $data['MAIL_DRIVER'],
'--email' => $data['MAIL_FROM'],
'--from' => $data['MAIL_FROM_NAME'],
'--encryption' => $data['MAIL_ENCRYPTION'],
'--password' => $data['MANDRILL_SECRET'],
]);
$this->assertNotEmpty($display);
$this->assertContains('Updating stored environment configuration file.', $display);
}
/**
* Test selection of the Postmark driver with no options passed.
*/
public function testPostmarkDriverSelection()
{
$data = [
'MAIL_DRIVER' => 'smtp',
'MAIL_HOST' => 'smtp.postmarkapp.com',
'MAIL_PORT' => '587',
'MAIL_USERNAME' => '123456',
'MAIL_PASSWORD' => '123456',
'MAIL_FROM' => 'mail@from.com',
'MAIL_FROM_NAME' => 'MailName',
'MAIL_ENCRYPTION' => 'tls',
];
$this->setupCoreFunctions($data);
$display = $this->runCommand($this->command, [], [
'postmark', '123456', $data['MAIL_FROM'], $data['MAIL_FROM_NAME'], $data['MAIL_ENCRYPTION'],
]);
$this->assertNotEmpty($display);
$this->assertContains('Updating stored environment configuration file.', $display);
}
/**
* Test postmark driver selection when variables are passed as options.
*/
public function testPostmarkDriverSelectionWithOptionsPassed()
{
$data = [
'MAIL_DRIVER' => 'smtp',
'MAIL_HOST' => 'smtp.postmarkapp.com',
'MAIL_PORT' => '587',
'MAIL_USERNAME' => '123456',
'MAIL_PASSWORD' => '123456',
'MAIL_FROM' => 'mail@from.com',
'MAIL_FROM_NAME' => 'MailName',
'MAIL_ENCRYPTION' => 'tls',
];
$this->setupCoreFunctions($data);
$display = $this->withoutInteraction()->runCommand($this->command, [
'--driver' => 'postmark',
'--email' => $data['MAIL_FROM'],
'--from' => $data['MAIL_FROM_NAME'],
'--encryption' => $data['MAIL_ENCRYPTION'],
'--username' => $data['MAIL_USERNAME'],
]);
$this->assertNotEmpty($display);
$this->assertContains('Updating stored environment configuration file.', $display);
}
/**
* Setup the core functions that are repeated across all of these tests.
*
* @param array $data
*/
private function setupCoreFunctions(array $data)
{
$this->config->shouldReceive('get')->withAnyArgs()->zeroOrMoreTimes()->andReturnNull();
$this->command->shouldReceive('writeToEnvironment')->with($data)->once()->andReturnNull();
$this->command->shouldReceive('call')->with('config:cache')->once()->andReturnNull();
}
}

View file

@ -25,14 +25,13 @@
namespace Tests\Unit\Commands\Location;
use Mockery as m;
use Tests\TestCase;
use Pterodactyl\Models\Location;
use Symfony\Component\Console\Tester\CommandTester;
use Tests\Unit\Commands\CommandTestCase;
use Pterodactyl\Services\Locations\LocationDeletionService;
use Pterodactyl\Console\Commands\Location\DeleteLocationCommand;
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
class DeleteLocationCommandTest extends TestCase
class DeleteLocationCommandTest extends CommandTestCase
{
/**
* @var \Pterodactyl\Console\Commands\Location\DeleteLocationCommand
@ -40,12 +39,12 @@ class DeleteLocationCommandTest extends TestCase
protected $command;
/**
* @var \Pterodactyl\Services\Locations\LocationDeletionService
* @var \Pterodactyl\Services\Locations\LocationDeletionService|\Mockery\Mock
*/
protected $deletionService;
/**
* @var \Pterodactyl\Contracts\Repository\LocationRepositoryInterface
* @var \Pterodactyl\Contracts\Repository\LocationRepositoryInterface|\Mockery\Mock
*/
protected $repository;
@ -76,11 +75,8 @@ class DeleteLocationCommandTest extends TestCase
$this->repository->shouldReceive('all')->withNoArgs()->once()->andReturn($locations);
$this->deletionService->shouldReceive('handle')->with($location2->id)->once()->andReturnNull();
$response = new CommandTester($this->command);
$response->setInputs([$location2->short]);
$response->execute([]);
$display = $this->runCommand($this->command, [], [$location2->short]);
$display = $response->getDisplay();
$this->assertNotEmpty($display);
$this->assertContains(trans('command/messages.location.deleted'), $display);
}
@ -98,12 +94,10 @@ class DeleteLocationCommandTest extends TestCase
$this->repository->shouldReceive('all')->withNoArgs()->once()->andReturn($locations);
$this->deletionService->shouldReceive('handle')->with($location2->id)->once()->andReturnNull();
$response = new CommandTester($this->command);
$response->execute([
$display = $this->withoutInteraction()->runCommand($this->command, [
'--short' => $location2->short,
]);
$display = $response->getDisplay();
$this->assertNotEmpty($display);
$this->assertContains(trans('command/messages.location.deleted'), $display);
}
@ -121,11 +115,8 @@ class DeleteLocationCommandTest extends TestCase
$this->repository->shouldReceive('all')->withNoArgs()->once()->andReturn($locations);
$this->deletionService->shouldReceive('handle')->with($location2->id)->once()->andReturnNull();
$response = new CommandTester($this->command);
$response->setInputs(['123_not_exist', 'another_not_exist', $location2->short]);
$response->execute([]);
$display = $this->runCommand($this->command, [], ['123_not_exist', 'another_not_exist', $location2->short]);
$display = $response->getDisplay();
$this->assertNotEmpty($display);
$this->assertContains(trans('command/messages.location.no_location_found'), $display);
$this->assertContains(trans('command/messages.location.deleted'), $display);
@ -144,10 +135,8 @@ class DeleteLocationCommandTest extends TestCase
$this->repository->shouldReceive('all')->withNoArgs()->once()->andReturn($locations);
$this->deletionService->shouldNotReceive('handle');
$response = new CommandTester($this->command);
$response->execute(['--short' => 'randomTestString'], ['interactive' => false]);
$display = $this->withoutInteraction()->runCommand($this->command, ['--short' => 'randomTestString']);
$display = $response->getDisplay();
$this->assertNotEmpty($display);
$this->assertContains(trans('command/messages.location.no_location_found'), $display);
}

View file

@ -25,13 +25,12 @@
namespace Tests\Unit\Commands\Location;
use Mockery as m;
use Tests\TestCase;
use Pterodactyl\Models\Location;
use Symfony\Component\Console\Tester\CommandTester;
use Tests\Unit\Commands\CommandTestCase;
use Pterodactyl\Services\Locations\LocationCreationService;
use Pterodactyl\Console\Commands\Location\MakeLocationCommand;
class MakeLocationCommandTest extends TestCase
class MakeLocationCommandTest extends CommandTestCase
{
/**
* @var \Pterodactyl\Console\Commands\Location\MakeLocationCommand
@ -39,7 +38,7 @@ class MakeLocationCommandTest extends TestCase
protected $command;
/**
* @var \Pterodactyl\Services\Locations\LocationCreationService
* @var \Pterodactyl\Services\Locations\LocationCreationService|\Mockery\Mock
*/
protected $creationService;
@ -68,11 +67,8 @@ class MakeLocationCommandTest extends TestCase
'long' => $location->long,
])->once()->andReturn($location);
$response = new CommandTester($this->command);
$response->setInputs([$location->short, $location->long]);
$response->execute([]);
$display = $this->runCommand($this->command, [], [$location->short, $location->long]);
$display = $response->getDisplay();
$this->assertNotEmpty($display);
$this->assertContains(trans('command/messages.location.created', [
'name' => $location->short,
@ -92,13 +88,11 @@ class MakeLocationCommandTest extends TestCase
'long' => $location->long,
])->once()->andReturn($location);
$response = new CommandTester($this->command);
$response->execute([
$display = $this->withoutInteraction()->runCommand($this->command, [
'--short' => $location->short,
'--long' => $location->long,
]);
$display = $response->getDisplay();
$this->assertNotEmpty($display);
$this->assertContains(trans('command/messages.location.created', [
'name' => $location->short,

View file

@ -26,16 +26,15 @@ namespace Tests\Unit\Commands\Maintenance;
use Mockery as m;
use Carbon\Carbon;
use Tests\TestCase;
use Tests\Unit\Commands\CommandTestCase;
use Illuminate\Contracts\Filesystem\Factory;
use Illuminate\Contracts\Filesystem\Filesystem;
use Symfony\Component\Console\Tester\CommandTester;
use Pterodactyl\Console\Commands\Maintenance\CleanServiceBackupFilesCommand;
class CleanServiceBackupFilesCommandTest extends TestCase
class CleanServiceBackupFilesCommandTest extends CommandTestCase
{
/**
* @var \Carbon\Carbon
* @var \Carbon\Carbon|\Mockery\Mock
*/
protected $carbon;
@ -45,12 +44,12 @@ class CleanServiceBackupFilesCommandTest extends TestCase
protected $command;
/**
* @var \Illuminate\Contracts\Filesystem\Filesystem
* @var \Illuminate\Contracts\Filesystem\Filesystem|\Mockery\Mock
*/
protected $disk;
/**
* @var \Illuminate\Contracts\Filesystem\Factory
* @var \Illuminate\Contracts\Filesystem\Factory|\Mockery\Mock
*/
protected $filesystem;
@ -82,10 +81,8 @@ class CleanServiceBackupFilesCommandTest extends TestCase
$this->carbon->shouldReceive('diffInMinutes')->with(null)->once()->andReturn(10);
$this->disk->shouldReceive('delete')->with('testfile.txt')->once()->andReturnNull();
$response = new CommandTester($this->command);
$response->execute([]);
$display = $this->runCommand($this->command);
$display = $response->getDisplay();
$this->assertNotEmpty($display);
$this->assertContains(trans('command/messages.maintenance.deleting_service_backup', ['file' => 'testfile.txt']), $display);
}
@ -101,10 +98,8 @@ class CleanServiceBackupFilesCommandTest extends TestCase
$this->carbon->shouldReceive('now')->withNoArgs()->once()->andReturnNull();
$this->carbon->shouldReceive('diffInMinutes')->with(null)->once()->andReturn(2);
$response = new CommandTester($this->command);
$response->execute([]);
$display = $this->runCommand($this->command);
$display = $response->getDisplay();
$this->assertEmpty($display);
}
}

View file

@ -83,6 +83,7 @@ class ProcessRunnableCommandTest extends CommandTestCase
$this->processScheduleService->shouldReceive('handle')->with($schedule)->once()->andReturnNull();
$display = $this->runCommand($this->command);
$this->assertNotEmpty($display);
$this->assertContains(trans('command/messages.schedule.output_line', [
'schedule' => $schedule->name,
@ -103,6 +104,7 @@ class ProcessRunnableCommandTest extends CommandTestCase
$this->repository->shouldReceive('getSchedulesToProcess')->with('00:00:00')->once()->andReturn(collect([$schedule]));
$display = $this->runCommand($this->command);
$this->assertNotEmpty($display);
$this->assertNotContains(trans('command/messages.schedule.output_line', [
'schedule' => $schedule->name,
@ -122,6 +124,7 @@ class ProcessRunnableCommandTest extends CommandTestCase
$this->repository->shouldReceive('getSchedulesToProcess')->with('00:00:00')->once()->andReturn(collect([$schedule]));
$display = $this->runCommand($this->command);
$this->assertNotEmpty($display);
$this->assertNotContains(trans('command/messages.schedule.output_line', [
'schedule' => $schedule->name,

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);
}

View file

@ -25,13 +25,12 @@
namespace Tests\Unit\Commands\User;
use Mockery as m;
use Tests\TestCase;
use Pterodactyl\Models\User;
use Symfony\Component\Console\Tester\CommandTester;
use Tests\Unit\Commands\CommandTestCase;
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
use Pterodactyl\Console\Commands\User\DisableTwoFactorCommand;
class DisableTwoFactorCommandTest extends TestCase
class DisableTwoFactorCommandTest extends CommandTestCase
{
/**
* @var \Pterodactyl\Console\Commands\User\DisableTwoFactorCommand
@ -39,10 +38,13 @@ class DisableTwoFactorCommandTest extends TestCase
protected $command;
/**
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface|\Mockery\Mock
*/
protected $repository;
/**
* Setup tests.
*/
public function setUp()
{
parent::setUp();
@ -68,11 +70,8 @@ class DisableTwoFactorCommandTest extends TestCase
'totp_secret' => null,
])->once()->andReturnNull();
$response = new CommandTester($this->command);
$response->setInputs([$user->email]);
$response->execute([]);
$display = $this->runCommand($this->command, [], [$user->email]);
$display = $response->getDisplay();
$this->assertNotEmpty($display);
$this->assertContains(trans('command/messages.user.2fa_disabled', ['email' => $user->email]), $display);
}
@ -92,12 +91,7 @@ class DisableTwoFactorCommandTest extends TestCase
'totp_secret' => null,
])->once()->andReturnNull();
$response = new CommandTester($this->command);
$response->execute([
'--email' => $user->email,
]);
$display = $response->getDisplay();
$display = $this->withoutInteraction()->runCommand($this->command, ['--email' => $user->email]);
$this->assertNotEmpty($display);
$this->assertContains(trans('command/messages.user.2fa_disabled', ['email' => $user->email]), $display);
}

View file

@ -25,13 +25,12 @@
namespace Tests\Unit\Commands\User;
use Mockery as m;
use Tests\TestCase;
use Pterodactyl\Models\User;
use Tests\Unit\Commands\CommandTestCase;
use Pterodactyl\Services\Users\UserCreationService;
use Symfony\Component\Console\Tester\CommandTester;
use Pterodactyl\Console\Commands\User\MakeUserCommand;
class MakeUserCommandTest extends TestCase
class MakeUserCommandTest extends CommandTestCase
{
/**
* @var \Pterodactyl\Console\Commands\User\MakeUserCommand
@ -72,13 +71,10 @@ class MakeUserCommandTest extends TestCase
'root_admin' => $user->root_admin,
])->once()->andReturn($user);
$response = new CommandTester($this->command);
$response->setInputs([
$display = $this->runCommand($this->command, [], [
'yes', $user->email, $user->username, $user->name_first, $user->name_last, 'Password123',
]);
$response->execute([]);
$display = $response->getDisplay();
$this->assertNotEmpty($display);
$this->assertContains(trans('command/messages.user.ask_password_help'), $display);
$this->assertContains($user->uuid, $display);
@ -104,13 +100,10 @@ class MakeUserCommandTest extends TestCase
'root_admin' => $user->root_admin,
])->once()->andReturn($user);
$response = new CommandTester($this->command);
$response->setInputs([
$display = $this->runCommand($this->command, ['--no-password' => true], [
'yes', $user->email, $user->username, $user->name_first, $user->name_last,
]);
$response->execute(['--no-password' => true]);
$display = $response->getDisplay();
$this->assertNotEmpty($display);
$this->assertNotContains(trans('command/messages.user.ask_password_help'), $display);
}
@ -131,8 +124,7 @@ class MakeUserCommandTest extends TestCase
'root_admin' => $user->root_admin,
])->once()->andReturn($user);
$response = new CommandTester($this->command);
$response->execute([
$display = $this->withoutInteraction()->runCommand($this->command, [
'--email' => $user->email,
'--username' => $user->username,
'--name-first' => $user->name_first,
@ -141,7 +133,6 @@ class MakeUserCommandTest extends TestCase
'--admin' => 0,
]);
$display = $response->getDisplay();
$this->assertNotEmpty($display);
$this->assertNotContains(trans('command/messages.user.ask_password_help'), $display);
$this->assertContains($user->uuid, $display);