コード例 #1
0
ファイル: MessageTest.php プロジェクト: NamelessCoder/gizzle
 /**
  * @return array
  */
 public function getToGitHubApiDataArrayTestValues()
 {
     $commit = new Commit();
     $commit->setId(321);
     $pullRequest = new PullRequest();
     $pullRequest->setId(456);
     $withCommit = new Message('Message');
     $withCommit->setCommit($commit);
     $withCommitAndPath = new Message('Message', '/path/to/file', 123);
     $withCommitAndPath->setCommit($commit);
     $withPullRequest = new Message('Message');
     $withPullRequest->setPullRequest($pullRequest);
     return array(array(new Message('Message'), array('body' => 'Message')), array(new Message('Message', '/path/to/file', 123), array('body' => 'Message')), array($withCommit, array('body' => 'Message')), array($withCommitAndPath, array('body' => 'Message', 'path' => '/path/to/file', 'position' => 123, 'commit_id' => 321)), array($withPullRequest, array('body' => 'Message', 'sha1' => 456)));
 }
コード例 #2
0
ファイル: Payload.php プロジェクト: NamelessCoder/gizzle
 /**
  * @return Commit
  */
 public function getHead()
 {
     if (TRUE === $this->repository instanceof Repository) {
         $this->head->setRepository($this->repository);
     }
     return $this->head;
 }
コード例 #3
0
 /**
  * @dataProvider getProcessTestValues
  * @param CommentPlugin $plugin
  * @param array $settings
  * @param array $errors
  * @param array $output
  * @param string|NULL $expectedMethod
  * @param string $expectedComment
  */
 public function testProcess(CommentPlugin $plugin, array $settings, array $errors, array $output, $expectedMethod, $expectedComment)
 {
     $payload = $this->getMockBuilder('NamelessCoder\\Gizzle\\Payload')->setMethods(array($expectedMethod))->disableOriginalConstructor()->getMock();
     $propertyReflection = new \ReflectionProperty($payload, 'response');
     $propertyReflection->setAccessible(TRUE);
     $propertyReflection->setValue($payload, new Response());
     $pullRequest = new PullRequest();
     $pullRequest->setId('pull-request-id');
     $commit = new Commit();
     $commit->setId('commit-id');
     $plugin->initialize($settings);
     $payload->setPullRequest($pullRequest);
     $payload->setHead($commit);
     if (0 < count($errors)) {
         $payload->getResponse()->setErrors($errors);
     }
     if (0 < count($output)) {
         $payload->getResponse()->addOutputFromPlugin($plugin, $output);
     }
     if ('dummy' !== $expectedMethod) {
         $payload->expects($this->once())->method($expectedMethod)->with($this->anything(), $expectedComment);
     }
     $plugin->process($payload);
 }
 public function testProcessRethrowsSoapFaultAsRuntimeException()
 {
     vfsStreamWrapper::register();
     vfsStreamWrapper::setRoot(new vfsStreamDirectory('temp', 0777));
     $settings = array(ExtensionRepositoryReleasePlugin::OPTION_DIRECTORY => vfsStream::url('temp'), ExtensionRepositoryReleasePlugin::OPTION_COMMENT => 'comment', ExtensionRepositoryReleasePlugin::OPTION_REMOVEBUILD => TRUE);
     $plugin = $this->getMock('NamelessCoder\\GizzleTYPO3Plugins\\GizzlePlugins\\ExtensionRepositoryReleasePlugin', array('validateCredentialsFile', 'getUploader', 'readUploadCredentials', 'getGitClonePlugin'));
     $payload = $this->getMock('NamelessCoder\\Gizzle\\Payload', array('getRepository', 'getHead', 'getResponse', 'getRef'), array(), '', FALSE);
     $repository = new Repository();
     $repository->setMasterBranch('master');
     $repository->setName('repository');
     $head = new Commit();
     $head->setId('123');
     $clone = $this->getMock('NamelessCoder\\GizzleGitPlugins\\GizzlePlugins\\ClonePlugin', array('initialize', 'process'));
     $clone->expects($this->once())->method('initialize')->with(array(ClonePlugin::OPTION_GITCOMMAND => ClonePlugin::DEFAULT_GITCOMMAND, ClonePlugin::OPTION_DIRECTORY => $settings[ExtensionRepositoryReleasePlugin::OPTION_DIRECTORY] . '/123/repository', ClonePlugin::OPTION_SINGLE => TRUE, ClonePlugin::OPTION_BRANCH => '1.1.1', ClonePlugin::OPTION_DEPTH => 1));
     $clone->expects($this->once())->method('process')->with($payload);
     $response = $this->getMock('NamelessCoder\\Gizzle\\Response', array('addOutputFromPlugin'));
     $response->expects($this->never())->method('addOutputFromPlugin');
     $uploader = $this->getMock('NamelessCoder\\TYPO3RepositoryClient\\Uploader', array('upload'));
     $uploader->expects($this->once())->method('upload')->with($settings[ExtensionRepositoryReleasePlugin::OPTION_DIRECTORY] . '/' . $head->getId() . '/' . $repository->getName(), 'username', 'password', $settings[ExtensionRepositoryReleasePlugin::OPTION_COMMENT])->willThrowException(new \SoapFault('test', 123));
     $payload->expects($this->any())->method('getRepository')->will($this->returnValue($repository));
     $payload->expects($this->any())->method('getResponse')->will($this->returnValue($response));
     $payload->expects($this->any())->method('getHead')->will($this->returnValue($head));
     $payload->expects($this->any())->method('getRef')->will($this->returnValue('refs/tags/1.1.1'));
     $plugin->expects($this->once())->method('getGitClonePlugin')->will($this->returnValue($clone));
     $plugin->expects($this->once())->method('validateCredentialsFile');
     $plugin->expects($this->once())->method('getUploader')->will($this->returnValue($uploader));
     $plugin->expects($this->once())->method('readUploadCredentials')->will($this->returnValue(array('username', 'password')));
     $plugin->initialize($settings);
     $this->setExpectedException('RuntimeException');
     $plugin->process($payload);
 }
