/
githubmirror
/
framework
Обзор
Документация
Войти
/
githubmirror
/
framework
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
13.x
tests/Support/HigherOrderProxyTest.php
71 строка
2 KB
Milad
[12.x] Add HigherOrderProxy tests (Collection & Tap) (#58138)
16 дек 2025, 18:02
Не верифицирован
16 дек 2025, 18:02
5e90d48
Код
Авторство
О чём код?
<?php namespace Illuminate\Tests\Support; use Illuminate\Support\Collection; use Illuminate\Support\HigherOrderCollectionProxy; use Illuminate\Support\HigherOrderTapProxy; use PHPUnit\Framework\TestCase; class HigherOrderProxyTest extends TestCase { public function test_get_proxies_property_access_to_items() { $items = new Collection([ (object) ['name' => 'Alice'], (object) ['name' => 'Bob'], ]); $proxy = new HigherOrderCollectionProxy($items, 'pluck'); // The proxied method returns a Collection instance; assert type and values $this->assertInstanceOf(Collection::class, $proxy->name); $this->assertEquals(['Alice', 'Bob'], $proxy->name->all()); } public function test_call_proxies_method_call_to_items() { $items = new Collection([ new class { public function shout($s) { return strtoupper($s); } }, new class { public function shout($s) { return strtoupper($s).'!'; } }, ]); $proxy = new HigherOrderCollectionProxy($items, 'map'); $result = $proxy->shout('hey'); $this->assertEquals(['HEY', 'HEY!'], $result->all()); } public function test_call_forwards_and_returns_target() { $target = new class { public $count = 0; public function increment($by = 1) { $this->count += $by; } }; $proxy = new HigherOrderTapProxy($target); $result = $proxy->increment(3); $this->assertSame(3, $target->count); $this->assertSame($target, $result); } }