File: NamespaceTest.php

package info (click to toggle)
php-opis-closure 3.6.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 576 kB
  • sloc: php: 3,313; xml: 41; makefile: 17; sh: 8
file content (34 lines) | stat: -rw-r--r-- 821 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php

namespace Opis\Closure\Test;

use Closure;
use Opis\Closure\ClosureContext;
use Opis\Closure\ClosureContext as SomeAlias;
use Opis\Closure\SerializableClosure;

final class NamespaceTest extends \PHPUnit\Framework\TestCase
{
    public function testNamespacedObjectInsideClosure()
    {
        $closure = function () {
            $object = new ClosureContext();

            self::assertInstanceOf('\Opis\Closure\ClosureContext', $object);
            self::assertInstanceOf(SomeAlias::class, $object);
        };

        $executable = $this->s($closure);

        $executable();
    }

    protected function s($closure)
    {
        if ($closure instanceof Closure) {
            $closure = new SerializableClosure($closure);
        }

        return unserialize(serialize($closure))->getClosure();
    }
}