public function testInterfaceAccessors() { $m = new ClassInspector('SR\\Reflection\\Tests\\Helper\\FixtureClassThree'); $result = $m->filterInterfaces(function (InterfaceInspector $m) { return false !== strpos($m->name(), 'Two'); }); $this->assertCount(1, $result); $result = $m->filterInterfaces(function (InterfaceInspector $m) { return $m->name() === 'abcdef'; }); $this->assertCount(0, $result); $result = $m->filterOneInterface(function (InterfaceInspector $m) { return $m->name() === 'FixtureInterfaceThree'; }); $this->assertTrue($result instanceof InterfaceInspector); $result = $m->filterOneInterface(function (InterfaceInspector $m) { return $m->name() === 'abcdef'; }); $this->assertNull($result); $result = $m->matchInterfaces('FixtureInterfaceThree'); $this->assertCount(1, $result); $this->assertTrue($result[0] instanceof InterfaceInspector); $result = $m->matchInterfaces('abcdef'); $this->assertCount(0, $result); $result = $m->matchOneInterface('FixtureInterfaceTwo'); $this->assertTrue($result instanceof InterfaceInspector); $result = $m->matchOneInterface('abcdef'); $this->assertNull($result); $this->assertTrue($m->implementsInterface('SR\\Reflection\\Tests\\Helper\\FixtureInterfaceTwo')); $this->assertTrue($m->implementsInterface('SR\\Reflection\\Tests\\Helper\\FixtureInterfaceThree')); $this->assertTrue($m->implementsInterface('FixtureInterfaceTwo')); $this->assertTrue($m->implementsInterface('FixtureInterfaceThree')); $this->assertFalse($m->implementsInterface('abcdef')); $result = $m->getInterface('FixtureInterfaceTwo'); $this->assertTrue($result instanceof InterfaceInspector); $result = $m->getInterface('FixtureInterfaceThree'); $this->assertTrue($result instanceof InterfaceInspector); $result = $m->getInterface('SR\\Reflection\\Tests\\Helper\\FixtureInterfaceTwo'); $this->assertTrue($result instanceof InterfaceInspector); $result = $m->getInterface('SR\\Reflection\\Tests\\Helper\\FixtureInterfaceThree'); $this->assertTrue($result instanceof InterfaceInspector); $result = $m->sortInterfaces(function (InterfaceInspector $a, InterfaceInspector $b) { return substr($a->name(), -3, 1) > substr($b->name(), -3, 1); }); $this->assertGreaterThan(1, $result); $result = $m->visitInterfaces(function (InterfaceInspector $p) { return $p->name() . 'VISITOR'; }); array_walk($result, function ($p) { $this->assertStringEndsWith('VISITOR', $p); }); $this->expectException(InvalidArgumentException::class); $this->getFixtureInstances()[0]->getInterface('abcdef'); }
/** * @return \ReflectionClass|\ReflectionObject */ public function reflectionDeclaringClass() { return $this->declaringClass->reflection(); }