1<?php
2
3declare(strict_types=1);
4
5namespace Metadata\Tests;
6
7use Metadata\MethodMetadata;
8use Metadata\Tests\Fixtures\TestObject;
9use PHPUnit\Framework\TestCase;
10
11class MethodMetadataTest extends TestCase
12{
13    public function testConstructor()
14    {
15        $metadata = new MethodMetadata('Metadata\Tests\Fixtures\TestObject', 'setFoo');
16        $expectedReflector = new \ReflectionMethod('Metadata\Tests\Fixtures\TestObject', 'setFoo');
17        $expectedReflector->setAccessible(true);
18
19        $this->assertEquals('Metadata\Tests\Fixtures\TestObject', $metadata->class);
20        $this->assertEquals('setFoo', $metadata->name);
21        $this->assertEquals($expectedReflector, $metadata->reflection);
22    }
23
24    public function testSerializeUnserialize()
25    {
26        $metadata = new MethodMetadata('Metadata\Tests\Fixtures\TestObject', 'setFoo');
27
28        $this->assertEquals($metadata, unserialize(serialize($metadata)));
29    }
30
31    public function testInvoke()
32    {
33        $obj = new TestObject();
34        $metadata = new MethodMetadata('Metadata\Tests\Fixtures\TestObject', 'setFoo');
35
36        $this->assertNull($obj->getFoo());
37        $metadata->invoke($obj, ['foo']);
38        $this->assertEquals('foo', $obj->getFoo());
39    }
40}
41