Пример #1
0
 /**
  * Execution test.
  */
 public function testExecute()
 {
     $repoUrl = 'git@github.com:amaxlab/git-web-hook-test.git';
     $json = '{"ref":"refs/heads/master","repository":{"name":"git-web-hook-test","url":"' . $repoUrl . '"},"commits":[{"id":"06f9ce8478e0973ec17b6253000a1f1f140c322b","message":"test commit1","timestamp":"2014-12-25T15:20:16+06:00","author":{"name":"Egor Zyuskin","email":"*****@*****.**"}}]}';
     $options = array('sendEmails' => false, 'sendEmailAuthor' => false, 'mailRecipients' => array(), 'allowedAuthors' => '*', 'allowedHosts' => '*');
     $repoDir = $this->makeTempDir('repo');
     $logFile = $this->makeFile($this->baseTempDir, 'hook.log');
     $this->assertTrue(chdir($repoDir), sprintf('Can\'t change directory to %s', $repoDir));
     $result = shell_exec('git init');
     $this->assertTrue(is_dir($repoDir . '/.git/'), sprintf('Can\'t init git repository in %s : %s', $repoDir, $result), true);
     $this->assertEmpty(shell_exec('git remote add origin ' . $repoUrl), 'Can\'t add origin');
     $logger = new Logger('git-web-hook');
     $logger->pushHandler(new StreamHandler($logFile, Logger::WARNING));
     $requestMock = $this->getMock('Symfony\\Component\\HttpFoundation\\Request', null, array($_GET, $_POST, array(), $_COOKIE, $_FILES, $_SERVER, $json));
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Request', $requestMock, 'Error during create mock Request');
     $hook = new Hook($repoDir, $options, $logger, $requestMock);
     $hook->addRepository($repoUrl)->addBranch('master', array('git status', 'git pull origin master'));
     $hook->execute();
     $content = file_get_contents($logFile);
     $this->assertEmpty($content, sprintf('Log file is not empty: %s', $content));
 }
<?php

/**
 * Created by PhpStorm.
 * User: zyuskin_en
 * Date: 31.12.14
 * Time: 1:06
 */
include __DIR__ . '/vendor/autoload.php';
use AmaxLab\GitWebHook\Hook;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
$logger = new Logger('git-web-hook');
$logger->pushHandler(new StreamHandler(__DIR__ . DIRECTORY_SEPARATOR . 'log' . DIRECTORY_SEPARATOR . 'hook.log', Logger::WARNING));
// or you can write logs to /var/log or somewhere else
$hook = new Hook(__DIR__, array(), $logger);
$hook->loadConfig(__DIR__ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.yml');
// you can copy config.yml.dist to config.yml and edit it
$hook->execute();