Skip to content

Commit

Permalink
Replace Travis with GitHub Actions (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddeboer authored Mar 6, 2022
1 parent e2fe6dc commit 73c4408
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 88 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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 }}
27 changes: 0 additions & 27 deletions .travis.yml

This file was deleted.

5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@
"docs": "https://portphp.readthedocs.org"
},
"require": {
"portphp/portphp": "^1.2.0"
"portphp/portphp": "^1.6.0"
},
"autoload": {
"psr-4": {
"Port\\Csv\\": "src/"
}
},
"require-dev": {
"phpunit/phpunit": "^4.0",
"phpspec/phpspec": "^2.1"
"phpunit/phpunit": "^9.5"
},
"autoload-dev": {
"psr-4": {
Expand Down
5 changes: 0 additions & 5 deletions phpspec.yml.dist

This file was deleted.

33 changes: 19 additions & 14 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
verbose="true"
>
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="false"
beStrictAboutOutputDuringTests="true"
convertDeprecationsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
verbose="true">
<testsuites>
<testsuite name="portphp/csv">
<directory suffix=".php">./tests/</directory>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit>
33 changes: 7 additions & 26 deletions src/CsvReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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)) {
Expand Down Expand Up @@ -196,18 +192,15 @@ 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) {
$this->file->seek($this->headerRowNumber + 1);
}
}

/**
* {@inheritdoc}
*/
public function count()
public function count(): int
{
if (null === $this->count) {
$position = $this->key();
Expand All @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/CsvReaderFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
13 changes: 3 additions & 10 deletions tests/CsvReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/CsvWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
7 changes: 6 additions & 1 deletion tests/fixtures/data_blank_lines.csv
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
50,123,"Description"6,456,"Another description"7,7890,"Some more info"
50,123,"Description"
6,456,"Another description"
7,7890,"Some more info"



0 comments on commit 73c4408

Please sign in to comment.