1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PHPで標準入出力をテストする

Last updated at Posted at 2018-12-09

頂いたコメントを元に、新しく記事を作成しました。
PHPで標準入出力をテストする(改め)
https://qiita.com/AraiKotaro/items/f6f61bb24c194c048275

dockerでPHPUnitを導入

$docker pull phpunit/phpunit

PHPコードを作成

Lines.php
<?php
class Lines extends \PHPUnit\Framework\TestCase
{
        public static function main()
        {
                echo('test');
        }
        function testMain()
        {
                ob_start();
                Lines::main();
                $actual = ob_get_clean();
                $expected = 'test';
                $this->assertEquals($expected, $actual);
        }
}
Lines::main();
?>

標準入力テストデータを作成

test.txt
test

テスト実行

$docker run -v (Lines.phpのあるディレクトリ):/app phpunit/phpunit Lines.php < test.txt

結果

$docker run -v (Lines.phpのあるディレクトリ):/app phpunit/phpunit Lines.php < test.txt
test
PHPUnit 6.5.13 by Sebastian Bergmann, Julien Breux (Docker) and contributors.

.                                                                   1 / 1 (100%)

Time: 120 ms, Memory: 4.00MB

OK (1 test, 1 assertion)

参考

http://miko.info/?p=1118
https://qiita.com/mosaxiv/items/f58bb7e141d9f7e85c75

1
0
4

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?