Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Corrected the exception class used and removed unnecessary strtolower in MethodScanner::setVisibility #140

Conversation

fhein
Copy link
Contributor

@fhein fhein commented Nov 5, 2017

Exception - which is used as exception class within setVisibility - is not a class but a (sub)namespace. InvalidArgumentException likely is the intended exception class here.

This is my first submission. Wanted to get my feet wet with the submission workflow. :)

@Ocramius
Copy link
Member

Ocramius commented Nov 5, 2017

@fhein patch looks fine, but a test case verifying the expected thrown exception type is needed. See https://github.com/zendframework/zend-code/blob/6b1059db5b368db769e4392c6cb6cc139e56640d/test/Scanner/MethodScannerTest.php

You can push to your current branch to update this PR 👍

mxc-commons added 2 commits November 5, 2017 17:58
- Added test case for InvalidArgumentException
- Added test case for switch
@fhein fhein changed the title Corrected the exception class used in MethodScanner::setVisibility Corrected the exception class used and removed unnecessary strtolower in MethodScanner::setVisibility Nov 6, 2017
@fhein
Copy link
Contributor Author

fhein commented Nov 6, 2017

Done. Plus a bit. :) Anything left to do?

{
$methodScanner = new MethodScanner([]);

self::assertTrue($methodScanner->setVisibility(T_PUBLIC) === $methodScanner);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertSame

$methodScanner = new MethodScanner([]);

self::assertTrue($methodScanner->setVisibility(T_PUBLIC) === $methodScanner);
self::assertTrue($methodScanner->setVisibility(T_PROTECTED) === $methodScanner);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertSame


self::assertTrue($methodScanner->setVisibility(T_PUBLIC) === $methodScanner);
self::assertTrue($methodScanner->setVisibility(T_PROTECTED) === $methodScanner);
self::assertTrue($methodScanner->setVisibility(T_PRIVATE) === $methodScanner);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertSame

@@ -110,4 +111,27 @@ public function testMethodScannerWorksWithSingleAbstractFunction()

self::assertTrue($method->isAbstract());
}

/**
* @expectedException \Zend\Code\Exception\InvalidArgumentException
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use $this->expectException() instead, and right before the call that causes the exception to be thrown.

$methodScanner = new MethodScanner([]);

$invalidArgument = 42;
self::assertTrue(! in_array($invalidArgument, [T_PUBLIC, T_PROTECTED, T_PRIVATE]));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this assertion - if the code stops throwing exceptions, we know we broke BC :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to stay with this one. Ok, it's not likely that the constant values of T_PUBLIC et al change. ;) But if the values were changed, the change could break the test (e.g. T_PUBLIC = 42).
BC would not be affected (in the particular context of this method).

Ok?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are testing something unrelated here, that's why I asked for removal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Now I make sure that the argument is invalid without asserting that.

@Ocramius
Copy link
Member

Ocramius commented Nov 7, 2017

Looking good!

@fhein
Copy link
Contributor Author

fhein commented Nov 7, 2017

:) . This was very helpful to setup and test my environment. Thanks.

After a short review of Roave/BetterReflection I think it is better to stop fiddling around with the scanner stuff here. I've got some spare time I could spent helping out. If you like and if there's demand, feel free to give me a try and direct me to somewhere where help is needed.

@weierophinney weierophinney merged commit 5e9f463 into zendframework:master Aug 13, 2018
weierophinney added a commit that referenced this pull request Aug 13, 2018
…ted_Exception_class_used

Corrected the exception class used and removed unnecessary strtolower in MethodScanner::setVisibility
weierophinney added a commit that referenced this pull request Aug 13, 2018
weierophinney added a commit that referenced this pull request Aug 13, 2018
weierophinney added a commit that referenced this pull request Aug 13, 2018
@weierophinney
Copy link
Member

Thanks, @fhein!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants