예제 #1
0
<?php

use nochso\Benchmark;
use nochso\Benchmark\Parameter;
use nochso\Benchmark\Report;
use nochso\Benchmark\Timer;
use nochso\Benchmark\Unit;
use nochso\Omni;
use nochso\Omni\Exec;
use nochso\Omni\Folder;
use nochso\Omni\Path;
require 'vendor/autoload.php';
$repos = ['aura/sql' => 'https://github.com/auraphp/Aura.Sql.git', 'doctrine/dbal' => 'https://github.com/doctrine/dbal.git', 'fzaninotto/faker' => 'https://github.com/fzaninotto/Faker.git', 'paris' => 'https://github.com/j4mie/paris.git', 'phpunit' => 'https://github.com/sebastianbergmann/phpunit.git', 'plates' => 'https://github.com/thephpleague/plates.git', 'slim' => 'https://github.com/slimphp/Slim.git', 'symfony/yaml' => 'https://github.com/symfony/yaml.git', 'twig' => 'https://github.com/twigphp/Twig.git'];
$tmpDir = Path::combine(sys_get_temp_dir(), 'phormat_benchmark');
Folder::ensure($tmpDir);
Timer::$defaultMinDuration = 1000;
$versions = ['phormat' => ['php', 'phormat', '-h'], 'php-cs-fixer' => ['php-cs-fixer', '--version'], 'phpfmt' => ['fmt.phar', '--version']];
foreach ($versions as $name => &$version) {
    $line = Exec::create()->run(...$version)->getOutput()[0];
    if (preg_match('/([0-9][0-9.-]+[0-9a-z-]+)/i', $line, $m)) {
        $version = $m[1];
    }
    $version = $name . ' ' . $version;
}
$report = new Report('Speed comparison of PHP source formatters', '', ['output_dir' => 'benchmark']);
$desc = 'Various open source projects are formatted with common settings.

Each repository is checked out `--hard` once before the benchmark is run.
`.php_cs` and `.php_cs_cache` files are removed to make php-cs-fixer comparable
with other formatters.
예제 #2
0
파일: FolderTest.php 프로젝트: nochso/omni
 public function testDelete_FailToDeleteRootFolder_MustThrow()
 {
     $root = vfsStream::setup('root', 0444);
     $folder = vfsStream::newDirectory('test', 0444)->at($root);
     $this->expectException('RuntimeException');
     Folder::delete($folder->url());
 }
예제 #3
0
 /**
  * @covers nochso\Omni\VcsVersionInfo::extractTag
  * @covers nochso\Omni\VcsVersionInfo::readMercurial
  */
 public function testMercurial()
 {
     if (!OS::hasBinary('hg') || getenv('TRAVIS')) {
         $this->markTestSkipped('hg (Mercurial) has to be available for this test.');
     }
     $repoDir = Path::combine(self::$base, 'hg');
     Folder::ensure($repoDir);
     // Set up a new repo with a single committed file
     Exec::create('hg')->run('init', $repoDir);
     // From now on prefix all 'hg' commands with repo and cwd path
     $hg = Exec::create('hg', '--repository', $repoDir, '--cwd', $repoDir);
     $fooPath = Path::combine($repoDir, 'foo.txt');
     touch($fooPath);
     $hg->run('add', $fooPath);
     $hg->run('commit', '-m init', '-u', 'Unit tester');
     $vcs = new VcsVersionInfo('name', null, $repoDir);
     $this->assertRegExp('/^[0-9a-f]+$/', $vcs->getVersion(), 'Version without a tag must be rev hash');
     file_put_contents($fooPath, 'throw dirt at tree');
     $vcs = new VcsVersionInfo('name', null, $repoDir);
     $this->assertRegExp('/^[0-9a-f]+-dirty$/', $vcs->getVersion(), 'Dirty version without a tag must end in -dirty');
     $hg->run('tag', '-u', 'Unit tester', '1.0.0');
     $hg->run('update', '1.0.0');
     $vcs = new VcsVersionInfo('name', null, $repoDir);
     $this->assertSame('1.0.0-dirty', $vcs->getVersion(), 'Dirty version with a tag must end in -dirty');
     $hg->run('update', '--clean', '1.0.0');
     $vcs = new VcsVersionInfo('name', null, $repoDir);
     $this->assertSame('1.0.0', $vcs->getVersion(), 'Clean version at specific tag');
     file_put_contents($fooPath, 'move on to next commit');
     $hg->run('commit', '-m move-on', '-u', 'Unit tester');
     $vcs = new VcsVersionInfo('name', null, $repoDir);
     $this->assertRegExp('/^1\\.0\\.0-1-m[0-9a-f]+$/', $vcs->getVersion(), 'Commit after latest tag');
     file_put_contents($fooPath, 'throw more dirt at tree');
     $vcs = new VcsVersionInfo('name', null, $repoDir);
     $this->assertRegExp('/^1\\.0\\.0-1-m[0-9a-f]+-dirty$/', $vcs->getVersion(), 'Commit after latest tag');
     Folder::delete($repoDir);
 }
예제 #4
0
 public function saveTargetProvider()
 {
     $tempFolder = Path::combine(sys_get_temp_dir(), 'nochso_writeme_test');
     Folder::ensure($tempFolder);
     return ['Specified target path' => [new Document(''), Path::combine($tempFolder, 'target.md'), Path::combine($tempFolder, 'target.md')], 'WRITEME turns to README' => [new Document('', Path::combine($tempFolder, 'WRITEME.md')), null, Path::combine($tempFolder, 'README.md')], 'WRITEME turns to README (case insensitive)' => [new Document('', Path::combine($tempFolder, 'writeme')), null, Path::combine($tempFolder, 'readme')], 'Get target path from frontmatter' => [new Document("---\ntarget: " . Path::combine($tempFolder, 'target.md') . "\n---"), null, Path::combine($tempFolder, 'target.md')]];
 }