Skip to content
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

Add path wildcard feature to Enumerator #300

Merged
merged 4 commits into from
Nov 28, 2016
Merged

Add path wildcard feature to Enumerator #300

merged 4 commits into from
Nov 28, 2016

Conversation

icanhazstring
Copy link
Member

Add wildcard possibility for includePaths and excludePaths

class EnumeratorTest extends \PHPUnit_Framework_TestCase
{

static $fixtureBasePath;

Choose a reason for hiding this comment

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

Visibility must be declared on property $fixtureBasePath


static $fixtureBasePath;

static $testPaths = [

Choose a reason for hiding this comment

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

Visibility must be declared on property $testPaths

public function testExclude($expectedPaths, $includePaths, $excludePaths)
{
$basePath = static::$fixtureBasePath;
$addBasePath = function($path) use ($basePath) {

Choose a reason for hiding this comment

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

Expected 1 space after FUNCTION keyword; 0 found

@lisachenko
Copy link
Member

Hi! Thank you for your job! I'll review it soon

@icanhazstring
Copy link
Member Author

icanhazstring commented Nov 23, 2016

@lisachenko can you merge this into the 1.x version line as well?
Problem ist for example we currently can only use PHP<=5.5 - but with the 2.x version line PHP>5.6 is required and the PR could be easily merged in both (no conflicts)

So this needs to be merged into both versions - if possible

foreach ($includePaths as $includePath) {
if (strpos($realPath, $includePath) === 0) {
foreach ($includePaths as $includePattern) {
if (preg_match('%' . $includePattern . '%', $filePath)) {
Copy link
Member

Choose a reason for hiding this comment

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

I have a worry, that preg_match() could be slow for checking a lot of files during class loading of big framework. Could you please check, if fnmatch() could be faster than preg_match().

Copy link
Member Author

Choose a reason for hiding this comment

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

Problem is that fnmatch does not work with multiple subfolders. so /base/*/test only includes /base/sub/test but not /base/sub/sub/test

Copy link
Member

Choose a reason for hiding this comment

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

Please, see: https://3v4l.org/iPR39#output Your case is second line

Copy link
Member Author

Choose a reason for hiding this comment

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

Well... ok. I'll rewrite it then :)

*
* @return string
*/
protected function parseWildcardPath($path)
Copy link
Member

Choose a reason for hiding this comment

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

This function can be replaced with built-in fnmatch(), see fnmatch() function

throw new \Exception('TEST_DIRECTORY not set, check your phpunit.xml');
}

static::$fixtureBasePath = realpath(TEST_DIRECTORY) . DIRECTORY_SEPARATOR . 'fixtures';
Copy link
Member

Choose a reason for hiding this comment

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

Oh, it's an armed gun ) Because for several cases realpath() can return false which will equal to the empty string. Maybe we can use VFS filesystem for safe tests?

*/
public static function tearDownAfterClass()
{
exec('rm -rf ' . static::$fixtureBasePath);
Copy link
Member

Choose a reason for hiding this comment

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

Very dangerous command, I think VFS will be better to use, because who knows if static::$fixtureBasePath will equal to the '/'?

@lisachenko lisachenko changed the base branch from master to 1.x November 23, 2016 11:18
@lisachenko
Copy link
Member

@icanhazstring changed the base to 1.x, please don't forget to rebase your local branch as well

*
* @return string
*/
protected function getFileFullPath(\SplFileInfo $file) {

Choose a reason for hiding this comment

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

Opening brace should be on a new line

// VFS does not support getRealPath()
$mock->expects($this->any())
->method('getFileFullPath')
->will($this->returnCallback(function(\SplFileInfo $file) {

Choose a reason for hiding this comment

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

Expected 1 space after FUNCTION keyword; 0 found

@icanhazstring
Copy link
Member Author

@lisachenko reworked the tests using vfs and using fnmatch() for testing path against pattern

@lisachenko lisachenko merged commit bd98a07 into goaop:1.x Nov 28, 2016
@lisachenko
Copy link
Member

Squashed and merged! Thank you very much! 👍

@lisachenko lisachenko added this to the 1.2.0 milestone Nov 28, 2016
lisachenko added a commit that referenced this pull request Nov 28, 2016
* origin/1.x:
  Add path wildcard feature to Enumerator (#300)

Conflicts:
	composer.json
	composer.lock
@icanhazstring icanhazstring deleted the feature/wildcard-enumerator branch November 28, 2016 14:36
lisachenko added a commit that referenced this pull request Jan 10, 2017
* origin/1.x:
  Fixed broken logic of matching with base path, related to #300
  Enable bootstraping autoload for composer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants