Skip to content

Commit 73c4408

Browse files
authored
Replace Travis with GitHub Actions (#8)
1 parent e2fe6dc commit 73c4408

File tree

10 files changed

+93
-88
lines changed

10 files changed

+93
-88
lines changed

.github/workflows/test.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
test:
11+
strategy:
12+
matrix:
13+
php-versions: [ '7.4', '8.0', '8.1' ]
14+
include:
15+
- php-versions: '7.4'
16+
coverage: pcov
17+
composer-prefer: '--prefer-lowest --prefer-stable'
18+
phpunit-flags: '--coverage-clover coverage.xml'
19+
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- uses: actions/checkout@v2
24+
25+
- name: Set up PHP
26+
uses: shivammathur/setup-php@v2
27+
with:
28+
php-version: ${{ matrix.php-versions }}
29+
coverage: ${{ matrix.coverage }}
30+
31+
- name: Validate composer.json and composer.lock
32+
run: composer validate --strict
33+
34+
- name: Cache Composer packages
35+
id: composer-cache
36+
uses: actions/cache@v2
37+
with:
38+
path: vendor
39+
key: ${{ runner.os }}-composer-${{ matrix.composer-prefer }}$-${{ hashFiles('**/composer.lock') }}
40+
restore-keys: |
41+
${{ runner.os }}-composer-${{ matrix.composer-prefer }}-
42+
43+
- name: Install dependencies
44+
run: composer update --prefer-dist --no-progress ${{ matrix.composer-prefer }}
45+
46+
- name: Run test suite
47+
run: vendor/bin/phpunit ${{ matrix.phpunit-flags }}
48+
49+
- name: Upload coverage
50+
if: matrix.coverage
51+
run: |
52+
wget https://scrutinizer-ci.com/ocular.phar
53+
php ocular.phar code-coverage:upload --format=php-clover coverage.xml --revision=${{ github.event.pull_request.head.sha || github.sha }}

.travis.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,15 @@
2323
"docs": "https://portphp.readthedocs.org"
2424
},
2525
"require": {
26-
"portphp/portphp": "^1.2.0"
26+
"portphp/portphp": "^1.6.0"
2727
},
2828
"autoload": {
2929
"psr-4": {
3030
"Port\\Csv\\": "src/"
3131
}
3232
},
3333
"require-dev": {
34-
"phpunit/phpunit": "^4.0",
35-
"phpspec/phpspec": "^2.1"
34+
"phpunit/phpunit": "^9.5"
3635
},
3736
"autoload-dev": {
3837
"psr-4": {

phpspec.yml.dist

Lines changed: 0 additions & 5 deletions
This file was deleted.

phpunit.xml.dist

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
3-
<phpunit backupGlobals="false"
4-
backupStaticAttributes="false"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
54
bootstrap="vendor/autoload.php"
6-
colors="true"
7-
convertErrorsToExceptions="true"
8-
convertNoticesToExceptions="true"
9-
convertWarningsToExceptions="true"
10-
processIsolation="false"
11-
stopOnFailure="false"
12-
syntaxCheck="false"
13-
verbose="true"
14-
>
5+
cacheResultFile=".phpunit.cache/test-results"
6+
executionOrder="depends,defects"
7+
forceCoversAnnotation="false"
8+
beStrictAboutOutputDuringTests="true"
9+
convertDeprecationsToExceptions="true"
10+
failOnRisky="true"
11+
failOnWarning="true"
12+
verbose="true">
1513
<testsuites>
16-
<testsuite name="portphp/csv">
17-
<directory suffix=".php">./tests/</directory>
14+
<testsuite name="default">
15+
<directory>tests</directory>
1816
</testsuite>
1917
</testsuites>
18+
19+
<coverage cacheDirectory=".phpunit.cache/code-coverage"
20+
processUncoveredFiles="true">
21+
<include>
22+
<directory suffix=".php">src</directory>
23+
</include>
24+
</coverage>
2025
</phpunit>

src/CsvReader.php

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ class CsvReader implements CountableReader, \SeekableIterator
8181
*/
8282
public function __construct(\SplFileObject $file, $delimiter = ',', $enclosure = '"', $escape = '\\')
8383
{
84-
ini_set('auto_detect_line_endings', true);
85-
8684
$this->file = $file;
8785
$this->file->setFlags(
8886
\SplFileObject::READ_CSV |
@@ -101,10 +99,8 @@ public function __construct(\SplFileObject $file, $delimiter = ',', $enclosure =
10199
* Return the current row as an array
102100
*
103101
* If a header row has been set, an associative array will be returned
104-
*
105-
* @return array
106102
*/
107-
public function current()
103+
public function current(): ?array
108104
{
109105
// If the CSV has no column headers just return the line
110106
if (empty($this->columnHeaders)) {
@@ -196,18 +192,15 @@ public function setHeaderRowNumber($rowNumber, $duplicates = null)
196192
* row. That way, when you iterate over the rows, that header row is
197193
* skipped.
198194
*/
199-
public function rewind()
195+
public function rewind(): void
200196
{
201197
$this->file->rewind();
202198
if (null !== $this->headerRowNumber) {
203199
$this->file->seek($this->headerRowNumber + 1);
204200
}
205201
}
206202

207-
/**
208-
* {@inheritdoc}
209-
*/
210-
public function count()
203+
public function count(): int
211204
{
212205
if (null === $this->count) {
213206
$position = $this->key();
@@ -220,34 +213,22 @@ public function count()
220213
return $this->count;
221214
}
222215

223-
/**
224-
* {@inheritdoc}
225-
*/
226-
public function next()
216+
public function next(): void
227217
{
228218
$this->file->next();
229219
}
230220

231-
/**
232-
* {@inheritdoc}
233-
*/
234-
public function valid()
221+
public function valid(): bool
235222
{
236223
return $this->file->valid();
237224
}
238225

239-
/**
240-
* {@inheritdoc}
241-
*/
242-
public function key()
226+
public function key(): int
243227
{
244228
return $this->file->key();
245229
}
246230

247-
/**
248-
* {@inheritdoc}
249-
*/
250-
public function seek($pointer)
231+
public function seek($pointer): void
251232
{
252233
$this->file->seek($pointer);
253234
}

tests/CsvReaderFactoryTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
namespace Port\Tests\Csv\Factory;
44

5+
use PHPUnit\Framework\TestCase;
56
use Port\Csv\CsvReaderFactory;
67

7-
class CsvReaderFactoryTest extends \PHPUnit_Framework_TestCase
8+
class CsvReaderFactoryTest extends TestCase
89
{
910
public function testGetReader()
1011
{

tests/CsvReaderTest.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
namespace Port\Tests\Csv;
44

5+
use PHPUnit\Framework\TestCase;
56
use Port\Csv\CsvReader;
67

7-
class CsvReaderTest extends \PHPUnit_Framework_TestCase
8+
class CsvReaderTest extends TestCase
89
{
910
public function testReadCsvFileWithColumnHeaders()
1011
{
@@ -182,17 +183,9 @@ public function testLastRowInvalidCsv()
182183
$this->assertEquals(array('strictly invalid'), current($errors));
183184
}
184185

185-
public function testLineBreaks()
186-
{
187-
$reader = $this->getReader('data_cr_breaks.csv');
188-
$this->assertCount(3, $reader);
189-
}
190-
191-
/**
192-
* @expectedException \Port\Exception\DuplicateHeadersException description
193-
*/
194186
public function testDuplicateHeadersThrowsException()
195187
{
188+
$this->expectException(\Port\Exception\DuplicateHeadersException::class);
196189
$reader = $this->getReader('data_column_headers_duplicates.csv');
197190
$reader->setHeaderRowNumber(0);
198191
}

tests/CsvWriterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Port\Tests\Csv;
44

55
use Port\Csv\CsvWriter;
6-
use Port\Tests\Writer\StreamWriterTest;
6+
use Port\Test\StreamWriterTest;
77

88
class CsvWriterTest extends StreamWriterTest
99
{
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
50,123,"Description"6,456,"Another description"7,7890,"Some more info"
1+
50,123,"Description"
2+
6,456,"Another description"
3+
7,7890,"Some more info"
4+
5+
6+

0 commit comments

Comments
 (0)