Completed
Pull Request — master (#513)
by Helpful
04:05
created

DeploynautLogFileTest::testLogFileNameSanitised()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 10
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
class DeploynautLogFileTest extends SapphireTest {
1 ignored issue
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
3
4
	protected $basePath;
5
6
	public function setUp() {
7
		parent::setUp();
8
9
		$this->basePath = '/tmp/deploynautlogstest';
10
		mkdir($this->basePath);
11
	}
12
13
	public function testLogFileNameSanitised() {
14
		$log = new DeploynautLogFile('SomeSortOf Filename (UAT).log', $this->basePath);
15
		$this->assertEquals($log->getSanitisedLogFilePath(), $this->basePath . '/somesortof-filename-uat.log');
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DeploynautLogFileTest>.

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...
16
17
		$log = new DeploynautLogFile('..SomeSortOf Filename_(UAT).log', $this->basePath);
18
		$this->assertEquals($log->getSanitisedLogFilePath(), $this->basePath . '/somesortof-filename-uat.log');
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DeploynautLogFileTest>.

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...
19
20
		$log = new DeploynautLogFile('test-project.1823.log', $this->basePath);
21
		$this->assertEquals($log->getSanitisedLogFilePath(), $this->basePath . '/test-project.1823.log');
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DeploynautLogFileTest>.

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...
22
	}
23
24
	public function testUnsanitisedLogFileFallback() {
25
		touch($this->basePath . '/' . 'SomeSortOf Filename (UAT).log');
26
27
		$log = new DeploynautLogFile('SomeSortOf Filename (UAT).log', $this->basePath);
28
		$this->assertEquals($log->getLogFilePath(), $this->basePath . '/SomeSortOf Filename (UAT).log');
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DeploynautLogFileTest>.

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...
29
		$this->assertTrue($log->exists());
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DeploynautLogFileTest>.

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...
30
31
		// writing into the logs still works, and we reference the old file path still.
32
		$log->write('Some test content');
33
		$this->assertEquals($log->getLogFilePath(), $this->basePath . '/SomeSortOf Filename (UAT).log');
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DeploynautLogFileTest>.

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
		$this->assertContains('Some test content', $log->content());
35
	}
36
37
	public function testLogWriting() {
38
		$log = new DeploynautLogFile('SomeSortOf Filename (UAT).log', $this->basePath);
39
		$this->assertFalse($log->exists());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DeploynautLogFileTest>.

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...
40
		$this->assertNull($log->getLogFilePath());
0 ignored issues
show
Bug introduced by
The method assertNull() does not seem to exist on object<DeploynautLogFileTest>.

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
		$log->write('This is some content');
43
		$this->assertTrue($log->exists());
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DeploynautLogFileTest>.

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...
44
		$this->assertEquals($this->basePath . '/somesortof-filename-uat.log', $log->getLogFilePath());
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DeploynautLogFileTest>.

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...
45
		$this->assertContains('This is some content', $log->content());
46
	}
47
48
	public function testLogDoesntExistMessage() {
49
		$log = new DeploynautLogFile('SomeSortOf Filename (UAT).log', $this->basePath);
50
		$this->assertNull($log->getLogFilePath());
0 ignored issues
show
Bug introduced by
The method assertNull() does not seem to exist on object<DeploynautLogFileTest>.

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...
51
		$this->assertEquals('Log has not been created yet.', $log->content());
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DeploynautLogFileTest>.

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...
52
	}
53
54
	public function tearDown() {
55
		parent::tearDown();
56
57
		exec(sprintf('rm -rf %s', $this->basePath));
58
	}
59
60
}
61