diff --git a/.github/actions/setup-php/action.yml b/.github/actions/setup-php/action.yml new file mode 100644 index 0000000..075753c --- /dev/null +++ b/.github/actions/setup-php/action.yml @@ -0,0 +1,37 @@ +name: Setup PHP + +description: Set up PHP & Composer + +inputs: + php-version: + required: false + type: string + description: the php version to use, defaults to 8.2 + default: '8.2' + +runs: + using: composite + steps: + - name: PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "${{ inputs.php-version }}" + tools: composer + coverage: xdebug + ini-values: zend.assertions=1,assert.exception=1,xdebug.mode=coverage + + - name: composer cache + id: composercache + shell: bash + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: cache php dependencies + uses: actions/cache@v3 + with: + path: ${{ steps.composercache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ inputs.php-version }}-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer-${{ inputs.php-version }}- + + - name: install php dependencies + shell: bash + run: composer install --no-interaction --no-progress diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..fdfa616 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,30 @@ +name: test + +on: + push: + branches: + - "**" + +jobs: + test: + name: test + runs-on: "ubuntu-20.04" + + strategy: + matrix: + include: + - php-version: 8.0 + - php-version: 8.1 + - php-version: 8.2 + + steps: + - name: checkout + uses: actions/checkout@v3 + + - name: PHP + uses: ./.github/actions/setup-php + with: + php-version: "${{ matrix.php-version }}" + + - name: tests + run: ./vendor/bin/phpunit diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 2a96349..0000000 --- a/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -notifications: - email: false - -language: php - -php: - - '7.4' - - '8.0' - -install: composer install - -script: make diff --git a/README.md b/README.md index 7bc6d95..81ba23a 100644 --- a/README.md +++ b/README.md @@ -5,16 +5,6 @@ A few helpers to make reading and writing CSV (and other delimited files) a bit easier. -## A Quick Note on Line Endings - -This library is a thin wrapper around `SplFileObject`, so all the caveats for -using that come into play here. This includes line endings. Your best best may -be to set `auto_detect_line_endings = On` in your `php.ini` or use... - -```php -ini_set('auto_detect_line_endings', true) -``` - ## Reading CSV ```php diff --git a/composer.json b/composer.json index fed5f5e..2dc629b 100644 --- a/composer.json +++ b/composer.json @@ -7,15 +7,21 @@ { "name": "Christopher Davis", "email": "chris@pmg.com" } ], "require": { - "php": "^7.4 || ^8.0" + "php": "^8.0" }, "require-dev": { "phpunit/phpunit": "^9.5", - "mikey179/vfsstream": "^1.6" + "mikey179/vfsstream": "^1.6", + "symfony/phpunit-bridge": "^5.4" }, "autoload": { "psr-4": { "PMG\\CsvSugar\\": "src/" } + }, + "autoload-dev": { + "psr-4": { + "PMG\\CsvSugar\\": "test/" + } } } diff --git a/phpunit.xml b/phpunit.xml index 2c125b3..523f9d9 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -8,7 +8,7 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - bootstrap="test/bootstrap.php"> + bootstrap="vendor/autoload.php"> @@ -22,5 +22,13 @@ + + + + + + + + diff --git a/src/AbstractReader.php b/src/AbstractReader.php index 5f9ce65..075d4a7 100644 --- a/src/AbstractReader.php +++ b/src/AbstractReader.php @@ -11,6 +11,8 @@ namespace PMG\CsvSugar; +use Generator; + /** * ABC for readers. * @@ -34,11 +36,11 @@ public function __construct(string $filename, Dialect $dialect=null) $this->dialect = $dialect ?: Dialect::csv(); } - public function getIterator() : iterable + public function getIterator() : Generator { $fh = $this->openFile(); try { - return $this->readFile($fh); + yield from $this->readFile($fh); } finally { @fclose($fh); } diff --git a/test/ConfigurationTest.php b/test/ConfigurationTest.php index 4983fd6..ef3493d 100644 --- a/test/ConfigurationTest.php +++ b/test/ConfigurationTest.php @@ -12,11 +12,13 @@ class ConfigurationTest extends TestCase { + use Configuration; + public function testConfigureFileObjectChangesTheCsvControlForTheFileObjectBaseOnDialect() { $dialect = new Dialect('|', "'"); $fh = new \SplFileObject(__FILE__, 'r'); - Configuration::configureFileObject($fh, $dialect); + self::configureFileObject($fh, $dialect); list($delimiter, $enclosure) = $fh->getCsvControl(); $this->assertEquals('|', $delimiter); diff --git a/test/bootstrap.php b/test/bootstrap.php deleted file mode 100644 index 6d9ec78..0000000 --- a/test/bootstrap.php +++ /dev/null @@ -1,15 +0,0 @@ -. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -@ini_set('auto_detect_line_endings', true); - -$loader = require __DIR__.'/../vendor/autoload.php'; - -$loader->addPsr4('PMG\\CsvSugar\\', __DIR__);