zhamao-framework/tests/ZM/GlobalFunctionsTest.php
sunxyw 97face2406
add chain and stopwatch helper functions (#99)
* add chain helper function

* add stopwatch helper function
2022-04-15 23:10:29 +08:00

44 lines
977 B
PHP

<?php
declare(strict_types=1);
namespace Tests\ZM;
use PHPUnit\Framework\TestCase;
/**
* @internal
*/
class GlobalFunctionsTest extends TestCase
{
public function testChain(): void
{
$mock = $this->getMockBuilder(\stdClass::class)
->addMethods(['foo', 'bar', 'baz'])
->getMock();
$mock->expects($this->once())
->method('foo')
->willReturn('foo');
$mock->expects($this->once())
->method('bar')
->with('foo')
->willReturn('bar');
$mock->expects($this->once())
->method('baz')
->with('bar')
->willReturn('baz');
$result = chain($mock)->foo()->bar(CARRY)->baz(CARRY);
$this->assertEquals('baz', $result);
}
public function testStopwatch(): void
{
$time = stopwatch(static function () {
usleep(10000);
});
$this->assertLessThan(0.1, $time);
}
}