/** * @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()); }
/** * Prepare testing data and returns it * * @return array */ protected function prepareFixtures() { /* @var $contributor User */ $contributor = $this->getModule('Yii2')->grabFixture('users', 'activeUser1'); /* @var $reviewer User */ $reviewer = $this->getModule('Yii2')->grabFixture('users', 'activeUser2'); // authorized user model $authModel = new Auth(['identityClass' => User::className(), 'identity' => $reviewer]); /* @var $project Project */ $project = $this->getModule('Yii2')->grabFixture('projects', 'gitProject'); /* @var $history BaseCommit[] */ $history = $project->getRepositoryObject()->getHistory(1, 0); $this->assertNotEmpty($history); $commit = $history[0]; $this->assertInstanceOf(BaseCommit::className(), $commit); return [$contributor, $reviewer, $authModel, $project, $commit]; }
/** * Test get project contributions array from date * * @return BaseCommit First commit from generator */ public function testGetProjectContributions() { /* @var $project Project */ $project = $this->getModule('Yii2')->grabFixture('projects', 'gitProject'); $dateFrom = new DateTime(); $dateFrom->setDate(2016, 1, 1); $dateFrom->setTime(0, 0, 0); $this->assertNotEmpty($this->projectApi->getProjectContributions($project, $dateFrom)); $this->assertContainsOnly(BaseCommit::className(), $this->projectApi->getProjectContributions($project, $dateFrom)); // check if not less than date from $firstCommit = null; foreach ($this->projectApi->getProjectContributions($project, $dateFrom) as $commit) { $this->assertGreaterThan($dateFrom->getTimestamp(), $commit->getDate()->getTimestamp()); if (is_null($firstCommit)) { $firstCommit = $commit; } } return $firstCommit; }
/** * Prepare testing data and returns it * * @param string $fileStatus Status wich will be set for file * * @return array */ protected function prepareFixtures($fileStatus) { /* @var $project Project */ $project = $this->getModule('Yii2')->grabFixture('projects', 'gitProject'); /* @var $history BaseCommit[] */ $history = $project->getRepositoryObject()->getHistory(100, 0); $this->assertNotEmpty($history); // search commit and file $commit = null; $file = null; foreach ($history as $searchCommit) { $this->assertInstanceOf(BaseCommit::className(), $searchCommit); foreach ($searchCommit->getChangedFiles() as $searchFile) { $commit = $searchCommit; $file = new File($searchFile->getPath(), $project->getRepositoryObject(), $fileStatus); break; } } return [$project, $commit, $file]; }