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()); }
/** * Gets a blob * * @param string $hash blob hash * @return GitPHP_Blob blob object */ public function GetBlob($hash) { if (empty($hash)) { return null; } if (preg_match('/^[0-9A-Fa-f]{4,39}$/', $hash) && !$this->compat) { $fullHash = $this->project->ExpandHash($hash); if ($fullHash == $hash) { throw new GitPHP_InvalidHashException($hash); } $hash = $fullHash; } if (!preg_match('/^[0-9A-Fa-f]{40}$/', $hash)) { return null; } $key = GitPHP_Blob::CacheKey($this->project->GetProject(), $hash); $blob = null; if ($this->memoryCache) { $blob = $this->memoryCache->Get($key); } if (!$blob) { if ($this->cache) { $blob = $this->cache->Get($key); } $strategy = null; if ($this->compat) { $strategy = new GitPHP_BlobLoad_Git($this->exe); } else { $strategy = new GitPHP_BlobLoad_Raw($this->objectLoader, $this->exe); } if ($blob) { $blob->SetProject($this->project); $blob->SetStrategy($strategy); } else { $blob = new GitPHP_Blob($this->project, $hash, $strategy); } $blob->AddObserver($this); if ($this->memoryCache) { $this->memoryCache->Set($key, $blob); } } return $blob; }