Files
pterodactyl-panel/tests/Unit/Commands/CommandTestCase.php
T

60 lines
1.5 KiB
PHP
Raw Normal View History

<?php
2017-09-25 21:43:01 -05:00
/**
* Pterodactyl - Panel
2017-01-24 17:57:08 -05:00
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
2017-09-25 21:43:01 -05:00
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
2016-12-14 21:56:25 +00:00
2017-09-19 22:10:14 -05:00
namespace Tests\Unit\Commands;
2017-09-19 22:10:14 -05:00
use Tests\TestCase;
use Illuminate\Console\Command;
2017-09-19 22:10:14 -05:00
use Illuminate\Contracts\Foundation\Application;
use Symfony\Component\Console\Tester\CommandTester;
2017-09-19 22:10:14 -05:00
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;
}
/**
2017-09-19 22:10:14 -05:00
* Return the display from running a command.
*
2017-09-19 22:10:14 -05:00
* @param \Illuminate\Console\Command $command
* @param array $args
* @param array $inputs
* @param array $opts
* @return string
*/
2017-09-19 22:10:14 -05:00
protected function runCommand(Command $command, array $args = [], array $inputs = [], array $opts = [])
{
2017-09-19 22:10:14 -05:00
if (! $command->getLaravel() instanceof Application) {
$command->setLaravel($this->app);
}
2017-09-19 22:10:14 -05:00
$response = new CommandTester($command);
$response->setInputs($inputs);
$opts = array_merge($opts, ['interactive' => $this->commandIsInteractive]);
2017-09-19 22:10:14 -05:00
$response->execute($args, $opts);
2017-09-19 22:10:14 -05:00
return $response->getDisplay();
}
}