ImportersBaseFactoryTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A test_make_will_throw_if_the_extending_class_is_not_defining_its_type() 0 5 1
A test_will_return_base_importer_if_map_empty() 0 6 1
A test_will_return_base_importer_if_map_emptied() 0 10 1
A test_will_return_filtered_importer() 0 12 1
A test_will_return_base_importer_if_slug_missing_from_map() 0 8 1
A test_will_return_the_mapped_importer() 0 8 1
A setUp() 0 4 1
1
<?php
2
3
namespace lloc\Msls\ContentImport\Importers;
4
5
use lloc\Msls\ContentImport\ImportCoordinates;
6
use lloc\Msls\ContentImport\Importers\PostMeta\Duplicating;
7
8
class BadImportersFactory extends ImportersBaseFactory {
9
}
10
11
class DummyImportersBaseFactoryOne extends ImportersBaseFactory {
12
13
	const TYPE = 'one';
14
15
	protected $importers_map = [];
16
}
17
18
class DummyImportersBaseFactoryTwo extends ImportersBaseFactory {
19
20
	const TYPE = 'two';
21
22
	protected $importers_map = [
23
		'some-option' => Duplicating::class,
24
	];
25
}
26
27
class ImportersBaseFactoryTest extends \Msls_UnitTestCase {
28
29
	/**
30
	 * @var ImportCoordinates
31
	 */
32
	protected $import_coordinates;
33
34
	/**
35
	 * Test make will throw if the extending class is not defining its type
36
	 */
37
	public function test_make_will_throw_if_the_extending_class_is_not_defining_its_type() {
38
		$this->expectException( \RuntimeException::class );
39
40
		BadImportersFactory::instance()->make( $this->import_coordinates->reveal() );
0 ignored issues
show
Bug introduced by
The method reveal() does not seem to exist on object<lloc\Msls\ContentImport\ImportCoordinates>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
	}
42
43
	/**
44
	 * Test will return BaseImporter if map empty
45
	 */
46
	public function test_will_return_base_importer_if_map_empty() {
47
		$this->assertInstanceOf(
48
			BaseImporter::class,
49
			DummyImportersBaseFactoryOne::instance()->make( $this->import_coordinates->reveal() )
0 ignored issues
show
Bug introduced by
The method reveal() does not seem to exist on object<lloc\Msls\ContentImport\ImportCoordinates>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
50
		);
51
	}
52
53
	/**
54
	 * Test will return BaseImporter if map emptied
55
	 */
56
	public function test_will_return_base_importer_if_map_emptied() {
57
		add_filter( 'msls_content_import_two_importers_map', function () {
58
			return [];
59
		} );
60
61
		$this->assertInstanceOf(
62
			BaseImporter::class,
63
			DummyImportersBaseFactoryTwo::instance()->make( $this->import_coordinates->reveal() )
0 ignored issues
show
Bug introduced by
The method reveal() does not seem to exist on object<lloc\Msls\ContentImport\ImportCoordinates>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
64
		);
65
	}
66
67
	/**
68
	 * Test will return filtered importer
69
	 */
70
	public function test_will_return_filtered_importer() {
71
		$importer = $this->prophesize( Importer::class )->reveal();
72
73
		add_filter( 'msls_content_import_one_importer', function () use ( $importer ) {
74
			return $importer;
75
		} );
76
77
		$this->assertSame(
78
			$importer,
79
			DummyImportersBaseFactoryOne::instance()->make( $this->import_coordinates->reveal() )
0 ignored issues
show
Bug introduced by
The method reveal() does not seem to exist on object<lloc\Msls\ContentImport\ImportCoordinates>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
80
		);
81
	}
82
83
	/**
84
	 * Test will return base importer if slug missing from map
85
	 */
86
	public function test_will_return_base_importer_if_slug_missing_from_map() {
87
		$this->import_coordinates->get_importer_for( 'two' )->willReturn( 'not-there' );
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->import_coordinate...get_importer_for('two') (of type string|null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
88
89
		$this->assertInstanceOf(
90
			BaseImporter::class,
91
			DummyImportersBaseFactoryTwo::instance()->make( $this->import_coordinates->reveal() )
0 ignored issues
show
Bug introduced by
The method reveal() does not seem to exist on object<lloc\Msls\ContentImport\ImportCoordinates>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
92
		);
93
	}
94
95
	/**
96
	 * Test will return the mapped importer
97
	 */
98
	public function test_will_return_the_mapped_importer() {
99
		$this->import_coordinates->get_importer_for( 'two' )->willReturn( 'some-option' );
0 ignored issues
show
Bug introduced by
The method willReturn cannot be called on $this->import_coordinate...get_importer_for('two') (of type string|null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
100
101
		$this->assertInstanceOf(
102
			Duplicating::class,
103
			DummyImportersBaseFactoryTwo::instance()->make( $this->import_coordinates->reveal() )
0 ignored issues
show
Bug introduced by
The method reveal() does not seem to exist on object<lloc\Msls\ContentImport\ImportCoordinates>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
104
		);
105
	}
106
107
	public function setUp() {
108
		parent::setUp();
109
		$this->import_coordinates = $this->prophesize( ImportCoordinates::class );
110
	}
111
}
112