Esempio n. 1
0
 /**
  * Load config test.
  */
 public function testLoadConfig()
 {
     $logFile = $this->makeFile($this->baseTempDir, 'hook.log');
     $logger = new Logger('git-web-hook');
     $logger->pushHandler(new StreamHandler($logFile, Logger::WARNING));
     $hook = new Hook(__DIR__, array(), $logger);
     $reposDir = $this->makeTempDir('repos.d');
     $testFile = $this->makeFile($reposDir, 'test3.yml');
     $this->generateRepoConfigFile($testFile, 3);
     $mainConfigFile = $this->makeFile($this->baseTempDir, 'main_config.yml');
     file_put_contents($mainConfigFile, $this->configTemplates->render('config1.php', array('reposDir' => $reposDir)));
     $hook->loadConfig($mainConfigFile);
     $options = $hook->getOptions();
     $this->assertFalse($options['sendEmails'], 'Wrong loaded configuration option sendEmails ');
     $this->assertFalse($options['sendEmailAuthor'], 'Wrong loaded configuration option sendEmailAuthor');
     $repository = $hook->getRepository('git@github.com:amaxlab/git-web-hook-test.git');
     $this->assertNotNull($repository, 'Repository was not loaded through config.yml ');
     $this->assertInstanceOf('AmaxLab\\GitWebHook\\Repository', $repository, 'It is not a repository object');
     $masterBranch = $repository->getBranch('master');
     $productionBranch = $repository->getBranch('production');
     $this->assertInstanceOf('AmaxLab\\GitWebHook\\Branch', $masterBranch, 'There is not a branch master');
     $this->assertInstanceOf('AmaxLab\\GitWebHook\\Branch', $productionBranch, 'There is not a branch master');
     $this->assertContains('*****@*****.**', $masterBranch->getOptions()['mailRecipients']);
     $this->assertContains('192.168.0.2', Request::getTrustedProxies(), 'There is error in configuring trusted proxies');
     $this->assertContains('192.168.0.3', Request::getTrustedProxies(), 'There is error in configuring trusted proxies');
     $this->assertNotContains('192.168.0.4', Request::getTrustedProxies(), 'There is error in configuring trusted proxies');
     $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();