Completed
Push — add/changelog-tooling ( 257a85 )
by
unknown
149:15 queued 138:48
created

CommandTestCase::getCommand()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
1
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
/**
3
 * Base test case for the changelogger tool commands.
4
 *
5
 * @package automattic/jetpack-changelogger
6
 */
7
8
namespace Automattic\Jetpack\Changelogger\Tests\Console;
9
10
use Automattic\Jetpack\Changelogger\Config;
11
use Automattic\Jetpack\Changelogger\Console\Application;
12
use Automattic\Jetpack\Changelogger\Tests\TestCase;
13
use Symfony\Component\Console\Output\BufferedOutput;
14
use Symfony\Component\Console\Tester\CommandTester;
15
16
/**
17
 * Base test case for the changelogger tool commands.
18
 */
19
class CommandTestCase extends TestCase {
20
21
	/**
22
	 * Get the command.
23
	 *
24
	 * @param string $name Command name.
25
	 * @return Command
26
	 */
27
	protected function getCommand( $name ) {
28
		// `$command->configure()` is called by `->__construct()`, which may
29
		// call Config, so we need Config to have an output set. Set one that
30
		// asserts that nothing is output, we don't need to test Config failure
31
		// cases here.
32
		$output = $this->getMockBuilder( BufferedOutput::class )
33
			->setMethods( array( 'doWrite' ) )
34
			->getMock();
35
		$output->expects( $this->never() )->method( 'doWrite' );
36
		Config::setOutput( $output );
37
38
		$app = new Application();
39
		return $app->find( $name );
40
	}
41
42
	/**
43
	 * Get a CommandTester.
44
	 *
45
	 * @param string $name Command name.
46
	 * @return CommandTester
47
	 */
48
	protected function getTester( $name ) {
49
		return new CommandTester( $this->getCommand( $name ) );
50
	}
51
52
}
53