mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-21 07:35:34 +08:00
add chain and stopwatch helper functions (#99)
* add chain helper function * add stopwatch helper function
This commit is contained in:
43
tests/ZM/GlobalFunctionsTest.php
Normal file
43
tests/ZM/GlobalFunctionsTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user