Merge pull request #11 from bessl/patch-2
[gitphp.git] / test / git / blob / BlobTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
 * Blob test class
 *
 * @author Christopher Han <xiphux@gmail.com>
 * @copyright Copyright (c) 2012 Christopher Han
 * @package GitPHP
 * @subpackage Test\Git\Blob
 */
class GitPHP_BlobTest extends PHPUnit_Framework_TestCase
{
        public function testLoad()
        {
                $strategymock = $this->getMock('GitPHP_BlobLoadStrategy_Interface');
                $strategymock->expects($this->once())->method('Load')->with($this->isInstanceOf('GitPHP_Blob'))->will($this->returnValue("data line 1\ndata line 2"));
 
                $projectmock = $this->getMockBuilder('GitPHP_Project')->disableOriginalConstructor()->getMock();
                
                $blob = new GitPHP_Blob($projectmock, '1234567890abcdef1234567890ABCDEF12345678', $strategymock);
                $this->assertEquals("data line 1\ndata line 2", $blob->GetData());
                $this->assertEquals("data line 1\ndata line 2", $blob->GetData());      //cached
                $this->assertEquals(array('data line 1', 'data line 2'), $blob->GetData(true));
        }
 
        public function testSize()
        {
                $strategymock = $this->getMock('GitPHP_BlobLoadStrategy_Interface');
                $strategymock->expects($this->once())->method('Load')->with($this->isInstanceOf('GitPHP_Blob'))->will($this->returnValue("data line 1\ndata line 2"));
 
                $projectmock = $this->getMockBuilder('GitPHP_Project')->disableOriginalConstructor()->getMock();
                
                $blob = new GitPHP_Blob($projectmock, '1234567890abcdef1234567890ABCDEF12345678', $strategymock);
                $this->assertEquals(23, $blob->GetSize());
                $this->assertEquals(23, $blob->GetSize());      //cached
 
                $strategymock = $this->getMock('GitPHP_BlobLoadStrategy_Interface');
                $blob = new GitPHP_Blob($projectmock, '1234567890abcdef1234567890ABCDEF12345678', $strategymock);
                $blob->SetSize(100);
                $this->assertEquals(100, $blob->GetSize());
        }
 
        public function testBinary()
        {
                $strategymock = $this->getMock('GitPHP_BlobLoadStrategy_Interface');
                $strategymock->expects($this->once())->method('Load')->with($this->isInstanceOf('GitPHP_Blob'))->will($this->returnValue("data line 1\ndata line 2"));
 
                $projectmock = $this->getMockBuilder('GitPHP_Project')->disableOriginalConstructor()->getMock();
                
                $blob = new GitPHP_Blob($projectmock, '1234567890abcdef1234567890ABCDEF12345678', $strategymock);
                $this->assertFalse($blob->IsBinary());
                $this->assertFalse($blob->IsBinary());  // cached
 
                $strategymock = $this->getMock('GitPHP_BlobLoadStrategy_Interface');
                $strategymock->expects($this->once())->method('Load')->with($this->isInstanceOf('GitPHP_Blob'))->will($this->returnValue("binary data" . chr(0) . "binary data"));
 
                $projectmock = $this->getMockBuilder('GitPHP_Project')->disableOriginalConstructor()->getMock();
                
                $blob = new GitPHP_Blob($projectmock, '1234567890abcdef1234567890ABCDEF12345678', $strategymock);
                $this->assertTrue($blob->IsBinary());
                $this->assertTrue($blob->IsBinary());   // cached
        }
 
        public function testObserver()
        {
                $projectmock = $this->getMockBuilder('GitPHP_Project')->disableOriginalConstructor()->getMock();
                $blob = new GitPHP_Blob($projectmock, '1234567890abcdef1234567890ABCDEF12345678', $this->getMock('GitPHP_BlobLoadStrategy_Interface'));
 
                $observermock = $this->getMock('GitPHP_Observer_Interface');
                $matcher = $this->once();
                $observermock->expects($matcher)->method('ObjectChanged')->with($this->isInstanceOf('GitPHP_Blob'), $this->equalTo(GitPHP_Observer_Interface::CacheableDataChange));
 
                $blob->AddObserver($observermock);
                $data = $blob->GetData();
                $data = $blob->GetData();       //cached
 
                $this->assertEquals(1, $matcher->getInvocationCount());
        }
}
 
comments