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

CommandLoaderTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testHas() 0 5 1
A testGet() 0 7 1
A testGet_failure() 0 5 1
A testGetNames() 0 7 1
1
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
/**
3
 * Tests for the changelogger CommandLoader 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\AddCommand;
12
use Automattic\Jetpack\Changelogger\Console\CommandLoader;
13
use Automattic\Jetpack\Changelogger\Tests\TestCase;
14
use Symfony\Component\Console\Exception\CommandNotFoundException;
15
use Symfony\Component\Console\Output\BufferedOutput;
16
17
/**
18
 * Tests for the changelogger CommandLoader class.
19
 *
20
 * @covers \Automattic\Jetpack\Changelogger\Console\CommandLoader
21
 */
22
class CommandLoaderTest extends TestCase {
23
	use \Yoast\PHPUnitPolyfills\Polyfills\ExpectException;
24
25
	/**
26
	 * Test `has()`.
27
	 */
28
	public function testHas() {
29
		$loader = new CommandLoader();
30
		$this->assertTrue( $loader->has( 'add' ) );
31
		$this->assertFalse( $loader->has( 'doesnotexist' ) );
32
	}
33
34
	/**
35
	 * Test `get()`.
36
	 */
37
	public function testGet() {
38
		$out = new BufferedOutput();
39
		Config::setOutput( $out );
40
41
		$loader = new CommandLoader();
42
		$this->assertInstanceOf( AddCommand::class, $loader->get( 'add' ) );
43
	}
44
45
	/**
46
	 * Test `get()` when passed an unrecognized command.
47
	 */
48
	public function testGet_failure() {
49
		$loader = new CommandLoader();
50
		$this->expectException( CommandNotFoundException::class );
51
		$loader->get( 'doesnotexist' );
52
	}
53
54
	/**
55
	 * Test `getNames()`.
56
	 */
57
	public function testGetNames() {
58
		$loader = new CommandLoader();
59
		$this->assertSame(
60
			array( 'add' ),
61
			$loader->getNames()
62
		);
63
	}
64
65
}
66