-
Notifications
You must be signed in to change notification settings - Fork 3
Test enhancement #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 5 commits
1bde7a1
506bdf8
c206ca6
14625aa
978255d
6583e51
acbbd21
91cab56
5a11f9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,4 +51,45 @@ public function testAliasedImport() | |
| $this->assertResolve(Tools::class . '\A', 'Tools\A'); | ||
| $this->assertResolve(Tools::class . '\A\B', 'Tools\A\B'); | ||
| } | ||
|
|
||
| /** | ||
| * @expectedException \InvalidArgumentException | ||
| * @expectedExceptionMessage Cannot infer the file name from the given ReflectionObject | ||
| */ | ||
| public function testConstructorWithInvalidInferFileNameShouldThrowInvalidArgumentException() | ||
| { | ||
| $resolver = new ImportResolver(new \ReflectionObject(new \Exception)); | ||
| } | ||
|
|
||
| public function testConstructorWithReflectionProperty() | ||
| { | ||
| $resolver = new ImportResolver(new \ReflectionProperty(ReflectionTarget::class, 'foo')); | ||
|
|
||
| $this->assertSame(ReflectionTarget::class, $resolver->resolve('ReflectionTarget')); | ||
| } | ||
|
|
||
| public function testConstructorWithReflectionMethod() | ||
| { | ||
| $resolver = new ImportResolver(new \ReflectionMethod(ReflectionTarget::class, 'publicStaticMethod')); | ||
|
|
||
| $this->assertSame('Brick\Reflection\Tests\publicStaticMethod', $resolver->resolve('publicStaticMethod')); | ||
| } | ||
|
|
||
| public function testConstructorWithReflectionParameter() | ||
| { | ||
| $resolver = new ImportResolver(new \ReflectionParameter([ | ||
| ReflectionTarget::class, 'privateFunc', | ||
| ], 'str')); | ||
|
|
||
| $this->assertSame('Brick\Reflection\Tests\privateFunc', $resolver->resolve('privateFunc')); | ||
|
||
| } | ||
|
|
||
| /** | ||
| * @expectedException \InvalidArgumentException | ||
| * @expectedExceptionMessage Cannot infer the declaring class from the given ReflectionFunction | ||
| */ | ||
| public function testConstructorWithReflectedFunctionShouldThrowInvalidArgumentException() | ||
|
||
| { | ||
| $resolver = new ImportResolver(new \ReflectionFunction('Brick\Reflection\Tests\reflectedFunc')); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <?php | ||
|
|
||
| namespace Brick\Reflection\Tests; | ||
|
|
||
| /** | ||
| * The Reflection Target class. | ||
| */ | ||
| class ReflectionTarget | ||
| { | ||
| /** | ||
| * @param string $foo | ||
|
||
| */ | ||
| private $foo; | ||
|
|
||
| /** | ||
| * @var string $bar | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be |
||
| */ | ||
| private $bar; | ||
|
|
||
| /** | ||
| * @var \\Exception $barWithType | ||
|
||
| */ | ||
| private $barWithType; | ||
|
|
||
| public function __construct() | ||
| { | ||
| $this->foo = 'foo'; | ||
| $this->bar = 'bar'; | ||
| } | ||
|
|
||
| /** | ||
| * @param string $str | ||
| * @return string $str | ||
|
||
| */ | ||
| private function privateFunc(string $str) | ||
| { | ||
| return $str; | ||
| } | ||
|
|
||
| /** | ||
| * @return void | ||
| */ | ||
| public static function publicStaticMethod() | ||
| { | ||
| return 'publicStaticMethod'; | ||
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?php | ||
|
|
||
| namespace Brick\Reflection\Tests; | ||
|
|
||
| /** | ||
| * The Target Reflection function without parameter. | ||
| */ | ||
| function reflectedFunc() | ||
| { | ||
| return 'test'; | ||
| } | ||
|
|
||
| /** | ||
| * The Target Reflection function with string parameter. | ||
| * @param string $arg | ||
| */ | ||
| function reflectedParameterFunc(string $arg) | ||
| { | ||
| return isset($arg) ? $arg : 'test'; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is actually weird, you're attempting to resolve a class called
publicStaticMethodwhich is very confusing. Let's just call it 'Foo'?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I write the wrong assertions here and it should be
ReflectionTargetclass.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, FYI it can be any class name, even if it does not exist!