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

ApplicationTest::testBasics()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

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