/** * Gets a single tag * * @param string $tag tag to find * @param string $hash hash of tag, if known * @return GitPHP_Tag tag object */ public function GetTag($tag, $hash = '') { if (empty($tag)) { return null; } $key = GitPHP_Tag::CacheKey($this->project->GetProject(), $tag); $tagObj = null; if ($this->memoryCache) { $tagObj = $this->memoryCache->Get($key); } if (!$tagObj) { if ($this->cache) { $tagObj = $this->cache->Get($key); } $strategy = null; if ($this->compat) { $strategy = new GitPHP_TagLoad_Git($this->exe); } else { $strategy = new GitPHP_TagLoad_Raw($this->objectLoader); } if ($tagObj) { $tagObj->SetProject($this->project); $tagObj->SetStrategy($strategy); } else { $tagObj = new GitPHP_Tag($this->project, $tag, $strategy, $hash); } $tagObj->AddObserver($this); if ($this->memoryCache) { $this->memoryCache->Set($key, $tagObj); } } return $tagObj; }
public function testObserver() { $projectmock = $this->getMockBuilder('GitPHP_Project')->disableOriginalConstructor()->getMock(); $tag = new GitPHP_Tag($projectmock, 'sometag', $this->getMock('GitPHP_TagLoadStrategy_Interface')); $observermock = $this->getMock('GitPHP_Observer_Interface'); $matcher = $this->once(); $observermock->expects($matcher)->method('ObjectChanged')->with($this->isInstanceOf('GitPHP_Tag'), $this->equalTo(GitPHP_Observer_Interface::CacheableDataChange)); $tag->AddObserver($observermock); $tagger = $tag->GetTagger(); $tagger = $tag->GetTagger(); //cached $this->assertEquals(1, $matcher->getInvocationCount()); }