/** * Tests commit variables */ public function testCommitVariables() { $commit = $this->repository->getCommit($this->variables['diff']); $this->assertInstanceOf('DateTime', $commit->getDate()); /* @var $wrapper GitWrapper */ $wrapper = $this->repository->getWrapper(); $this->assertTrue($wrapper->checkIsSha1($commit->getId())); $this->assertNotEmpty($commit->contributorName); $this->assertNotEmpty($commit->contributorEmail); $this->assertNotEmpty($commit->message); $this->assertNotEmpty($commit->getParentsId()); foreach ($commit->getParentsId() as $parentId) { $this->assertTrue($wrapper->checkIsSha1($parentId)); } $this->assertNotEmpty($commit->getChangedFiles()); $this->assertContainsOnly(File::className(), $commit->getChangedFiles()); $lastFilePath = null; $lastFileStatus = null; foreach ($commit->getChangedFiles() as $item) { $this->assertInstanceOf(File::className(), $item); $this->assertInternalType('string', $item->getStatus()); $this->assertInternalType('string', $item->getPath()); $this->assertInternalType('string', $item->getPathname()); $lastFilePath = $item->getPathname(); $lastFileStatus = $item->getStatus(); } $this->assertEquals($commit->getFileStatus($lastFilePath), $lastFileStatus); $lastFile = $commit->getFileByPath($lastFilePath); $this->assertInstanceOf(File::className(), $lastFile); $this->assertEquals($lastFilePath, $lastFile->getPathname()); $this->assertEquals($lastFileStatus, $lastFile->getStatus()); return $commit; }
/** * @inheritdoc */ public function init() { if (!$this->project instanceof Project) { throw new InvalidParamException('Project variable must be an instance of ' . Project::className()); } if (!$this->repository instanceof BaseRepository) { throw new InvalidParamException('Repository variable must be an instance of ' . BaseRepository::className()); } if (!$this->commit instanceof BaseCommit) { throw new InvalidParamException('Commit variable must be an instance of ' . BaseCommit::className()); } if (!$this->file instanceof File) { throw new InvalidParamException('File variable must be an instance of ' . File::className()); } $this->id = $this->commit->getId() . md5($this->file->getPathname()); }
/** * Tests history getter for sepcified path */ public function testPathHistory() { $history = $this->repository->getHistory(2, 0, $this->variables['pathHistory']); $this->assertNotEmpty($history); $this->assertContainsOnlyInstancesOf(Commit::className(), $history); $this->assertCount(2, $history); foreach ($history as $commit) { /* @var $commit Commit */ $commit = $this->repository->getCommit($commit->getId()); $this->assertNotEmpty($commit->getChangedFiles()); $hasCurrentFile = false; foreach ($commit->getChangedFiles() as $file) { /* @var $file File */ $this->assertInstanceOf(File::className(), $file); if ($this->variables['pathHistory'] === $file->getPathname()) { $hasCurrentFile = true; } } $this->assertTrue($hasCurrentFile); } return $history; }