|
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() ); |
|
|
|
|
|
|
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() ) |
|
|
|
|
|
|
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() ) |
|
|
|
|
|
|
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() ) |
|
|
|
|
|
|
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' ); |
|
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
$this->assertInstanceOf( |
|
90
|
|
|
BaseImporter::class, |
|
91
|
|
|
DummyImportersBaseFactoryTwo::instance()->make( $this->import_coordinates->reveal() ) |
|
|
|
|
|
|
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' ); |
|
|
|
|
|
|
100
|
|
|
|
|
101
|
|
|
$this->assertInstanceOf( |
|
102
|
|
|
Duplicating::class, |
|
103
|
|
|
DummyImportersBaseFactoryTwo::instance()->make( $this->import_coordinates->reveal() ) |
|
|
|
|
|
|
104
|
|
|
); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function setUp() { |
|
108
|
|
|
parent::setUp(); |
|
109
|
|
|
$this->import_coordinates = $this->prophesize( ImportCoordinates::class ); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
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.