Completed
Push — add/changelog-tooling ( 7f5585...86359e )
by
unknown
58:45 queued 48:46
created

CommandTestCase::getTester()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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