ImportLoggerTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 80
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 2

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A it_should_be_instantiatable() 0 5 1
A make_instance() 0 3 1
A test_log_error() 0 6 1
A test_log_success() 0 6 1
A test_log_information() 0 6 1
A test_merge() 0 25 1
A test_save() 0 3 1
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() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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() );
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...
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