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

ApplicationTest::testDoRun()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 21
rs 9.584
c 0
b 0
f 0
1
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
/**
3
 * Tests for the changelogger Application class.
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\Command\Command;
14
use Symfony\Component\Console\Tester\ApplicationTester;
15
use Wikimedia\TestingAccessWrapper;
16
17
/**
18
 * Tests for the changelogger Application class.
19
 *
20
 * @covers \Automattic\Jetpack\Changelogger\Console\Application
21
 */
22
class ApplicationTest extends TestCase {
23
	use \Yoast\PHPUnitPolyfills\Polyfills\AssertionRenames;
24
	use \Yoast\PHPUnitPolyfills\Polyfills\AssertIsType;
25
26
	/**
27
	 * Test the application.
28
	 */
29
	public function testBasics() {
30
		$app = new Application();
31
32
		$this->assertSame( 'Jetpack Changelogger', $app->getName() );
33
		$this->assertSame( Application::VERSION, $app->getVersion() );
34
35
		$app->setAutoExit( false );
36
		$tester = new ApplicationTester( $app );
37
		$tester->run( array( 'command' => 'list' ) );
38
		$output = $tester->getDisplay();
39
		$this->assertMatchesRegularExpression( '/Available commands:/', $output );
40
		$this->assertMatchesRegularExpression( '/add\s*Adds a changelog entry file/', $output );
41
	}
42
43
	/**
44
	 * Test the stuff done by doRun().
45
	 */
46
	public function testDoRun() {
47
		$app = new Application();
48
		$app->setAutoExit( false );
49
50
		$mock = $this->getMockBuilder( Command::class )
51
			->setConstructorArgs( array( 'testDoRun' ) )
52
			->setMethods( array( 'execute' ) )
53
			->getMock();
54
		$mock->expects( $this->once() )->method( 'execute' )->willReturnCallback(
55
			function ( $input, $output ) {
56
				$this->assertSame( $output, TestingAccessWrapper::newFromClass( Config::class )->out );
57
				$this->assertTrue( $output->getFormatter()->hasStyle( 'warning' ) );
58
				return 42;
59
			}
60
		);
61
		$app->add( $mock );
62
63
		$tester = new ApplicationTester( $app );
64
		$code   = $tester->run( array( 'command' => 'testDoRun' ), array( 'decorated' ) );
65
		$this->assertSame( 42, $code );
66
	}
67
68
}
69