/
githubmirror
/
framework
Обзор
Документация
Войти
/
githubmirror
/
framework
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
13.x
tests/Support/SupportTimeboxTest.php
86 строк
2 KB
Jason McCreary
[13.x] Mockery cleanup (#61117)
10 авг 2026, 20:23
Не верифицирован
10 авг 2026, 20:23
2ee40ee
Код
Авторство
О чём код?
<?php namespace Illuminate\Tests\Support; use Exception; use Illuminate\Support\Timebox; use Mockery; use PHPUnit\Framework\TestCase; class SupportTimeboxTest extends TestCase { public function testMakeExecutesCallback() { $callback = function () { $this->assertTrue(true); }; (new Timebox)->call($callback, 0); } public function testMakeWaitsForMicroseconds() { $mock = Mockery::spy(Timebox::class)->shouldAllowMockingProtectedMethods()->makePartial(); $mock->expects('usleep'); $mock->call(function () { }, 10000); $mock->shouldHaveReceived('usleep')->once(); } public function testMakeShouldNotSleepWhenEarlyReturnHasBeenFlagged() { $mock = Mockery::spy(Timebox::class)->shouldAllowMockingProtectedMethods()->makePartial(); $mock->call(function ($timebox) { $timebox->returnEarly(); }, 10000); $mock->shouldNotHaveReceived('usleep'); } public function testMakeShouldSleepWhenDontEarlyReturnHasBeenFlagged() { $mock = Mockery::spy(Timebox::class)->shouldAllowMockingProtectedMethods()->makePartial(); $mock->expects('usleep'); $mock->call(function ($timebox) { $timebox->returnEarly(); $timebox->dontReturnEarly(); }, 10000); $mock->shouldHaveReceived('usleep')->once(); } public function testMakeWaitsForMicrosecondsWhenExceptionIsThrown() { $mock = Mockery::spy(Timebox::class)->shouldAllowMockingProtectedMethods()->makePartial(); $mock->expects('usleep'); try { $this->expectExceptionObject(new Exception('Exception within Timebox callback.')); $mock->call(function () { throw new Exception('Exception within Timebox callback.'); }, 10000); } finally { $mock->shouldHaveReceived('usleep')->once(); } } public function testMakeShouldNotSleepWhenEarlyReturnHasBeenFlaggedAndExceptionIsThrown() { $mock = Mockery::spy(Timebox::class)->shouldAllowMockingProtectedMethods()->makePartial(); try { $this->expectExceptionObject(new Exception('Exception within Timebox callback.')); $mock->call(function ($timebox) { $timebox->returnEarly(); throw new Exception('Exception within Timebox callback.'); }, 10000); } finally { $mock->shouldNotHaveReceived('usleep'); } } }