Skip to content

Commit

Permalink
Added spl tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sorinsarca committed Dec 28, 2024
1 parent 1573ef5 commit 134801f
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/PHP80/SplTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Opis\Closure\Test\PHP80;

use ArrayObject, SplObjectStorage;
use Opis\Closure\Test\SerializeTestCase;

class SplTest extends SerializeTestCase
{
public function testArrayObject()
{
$obj = new ArrayObject(["fn" => static fn () => "ok_key"], ArrayObject::STD_PROP_LIST);
$obj->fn = static fn() => "ok_prop";
$obj = $this->process($obj);
$this->assertEquals("ok_key", $obj["fn"]());
$this->assertEquals("ok_prop", ($obj->fn)());
}

public function testSplObjectStorage()
{
$f = static fn () => "ok";
$obj = new SplObjectStorage();
$obj[$f] = $f;

$obj = $this->process($obj);

$closure = iterator_to_array($obj)[0];

$this->assertEquals("ok", $closure());
$this->assertEquals($closure, $obj[$closure]);
}
}

0 comments on commit 134801f

Please sign in to comment.