|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace lloc\Msls\ContentImport; |
|
4
|
|
|
|
|
5
|
|
|
use lloc\Msls\ContentImport\ImportLogger as Logger; |
|
6
|
|
|
|
|
7
|
|
|
class ImportLoggerTest extends \Msls_UnitTestCase { |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @var \lloc\Msls\ContentImport\ImportCoordinates |
|
11
|
|
|
*/ |
|
12
|
|
|
public $import_coordinates; |
|
13
|
|
|
|
|
14
|
|
|
function setUp() { |
|
|
|
|
|
|
15
|
|
|
parent::setUp(); |
|
16
|
|
|
$this->import_coordinates = $this->prophesize( ImportCoordinates::class ); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @test |
|
21
|
|
|
* it should be instantiatable |
|
22
|
|
|
*/ |
|
23
|
|
|
public function it_should_be_instantiatable() { |
|
24
|
|
|
$sut = $this->make_instance(); |
|
25
|
|
|
|
|
26
|
|
|
$this->assertInstanceOf( Logger::class, $sut ); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @return Logger |
|
31
|
|
|
*/ |
|
32
|
|
|
private function make_instance() { |
|
33
|
|
|
return new Logger( $this->import_coordinates->reveal() ); |
|
|
|
|
|
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function test_log_error() { |
|
37
|
|
|
$obj = $this->make_instance(); |
|
38
|
|
|
$obj->log_error( 'some/path/foo', 'foo-bar' ); |
|
39
|
|
|
|
|
40
|
|
|
$this->assertEquals( 'foo-bar', $obj->get_error( 'some/path/foo' ) ); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function test_log_success() { |
|
44
|
|
|
$obj = $this->make_instance(); |
|
45
|
|
|
$obj->log_success( 'some/path/foo', 'foo-bar' ); |
|
46
|
|
|
|
|
47
|
|
|
$this->assertEquals( 'foo-bar', $obj->get_success( 'some/path/foo' ) ); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function test_log_information() { |
|
51
|
|
|
$obj = $this->make_instance(); |
|
52
|
|
|
$obj->log_information( 'foo', 'bar' ); |
|
53
|
|
|
|
|
54
|
|
|
$this->assertEquals( 'bar', $obj->get_information( 'foo' ) ); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function test_merge() { |
|
58
|
|
|
$obj_1 = $this->make_instance(); |
|
59
|
|
|
$obj_2 = $this->make_instance(); |
|
60
|
|
|
|
|
61
|
|
|
$obj_1->log_information( 'foo', 'bar' ); |
|
62
|
|
|
$obj_1->log_error( 'foo/one/two', [ 'one' => '23' ] ); |
|
63
|
|
|
$obj_1->log_error( 'bar/one/two', [ 'one' => '23' ] ); |
|
64
|
|
|
$obj_1->log_success( 'foo/one/two', [ 'one' => '23' ] ); |
|
65
|
|
|
$obj_1->log_success( 'bar/one/two', [ 'one' => '23' ] ); |
|
66
|
|
|
|
|
67
|
|
|
$obj_2->log_information( 'bar', 'foo' ); |
|
68
|
|
|
$obj_2->log_error( 'foo/one/two', [ 'two' => '89' ] ); |
|
69
|
|
|
$obj_2->log_error( 'bar/one/two', [ 'two' => '89' ] ); |
|
70
|
|
|
$obj_2->log_success( 'foo/one/two', [ 'two' => '89' ] ); |
|
71
|
|
|
$obj_2->log_success( 'bar/one/two', [ 'two' => '89' ] ); |
|
72
|
|
|
|
|
73
|
|
|
$obj_1->merge( $obj_2 ); |
|
74
|
|
|
|
|
75
|
|
|
$this->assertEquals( 'foo', $obj_1->get_information( 'bar' ) ); |
|
76
|
|
|
$this->assertEquals( 'bar', $obj_1->get_information( 'foo' ) ); |
|
77
|
|
|
$this->assertEquals( [ 'one' => '23', 'two' => '89' ], $obj_1->get_error( 'foo/one/two' ) ); |
|
78
|
|
|
$this->assertEquals( [ 'one' => '23', 'two' => '89' ], $obj_1->get_error( 'bar/one/two' ) ); |
|
79
|
|
|
$this->assertEquals( [ 'one' => '23', 'two' => '89' ], $obj_1->get_success( 'foo/one/two' ) ); |
|
80
|
|
|
$this->assertEquals( [ 'one' => '23', 'two' => '89' ], $obj_1->get_success( 'bar/one/two' ) ); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function test_save() { |
|
84
|
|
|
$this->markTestSkipped( 'Skipped as how and where to log is still undecided' ); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.