LoginSignup
14
12

More than 5 years have passed since last update.

作業している“フリ”をできる休憩用xUnit

Last updated at Posted at 2014-05-17

はじめに

巷で話題になってる作業しているフリの…のxUnit(今回はPHPUnit)版を作りました。
ジョークアプリです。休憩用です。
指定した時間、テストを流しているフリをします。

Demo

ju.gif

使い方

./jokeUnit.php -m [休憩時間(分)] -s [休憩時間(数)]
すごくテキトーです。

ソース

jokeUnit.php
#!/usr/bin/php
<?php
// オプション -m [分] -s [秒]

// オプション取得
// (オプションが何も指定されていなければデフォルト10秒
$options = getopt('m:s:');
$minutes = (is_null($options['m'])) ? 0  : $options['m'];
$sec     = (is_null($options['s'])) ? 10 : $options['s'];

// 処理秒数
$processing_sec = $sec + ($minutes * 60);
// 終了時間(unixtime)
$end_unix_time = time() + $processing_sec;
// 最大ドット数
$max_dot = $processing_sec * 2;

// 画面クリア
print("\033[2J");
print("\033[0;0H");

print("PHPUnit 4.1.0 by Sebastian Bergmann.\n\n");

// 表示したドット数
$dot = 0;
$wait_time = $processing_sec / $max_dot * 1000000;
while(time() < $end_unix_time){
    print('.');
    $dot++;
    if ($dot % 61 == 0){
        print('  '.str_pad($dot, strlen($max_dot), ' ', STR_PAD_LEFT).' / '.$max_dot.' ( '.str_pad(floor($dot/$max_dot* 100), 2, ' ', STR_PAD_LEFT).'%)'."\n");
    }
    usleep($wait_time);
}
print("\n\n");
print('Time: '.$processing_sec.' seconds, Memory: 8.00Mb'."\n");
print("\n");
print('OK ('.$max_dot.' tests, '.($max_dot + rand(1, $max_dot * 3)).' assertions)'."\n");
14
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
12