bingher/ think-test
ThinkPHP6 的 PHPUnit
v1.0.2
2023-08-13 07:53 UTC
Requires
- php: >=7.3
- phpunit/phpunit: ^9.5
Requires (Dev)
- ext-xdebug: *
- topthink/framework: ^6.0.0
README
安装
composer require bingher/think-test
使用方法
添加测试用例 /test/Test.php
<?php use bingher\ThinkTest\ThinkTest; class Test extends ThinkTest { public function testTap() { $result = tap('world'); $this->assertEquals($result, 'world'); $result = tap('world', null); $this->assertEquals($result, 'world'); $result = tap( 'world', function ($v) { $v = 'hello ' . $v; } ); $this->assertEquals($result, 'world'); $result = tap( 'world', function (&$v) { $v = 'hello ' . $v; } ); $this->assertEquals($result, 'hello world'); } }
运行测试用例
windows
./vendor/bin/tpt.bat ./test/Test.php
Unix/Linux
./vendor/bin/tpt ./test/Test.php
更多
等待测试类 test/Hello.php
<?php namespace bingher\test; use bingher\ThinkTest\ThinkTest; class Test extends ThinkTest { public function testTap() { $result = tap('world'); $this->assertEquals($result, 'world'); $result = tap('world', null); $this->assertEquals($result, 'world'); $result = tap( 'world', function ($v) { $v = 'hello ' . $v; } ); $this->assertEquals($result, 'world'); $result = tap( 'world', function (&$v) { $v = 'hello ' . $v; } ); $this->assertEquals($result, 'hello world'); } }
测试用例 test/HelloTest.php
<?php namespace bingher\test; use bingher\ThinkTest\ThinkTest; class HelloTest extends ThinkTest { public function testSay() { $hello = new Hello; //use prop function get protected properties $name = $this->prop($hello, 'name'); $this->assertEquals($name, 'bingher'); $result = $hello->say(); $this->assertEquals($result, 'hello bingher'); } public function testSmile() { $hello = new Hello('mondy'); //use prop function get protected properties $name = $this->prop($hello, 'name'); $this->assertEquals($name, 'mondy'); //use call function run protected function $result = $this->call($hello, 'smile'); $this->assertEquals($result, 'hello mondy :)'); //add params $result = $this->call($hello, 'smile', [2]); $this->assertEquals($result, 'hello mondy :):)'); //use prop function set protected properties value $this->prop($hello, 'name', 'everyone'); $name = $this->prop($hello, 'name'); $this->assertEquals($name, 'everyone'); } }