Php-file-iterator - FilterIterator implementation that filters files based on a list of suffixes, prefixes, and other exclusion criteria.

Overview

Build Status

php-file-iterator

Installation

You can add this library as a local, per-project dependency to your project using Composer:

composer require phpunit/php-file-iterator

If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency:

composer require --dev phpunit/php-file-iterator
Comments
  • File missing while using `File_Iterator_Factory`

    File missing while using `File_Iterator_Factory`

    As my test files increasing, I found some of the test case was not able to run. I got the message like this:

    Time: 1.7 seconds, Memory: 6.00MB
    
    No tests executed!
    
    Process finished with exit code 0
    

    After running some tests, I figure out that the problem occurs at /src/Facade.php::getFilesAsArray.

    When using foreach to run the iterartor created by File_Iterator_Factory, it seems to be ok in normal situation. But when the files in the directory up to more than 60, some of the files seems to be missing.

    It may be a problem with php's iterator, And I suggest that you can call $iterator->rewind() before using foreach. Or you can use $iterator->next() and other funtions to iterate.

    You can use the file below to reproduce the problem of RecursiveDirectoryIterator, which is used in File_Iterator_Factory reproduce_test_code.txt

    opened by nlrex 8
  • Exclude is not considered if it's a parent of base path

    Exclude is not considered if it's a parent of base path

    This seems to be the cause of sebastianbergmann/phpunit#2815. When trying to make a single "exclude" relative, it strips base path from it which doesn't work if an "exclude" is a parent of base path, which (supposedly) must exclude all the contents of base path. While #27 tries to address this issue, I'm not sure whether this would work on Windows so probably it needs another take.

    stale 
    opened by kamazee 8
  • Set exclude var to

    Set exclude var to "/" if its an empty string after removing the basepath

    With following testsuites configuration, the php-file-iterator returned a PHP warning To prevent this warning I suggest that if the $_exclude var ist empty after removing the basepath it should be set to '/'.

    Testsuite configuration:

    <testsuites>
        <testsuite name="some">
            <directory>../src/Acme/SomeBundle/Tests</directory>
        </testsuite>
        <testsuite name="other">
            <directory>../src/*/*Bundle/Tests</directory>
            <directory>../src/*/*/*Bundle/Tests</directory>
            <exclude>../src/Acme/SomeBundle/Tests</exclude>
        </testsuite>
    </testsuites>
    

    PHP-Warning:

    PHP Warning:  strpos(): Empty needle in /some-dir/vendor/phpunit/php-file-iterator/src/Iterator.php on line 104
    
    opened by IceShack 8
  • 1.3.0RC1 issue

    1.3.0RC1 issue

    I had installed that and phpunit dies with

    till@dev:~$ phpunit
    PHP Fatal error:  Class 'File_Iterator' not found in /usr/share/php/File/Iterator/Factory.php on line 105
    

    This was the list of installed packages:

    till@dev:~$ pear list -c pear.phpunit.de
    Installed packages, channel pear.phpunit.de:
    ============================================
    Package            Version  State
    DbUnit             1.0.3    stable
    File_Iterator      1.3.0RC1 beta
    PHPUnit            3.5.15   stable
    PHPUnit_MockObject 1.1.0RC2 beta
    PHPUnit_Selenium   1.1.0RC1 beta
    PHP_CodeCoverage   1.0.5    stable
    PHP_Timer          1.0.2    stable
    PHP_TokenStream    1.1.0RC2 beta
    Text_Template      1.1.1RC1 beta
    phpUnderControl    0.5.0    beta
    phpcpd             1.3.2    stable
    phploc             1.6.1    stable
    

    A downgrade to 1.2.6 fixed it.

    opened by till 8
  • Follow symlinks

    Follow symlinks

    I am the developer of several Drupal modules and to make my life easier I created symlinks to those modules within a Drupal installation I use as a testbed. However, as symlinks are not followed, my modules' PHPUnit tests are not recognized by PHPUnit when running tests from the Drupal root. Supporting symlinks will allow me to run all PHPUnit tests in the installation together in one go.

    opened by bartfeenstra 7
  • ignore exclude wildcard directories that do not resolve to paths

    ignore exclude wildcard directories that do not resolve to paths

    This is to handle a case where, for example, an exclude directory is specified with a wildcard, but no directories are actually matched by the \glob() call. At present, this causes \realpath($path) to return false. Such a value should be filtered out of the returned paths.

    If this PR is insufficient either as a code change or in the description here, let me know and I can rectify.

    opened by shieldo 6
  • Regression in 2.0 causes File_Iterator to filter everything if target has hidden parent directory

    Regression in 2.0 causes File_Iterator to filter everything if target has hidden parent directory

    I've just updated PHPUnit to 7.2.4 and our TeamCity CI-Server is not running any tests anymore. The reason imho that the TeamCity agents are using hidden work directories. So it seem, we're back to square #1.

    opened by soerenbernstein 5
  • Warning: strpos(): Empty delimiter in /usr/share/php/File/Iterator.php on line 142

    Warning: strpos(): Empty delimiter in /usr/share/php/File/Iterator.php on line 142

    if i execute phpcpd in a directory up of the source-code, i get the following error:

    Warning: strpos(): Empty delimiter in /usr/share/php/File/Iterator.php on line 142

    i detect the problem on line 89 of file Iterator.php. On each exclude directory will execute realtpath. but realpath return false, because realpath is not in the right directory.

    Two Solutions:

    1. remove line 89: $exclude = array_map('realpath', $exclude);
    2. append $basepath on each exclude directory: $exclude = array_map(create_function('$path', 'return "'.($basepath[strlen($basepath)-1] != '/' ? $basepath.'/' : $basepath).'".($path[0] == "/" ? substr($path, -1) : $path);'), $exclude);
    opened by Valgard 5
  • Fatal error when phpunit 9 generate html coverage

    Fatal error when phpunit 9 generate html coverage

    Info and verisons

    Affected version: ^9

    Fatal error: Uncaught TypeError: Argument 1 passed to SebastianBergmann\FileIterator\Iterator::acceptPath() must be of the type string, bool given, called in /Users/roquie/google_drive/projects/spacetab-io/calcifer/human-resources/vendor/phpunit/php-file-iterator/src/Iterator.php on line 64 and defined in /Users/roquie/google_drive/projects/spacetab-io/calcifer/human-resources/vendor/phpunit/php-file-iterator/src/Iterator.php on line 69
    

    With ^8 version html coverage works fine.

    PHP 7.4.5 (cli) (built: Apr 23 2020 02:25:56) ( NTS )
    Copyright (c) The PHP Group
    Zend Engine v3.4.0, Copyright (c) Zend Technologies
        with Xdebug v2.9.0, Copyright (c) 2002-2019, by Derick Rethans
        with Zend OPcache v7.4.5, Copyright (c), by Zend Technologies
    

    Debug

    That happened because realpath fails to resolve symbolic link in amphp/windows-registry package.

    PHPUnit 9.2.5 by Sebastian Bergmann and contributors.
    
    Runtime:       PHP 7.4.5 with Xdebug 2.9.0
    Configuration: /Users/roquie/google_drive/projects/spacetab-io/calcifer/project/phpunit.xml
    false
    SplFileInfo {#80
      path: "/Users/roquie/google_drive/projects/spacetab-io/calcifer/project/vendor/amphp/windows-registry/docs"
      filename: "asset"
      basename: "asset"
      pathname: "/Users/roquie/google_drive/projects/spacetab-io/calcifer/project/vendor/amphp/windows-registry/docs/asset"
      extension: ""
      realPath: false
      type: "link"
      writable: false
      readable: false
      executable: false
      file: false
      dir: false
      link: true
      linkTarget: ".shared/asset"
    }
    

    Possible solutions:

    1. Throw an exception
    2. Ignore.

    What do you think?

    opened by roquie 4
  • Fix iteration files with usage directory or exclude uses glob

    Fix iteration files with usage directory or exclude uses glob

    Blocked by https://github.com/sebastianbergmann/php-file-iterator/pull/39

    Fixes https://github.com/sebastianbergmann/phpunit/issues/2815 and https://github.com/sebastianbergmann/php-file-iterator/issues/30

    Problems

    1. Path to exclude is less than basepath, str_replace the basepath fails
    2. Path to exclude is equals to basepath, strpos fails

    Test

    Unfortunately package does not have unit tests, there is test files:

    #!/usr/bin/env php
    <?php
    require_once 'vendor/autoload.php';
    
    $factory = new \SebastianBergmann\FileIterator\Factory();
    $iterator = $factory->getFileIterator('local/*/test', '', '', ['local/two', 'local/three/*']);
    $files = array_keys(iterator_to_array($iterator));
    
    assert(in_array('/home/local/one/test/OneTest.php', $files) === true);
    assert(in_array('/home/local/two/test/TwoTest.php', $files) === false);
    assert(in_array('/home/local/three/test/ThreeTest.php', $files) === false);
    

    Proposal

    Remove the basePath from iterator at all, compare the real path from file iterator and real path in excludes.

    opened by slavcodev 4
  • Regression causes

    Regression causes "No tests executed!"

    Hi, I tried the exact same build with php-file-iterator 1.4.3: https://travis-ci.org/pug-php/pug-symfony/jobs/307889898 Execute all tests.

    And with 1.4.4: https://travis-ci.org/pug-php/pug-symfony/jobs/307872780 Output No tests executed!

    Something with the new exclude system seems too restrictive.

    opened by kylekatarnls 4
  • Too slow execution when tests folder contains many files (not even tests)

    Too slow execution when tests folder contains many files (not even tests)

    Hello,

    we noticed that our phpunit tests started to freeze before execution for up to 1 minute. After debugging, I found that the bottclneck is in the $fileIteratorFacade->getFilesAsArray(...) method.

    It foreaches over every file in the folders recursevely, even if the folders are excluded. Let me explain it with the example:

    Consider we have the following structure:

    first
    ├── exclude
    │   ├── exclude1.php
    │   └── exclude2.php
    ├── first1.php
    └── second
        ├── second1.php
        └── second2.php
    

    and the following simple script:

    <?php
    
    require 'vendor/autoload.php';
    
    use SebastianBergmann\FileIterator\Factory;
    
    $factory = new Factory();
    
    $iterator = $factory->getFileIterator('first', '', '', ['first/exclude']);
    
    foreach ($iterator as $file) {
        echo $file->getRealPath(), "\n\n";
    }
    

    When I add a debugging code to the vendor here:

    https://github.com/sebastianbergmann/php-file-iterator/blob/7f0f29702170e2786b2df813af970135765de6fc/src/Iterator.php#L73-L77

    I get the following result:

    /tmp/phpunit-filter/first/first1.php
    
    >> Excluding /tmp/phpunit-filter/first/exclude/exclude2.php
    
    >> Excluding /tmp/phpunit-filter/first/exclude/exclude1.php
    
    /tmp/phpunit-filter/first/second/second2.php
    
    /Users/maksrafalko/tmp/phpunit-filter/first/second/second1.php
    

    Please note that while first/exclude folder is excluded, Iterator keeps traversing over all files from excluded folder.

    Imagine, we have hundred of thousands of files (vendor folders) inside excluded folder, but each file is anyway processed.

    What is the right way to do it?

    From my opinion, folders that are excluded must not be traversed. Let's see how symfony/finder does it. Again, create a simple script for the same folder structure:

    <?php
    
    require 'vendor/autoload.php';
    
    use Symfony\Component\Finder\Finder;
    
    $finder = new Finder();
    
    $finder->files()->in('first')->exclude('exclude');
    
    foreach ($finder as $file) {
        echo $file->getRealPath(), "\n\n";
    }
    

    and let's see the result:

    /tmp/phpunit-filter/first/first1.php
    
    >> Excluding exclude
    
    /tmp/phpunit-filter/first/second/second2.php
    
    /tmp/phpunit-filter/first/second/second1.php
    

    As you can see, symfony/finder meets first/excluded folder, sees that it is excluded and does not traverse it farther.

    This is done thanks to FilterIterator and its implementation in symfony/finder: ExcludeDirectoryFilterIterator

    1. Do you think we need to implement something similar in php-file-iterator?
    2. Do you have any objections or know something that is incompatible with the filter iterator?

    Thank you.

    https://github.com/symfony/finder/blob/1d4d30533fa8e343a85f6c51b0cba1ef5d041929/Iterator/ExcludeDirectoryFilterIterator.php#L57-L59

    opened by maks-rafalko 1
Owner
Sebastian Bergmann
Sebastian Bergmann is the creator of PHPUnit. He co-founded thePHP.cc and helps PHP teams build better software.
Sebastian Bergmann
Easily add sub domains to your CakePHP application using route prefixes

Easily add sub domains to your CakePHP application using route prefixes. Based on code created by chinpei215.

multidimension.al 4 Feb 28, 2019
Rules to detect game engines and other technologies based on Steam depot file lists

SteamDB File Detection Rule Sets This is a set of scripts that are used by SteamDB to make educated guesses about the engine(s) & technology used to b

Steam Database 103 Dec 14, 2022
Reset UI Bookmarks allows admin users to reset their own UI bookmarks such as state of filters, column positions and applied sorting ( e.g Sales > Orders ).

Reset Ui Bookmarks Reset UI Bookmarks becomes an invaluable tool while working daily in the admin panel, especially on Magento® instances with a large

Magenizr 23 Oct 19, 2022
Implement event systems, signal slots, intercepting filters, and observers.

zend-eventmanager Repository abandoned 2019-12-31 This repository has moved to laminas/laminas-eventmanager. zend-eventmanager is designed for the fol

Zend Framework 1.7k Dec 9, 2022
This library can be used, among other things, to retrieve the classes, interfaces, traits, enums, functions and constants declared in a file

marijnvanwezel/reflection-file Library that allows reflection of files. This library can be used, among other things, to retrieve the classes, interfa

Marijn van Wezel 5 Apr 17, 2022
Wordpress/Elementor Plugin to list files from any folder

File List - Wordpress/Elementor Plugin Elementor plugin to generate a file list from an existing folder and rendering .index.html files as headers. Ge

Nabil Redmann 1 Jan 27, 2022
SPAM Registration Stopper is a Q2A plugin that prevents highly probable SPAM user registrations based on well-known SPAM checking services and other techniques

SPAM Registration Stopper [by Gabriel Zanetti] Description SPAM Registration Stopper is a Question2Answer plugin that prevents highly probable SPAM us

Gabriel Zanetti 2 Jan 23, 2022
PHP implementation for reading and writing Apache Parquet files/streams

php-parquet This is the first parquet file format reader/writer implementation in PHP, based on the Thrift sources provided by the Apache Foundation.

null 17 Oct 25, 2022
File Upload widget with multiple file selection, drag&drop support, progress bar, validation and preview images, audio and video for jQuery

File Upload widget with multiple file selection, drag&drop support, progress bar, validation and preview images, audio and video for jQuery. Supports cross-domain, chunked and resumable file uploads. Works with any server-side platform (Google App Engine, PHP, Python, Ruby on Rails, Java, etc.) that supports standard HTML form file uploads.

Sebastian Tschan 31.1k Dec 30, 2022
Provide CSV, JSON, XML and YAML files as an Import Source for the Icinga Director and optionally ship hand-crafted additional Icinga2 config files

Icinga Web 2 Fileshipper module The main purpose of this module is to extend Icinga Director using some of it's exported hooks. Based on them it offer

Icinga 25 Sep 18, 2022
Write to Laravel Config files and maintain file integrity

Laravel Config Writer Write to Laravel Config files and maintain file integrity. This library is an extension of the Config component used by Laravel.

Sam Geo 158 Dec 30, 2022
Optimizes class loading performance by generating a single PHP file containing all of the autoloaded files.

Class Preloader for PHP This tool is used to generate a single PHP script containing all of the classes required for a specific use case. Using a sing

Class Preloader 356 Nov 26, 2022
Perch Dashboard app for exporting content to (Kirby) text files and Kirby Blueprint files

toKirby Perch Dashboard app for exporting content to (Kirby) text files and Kirby Blueprint files. You can easily install and test it in a few steps.

R. Banus 4 Jan 15, 2022
An online system to keep digitized form of employee personal files (staff personal files)

An online system to keep digitized form of employee personal files (staff personal files).

p r o c e s s o r 2 Jun 18, 2022
Creating data transfer objects with the power of php objects. No php attributes, no reflection api, and no other under the hook work.

Super Simple DTO Creating data transfer objects with the power of php objects. No php attributes, no reflection api, and no other under the hook work.

Mohammed Manssour 8 Jun 8, 2023
:globe_with_meridians: List of all countries with names and ISO 3166-1 codes in all languages and data formats.

symfony upgrade fixer • twig gettext extractor • wisdom • centipede • permissions handler • extraload • gravatar • locurro • country list • transliter

Saša Stamenković 5k Dec 22, 2022
A list of ICs and IPs for AI, Machine Learning and Deep Learning.

AI Chip (ICs and IPs) Editor S.T.(Linkedin) Welcome to My Wechat Blog StarryHeavensAbove for more AI chip related articles Latest updates Add news of

Shan Tang 1.4k Jan 3, 2023
World Currency list in PHP constants and in array (Currency::USD)

World Currency list in PHP constants and in array (Currency::USD) If you need to work with currencies in the code and describe each time "USD", "EUR"

Krepysh 4 Jun 27, 2022