コード例 #5
0
 /**
  * @param Payload $payload
  * @return boolean
  */
 protected function validateCodeStyleOfPhpFilesInCommits(Payload $payload)
 {
     $url = $payload->getPullRequest()->resolveApiUrl(PullRequest::API_URL_COMMITS);
     $response = $payload->getApi()->get($url);
     $commits = json_decode($response->getContent(), JSON_OBJECT_AS_ARRAY);
     $hasErrors = FALSE;
     foreach ($commits as $commitData) {
         $commitUrl = $commitData['url'];
         $commitResponse = $payload->getApi()->get($commitUrl);
         $commitData = json_decode($commitResponse->getContent(), JSON_OBJECT_AS_ARRAY);
         $commit = new Commit($commitData);
         $commit->setId($commitData['sha']);
         foreach ($commitData['files'] as $fileData) {
             $extension = pathinfo($fileData['filename'], PATHINFO_EXTENSION);
             if (self::PHP_EXTENSION === $extension) {
                 $result = $this->validateCodeStyleOfPhpFile($payload, $commit, $fileData['raw_url'], $fileData['filename']);
                 $hasErrors = TRUE !== $result || TRUE === $hasErrors;
             }
         }
     }
     return FALSE === $hasErrors;
 }
コード例 #6
0
ファイル: PayloadTest.php プロジェクト: NamelessCoder/gizzle
 /**
  * @return void
  */
 public function testGetHeadAssignsRepositoryToHead()
 {
     $payload = $this->getMockBuilder('NamelessCoder\\Gizzle\\Payload')->setMethods(array('getApi'))->setConstructorArgs(array('{}', ''))->getMock();
     $repository = new Repository();
     $repository->setId('test-repository');
     $payload->setRepository($repository);
     $head = new Commit();
     $head->setId('test-commit');
     $this->assertNull($head->getRepository());
     $payload->setHead($head);
     $this->assertSame($head, $payload->getHead());
     $this->assertSame($repository, $payload->getHead()->getRepository());
 }
コード例 #7
0
 /**
  * @param string $message
  * @param string|boolean $expected
  * @dataProvider getCommitMessageContainsValidPrefixTestValues
  */
 public function testCommitMessageContainsValidPrefix($message, $expected)
 {
     $plugin = new FormalitiesPlugin();
     $commit = new Commit();
     $commit->setMessage($message);
     $method = new \ReflectionMethod($plugin, 'commitMessageContainsValidPrefix');
     $method->setAccessible(TRUE);
     $result = $method->invokeArgs($plugin, array($commit));
     $this->assertEquals($expected, $result);
 }