DynamicModelSeederTaskTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 74
Duplicated Lines 21.62 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 16
loc 74
c 0
b 0
f 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 7 7 1
A _createShellMock() 9 9 1
A testGetModelName() 0 5 1
A testFieldFormatters() 0 5 1
A testGetSeedingMode() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
App::uses('DynamicModelSeederTask', 'FakeSeeder.Console/Command/Task');
4
App::uses('ConsoleOutput', 'Console');
5
App::uses('ConsoleInput', 'Console');
6
7
/**
8
 * A testable implementation of DynamicModelSeederTask
9
 */
10
class TestDynamicModelSeederTask extends DynamicModelSeederTask {
11
12
	/**
13
	 * Set a specific ModelName to be executed
14
	 *
15
	 * @var array
16
	 */
17
	public $args = array(0 => 'ModelName');
18
19
	/**
20
	 * Set some test dummy formatters
21
	 *
22
	 * @var array
23
	 */
24
	protected $_fieldFormatters = array('foo' => 'bar');
25
26
}
27
28
/**
29
 * DynamicModelSeederTask Test
30
 *
31
 * @coversDefaultClass DynamicModelSeederTask
32
 */
33
class DynamicModelSeederTaskTest extends CakeTestCase {
34
35
	/**
36
	 * The task under test
37
	 *
38
	 * @var null|TestDynamicModelSeederTask
39
	 */
40
	protected $_task = null;
41
42
	/**
43
	 * Setup the shell under test
44
	 *
45
	 * @return void
46
	 */
47 View Code Duplication
	public function setUp() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
		parent::setUp();
49
50
		$this->_createShellMock(
51
			array('in', 'out', 'hr', 'createFile', 'error', 'err', '_stop', '_showInfo', 'dispatchShell', '_getSeederTasks')
52
		);
53
	}
54
55
	/**
56
	 * Creates a shell mock
57
	 *
58
	 * @param array $methods A list of methods to mock.
59
	 * @param string $className Optional name of the seeder shell class to mock.
60
	 * @return void
61
	 */
62 View Code Duplication
	protected function _createShellMock($methods, $className = 'TestDynamicModelSeederTask') {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
		$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
64
		$in = $this->getMock('ConsoleInput', array(), array(), '', false);
65
		$this->_task = $this->getMock(
66
			$className,
67
			$methods,
68
			array($out, $out, $in)
69
		);
70
	}
71
72
	/**
73
	 * Tests the _getModelName method
74
	 *
75
	 * @return void
76
	 * @covers ::getModelName
77
	 */
78
	public function testGetModelName() {
79
		$result = $this->_task->getModelName();
80
		$expected = 'ModelName';
81
		$this->assertEquals($expected, $result);
82
	}
83
84
	/**
85
	 * Tests the _fieldFormatters method
86
	 *
87
	 * @return void
88
	 * @covers ::fieldFormatters
89
	 */
90
	public function testFieldFormatters() {
91
		$result = $this->_task->fieldFormatters();
92
		$expected = array('foo' => 'bar');
93
		$this->assertEquals($expected, $result);
94
	}
95
96
	/**
97
	 * Tests the _getSeedingMode method
98
	 *
99
	 * @return void
100
	 * @covers ::getSeedingMode
101
	 */
102
	public function testGetSeedingMode() {
103
		$result = $this->_task->getSeedingMode();
104
		$this->assertEquals('auto', $result);
105
	}
106
}