Passed
Branch master (1e39e8)
by Caen
03:01
created

FileCacheServiceUnixsumMethodTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 71
rs 10
c 0
b 0
f 0
wmc 11
1
<?php
2
3
namespace Hyde\Framework\Testing\Unit;
4
5
use Hyde\Framework\Services\FileCacheService as Service;
6
use Hyde\Testing\TestCase;
7
8
class FileCacheServiceUnixsumMethodTest extends TestCase
9
{
10
    public function test_method_returns_string()
11
    {
12
        $this->assertIsString(Service::unixsum('foo'));
13
    }
14
15
    public function test_method_returns_string_with_length_of_32()
16
    {
17
        $this->assertEquals(32, strlen(Service::unixsum('foo')));
18
    }
19
20
    public function test_method_returns_string_matching_expected_format()
21
    {
22
        $this->assertMatchesRegularExpression('/^[a-f0-9]{32}$/', Service::unixsum('foo'));
23
    }
24
25
    public function test_method_returns_same_value_for_same_string_using_normal_method()
26
    {
27
        $this->assertEquals(md5('foo'), Service::unixsum('foo'));
28
    }
29
30
    public function test_method_returns_different_value_for_different_string()
31
    {
32
        $this->assertNotEquals(Service::unixsum('foo'), Service::unixsum('bar'));
33
    }
34
35
    public function test_function_is_case_sensitive()
36
    {
37
        $this->assertNotEquals(Service::unixsum('foo'), Service::unixsum('FOO'));
38
    }
39
40
    public function test_function_is_space_sensitive()
41
    {
42
        $this->assertNotEquals(Service::unixsum(' foo '), Service::unixsum('foo'));
43
    }
44
45
    public function test_method_returns_same_value_regardless_of_end_of_line_sequence()
46
    {
47
        $this->assertEquals(Service::unixsum('foo'), Service::unixsum('foo'));
48
        $this->assertEquals(Service::unixsum("foo\n"), Service::unixsum("foo\n"));
49
        $this->assertEquals(Service::unixsum("foo\n"), Service::unixsum("foo\r"));
50
        $this->assertEquals(Service::unixsum("foo\n"), Service::unixsum("foo\r\n"));
51
    }
52
53
    public function test_method_returns_same_value_for_string_with_mixed_end_of_line_sequences()
54
    {
55
        $this->assertEquals(Service::unixsum("foo\nbar\r\nbaz\r\n"),
56
            Service::unixsum("foo\nbar\nbaz\n"));
57
    }
58
59
    public function test_method_returns_same_value_when_loaded_from_file()
60
    {
61
        $string = "foo\nbar\r\nbaz\r\n";
62
        $file = tempnam(sys_get_temp_dir(), 'foo');
63
        file_put_contents($file, $string);
64
65
        $this->assertEquals(Service::unixsum($string), Service::unixsum(file_get_contents($file)));
66
67
        unlink($file);
68
    }
69
70
    public function test_method_returns_same_value_when_loaded_from_file_using_shorthand()
71
    {
72
        $string = "foo\nbar\r\nbaz\r\n";
73
        $file = tempnam(sys_get_temp_dir(), 'foo');
74
        file_put_contents($file, $string);
75
76
        $this->assertEquals(Service::unixsum($string), Service::unixsumFile($file));
77
78
        unlink($file);
79
    }
80
}
81