Completed
Push — add/changelog-tooling ( 7f5585...86359e )
by
unknown
58:45 queued 48:46
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;
9
10
use Automattic\Jetpack\Changelogger\AddCommand;
11
use Automattic\Jetpack\Changelogger\CommandLoader;
12
use Automattic\Jetpack\Changelogger\Config;
13
use Symfony\Component\Console\Exception\CommandNotFoundException;
14
use Symfony\Component\Console\Output\BufferedOutput;
15
16
/**
17
 * Tests for the changelogger CommandLoader class.
18
 *
19
 * @covers \Automattic\Jetpack\Changelogger\CommandLoader
20
 */
21
class CommandLoaderTest extends TestCase {
22
	use \Yoast\PHPUnitPolyfills\Polyfills\ExpectException;
23
24
	/**
25
	 * Test `has()`.
26
	 */
27
	public function testHas() {
28
		$loader = new CommandLoader();
29
		$this->assertTrue( $loader->has( 'add' ) );
30
		$this->assertFalse( $loader->has( 'doesnotexist' ) );
31
	}
32
33
	/**
34
	 * Test `get()`.
35
	 */
36
	public function testGet() {
37
		$out = new BufferedOutput();
38
		Config::setOutput( $out );
39
40
		$loader = new CommandLoader();
41
		$this->assertInstanceOf( AddCommand::class, $loader->get( 'add' ) );
42
	}
43
44
	/**
45
	 * Test `get()` when passed an unrecognized command.
46
	 */
47
	public function testGet_failure() {
48
		$loader = new CommandLoader();
49
		$this->expectException( CommandNotFoundException::class );
50
		$loader->get( 'doesnotexist' );
51
	}
52
53
	/**
54
	 * Test `getNames()`.
55
	 */
56
	public function testGetNames() {
57
		$loader = new CommandLoader();
58
		$this->assertSame(
59
			array( 'add', 'validate' ),
60
			$loader->getNames()
61
		);
62
	}
63
64
}
65