diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..4f1ea42 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,53 @@ +name: Test + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + test: + strategy: + matrix: + php-versions: [ '7.4', '8.0', '8.1' ] + include: + - php-versions: '7.4' + coverage: pcov + composer-prefer: '--prefer-lowest --prefer-stable' + phpunit-flags: '--coverage-clover coverage.xml' + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + coverage: ${{ matrix.coverage }} + + - name: Validate composer.json and composer.lock + run: composer validate --strict + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v2 + with: + path: vendor + key: ${{ runner.os }}-composer-${{ matrix.composer-prefer }}$-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer-${{ matrix.composer-prefer }}- + + - name: Install dependencies + run: composer update --prefer-dist --no-progress ${{ matrix.composer-prefer }} + + - name: Run test suite + run: vendor/bin/phpunit ${{ matrix.phpunit-flags }} + + - name: Upload coverage + if: matrix.coverage + run: | + wget https://scrutinizer-ci.com/ocular.phar + php ocular.phar code-coverage:upload --format=php-clover coverage.xml --revision=${{ github.event.pull_request.head.sha || github.sha }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d111709..0000000 --- a/.travis.yml +++ /dev/null @@ -1,27 +0,0 @@ -dist: trusty - -language: php - -php: - - 5.6 - - 7.1 - - 7.2 - - 7.3 - -matrix: - include: - - php: 5.6 - env: - - COMPOSER_FLAGS="--prefer-lowest --prefer-stable" - - COVERAGE=true - - PHPUNIT_FLAGS="--coverage-clover=coverage.clover" - -install: - - travis_retry composer update ${COMPOSER_FLAGS} --prefer-source --no-interaction - -script: - - vendor/bin/phpunit ${PHPUNIT_FLAGS} - -after_script: - - if [[ "$COVERAGE" = true ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi - - if [[ "$COVERAGE" = true ]]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi diff --git a/composer.json b/composer.json index 48d2ed7..0b7f00f 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "docs": "https://portphp.readthedocs.org" }, "require": { - "portphp/portphp": "^1.2.0" + "portphp/portphp": "^1.6.0" }, "autoload": { "psr-4": { @@ -31,8 +31,7 @@ } }, "require-dev": { - "phpunit/phpunit": "^4.0", - "phpspec/phpspec": "^2.1" + "phpunit/phpunit": "^9.5" }, "autoload-dev": { "psr-4": { diff --git a/phpspec.yml.dist b/phpspec.yml.dist deleted file mode 100644 index 0da615e..0000000 --- a/phpspec.yml.dist +++ /dev/null @@ -1,5 +0,0 @@ -suites: - library_suite: - namespace: Port\Csv - psr4_prefix: Port\Csv -formatter.name: pretty diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3d8fe50..8766657 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,20 +1,25 @@ - - + cacheResultFile=".phpunit.cache/test-results" + executionOrder="depends,defects" + forceCoversAnnotation="false" + beStrictAboutOutputDuringTests="true" + convertDeprecationsToExceptions="true" + failOnRisky="true" + failOnWarning="true" + verbose="true"> - - ./tests/ + + tests + + + + src + + diff --git a/src/CsvReader.php b/src/CsvReader.php index c50871f..7423c30 100644 --- a/src/CsvReader.php +++ b/src/CsvReader.php @@ -81,8 +81,6 @@ class CsvReader implements CountableReader, \SeekableIterator */ public function __construct(\SplFileObject $file, $delimiter = ',', $enclosure = '"', $escape = '\\') { - ini_set('auto_detect_line_endings', true); - $this->file = $file; $this->file->setFlags( \SplFileObject::READ_CSV | @@ -101,10 +99,8 @@ public function __construct(\SplFileObject $file, $delimiter = ',', $enclosure = * Return the current row as an array * * If a header row has been set, an associative array will be returned - * - * @return array */ - public function current() + public function current(): ?array { // If the CSV has no column headers just return the line if (empty($this->columnHeaders)) { @@ -196,7 +192,7 @@ public function setHeaderRowNumber($rowNumber, $duplicates = null) * row. That way, when you iterate over the rows, that header row is * skipped. */ - public function rewind() + public function rewind(): void { $this->file->rewind(); if (null !== $this->headerRowNumber) { @@ -204,10 +200,7 @@ public function rewind() } } - /** - * {@inheritdoc} - */ - public function count() + public function count(): int { if (null === $this->count) { $position = $this->key(); @@ -220,34 +213,22 @@ public function count() return $this->count; } - /** - * {@inheritdoc} - */ - public function next() + public function next(): void { $this->file->next(); } - /** - * {@inheritdoc} - */ - public function valid() + public function valid(): bool { return $this->file->valid(); } - /** - * {@inheritdoc} - */ - public function key() + public function key(): int { return $this->file->key(); } - /** - * {@inheritdoc} - */ - public function seek($pointer) + public function seek($pointer): void { $this->file->seek($pointer); } diff --git a/tests/CsvReaderFactoryTest.php b/tests/CsvReaderFactoryTest.php index 15edd04..8d737df 100644 --- a/tests/CsvReaderFactoryTest.php +++ b/tests/CsvReaderFactoryTest.php @@ -2,9 +2,10 @@ namespace Port\Tests\Csv\Factory; +use PHPUnit\Framework\TestCase; use Port\Csv\CsvReaderFactory; -class CsvReaderFactoryTest extends \PHPUnit_Framework_TestCase +class CsvReaderFactoryTest extends TestCase { public function testGetReader() { diff --git a/tests/CsvReaderTest.php b/tests/CsvReaderTest.php index f60b000..acf04ae 100644 --- a/tests/CsvReaderTest.php +++ b/tests/CsvReaderTest.php @@ -2,9 +2,10 @@ namespace Port\Tests\Csv; +use PHPUnit\Framework\TestCase; use Port\Csv\CsvReader; -class CsvReaderTest extends \PHPUnit_Framework_TestCase +class CsvReaderTest extends TestCase { public function testReadCsvFileWithColumnHeaders() { @@ -182,17 +183,9 @@ public function testLastRowInvalidCsv() $this->assertEquals(array('strictly invalid'), current($errors)); } - public function testLineBreaks() - { - $reader = $this->getReader('data_cr_breaks.csv'); - $this->assertCount(3, $reader); - } - - /** - * @expectedException \Port\Exception\DuplicateHeadersException description - */ public function testDuplicateHeadersThrowsException() { + $this->expectException(\Port\Exception\DuplicateHeadersException::class); $reader = $this->getReader('data_column_headers_duplicates.csv'); $reader->setHeaderRowNumber(0); } diff --git a/tests/CsvWriterTest.php b/tests/CsvWriterTest.php index 72e93bb..6556ba9 100644 --- a/tests/CsvWriterTest.php +++ b/tests/CsvWriterTest.php @@ -3,7 +3,7 @@ namespace Port\Tests\Csv; use Port\Csv\CsvWriter; -use Port\Tests\Writer\StreamWriterTest; +use Port\Test\StreamWriterTest; class CsvWriterTest extends StreamWriterTest { diff --git a/tests/fixtures/data_blank_lines.csv b/tests/fixtures/data_blank_lines.csv index d9e9e5f..97c2cca 100644 --- a/tests/fixtures/data_blank_lines.csv +++ b/tests/fixtures/data_blank_lines.csv @@ -1 +1,6 @@ -50,123,"Description" 6,456,"Another description" 7,7890,"Some more info" \ No newline at end of file +50,123,"Description" +6,456,"Another description" +7,7890,"Some more info" + + +