Skip to content

Commit e95645f

Browse files
authored
Merge pull request #5 from bcremer/bump-php-compat
Introduce Github Actions / Increase minimum PHP Version
2 parents c3987a9 + 83d17ff commit e95645f

8 files changed

+113
-73
lines changed

.github/workflows/build.yaml

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
2+
# https://docs.github.com/en/actions
3+
4+
name: Build
5+
6+
on:
7+
pull_request:
8+
push:
9+
branches:
10+
- main
11+
12+
jobs:
13+
unit-tests:
14+
name: Tests
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
php-version:
19+
- 7.3
20+
- 7.4
21+
- 8.0
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v2
25+
26+
- name: Install PHP
27+
uses: shivammathur/setup-php@v2
28+
with:
29+
coverage: none
30+
php-version: ${{ matrix.php-version }}
31+
32+
- name: Determine composer cache directory
33+
id: determine-composer-cache-directory
34+
run: echo "::set-output name=directory::$(composer config cache-dir)"
35+
36+
- name: Cache dependencies installed with composer
37+
uses: actions/cache@v2
38+
with:
39+
path: ${{ steps.determine-composer-cache-directory.outputs.directory }}
40+
key: php-${{ matrix.php-version }}-composer-${{ hashFiles('composer.json') }}
41+
restore-keys: php-${{ matrix.php-version }}-composer-
42+
43+
- name: Install dependencies
44+
run: composer install --no-interaction --no-progress
45+
46+
- name: Run phpunit/phpunit
47+
run: vendor/bin/phpunit
48+
49+
tests-with-coverage:
50+
name: "Tests with coverage and PR Comments"
51+
runs-on: ubuntu-latest
52+
strategy:
53+
matrix:
54+
php-version:
55+
- 7.4
56+
steps:
57+
- name: Checkout
58+
uses: actions/checkout@v2
59+
60+
- name: Install PHP
61+
uses: shivammathur/setup-php@v2
62+
with:
63+
coverage: pcov
64+
php-version: ${{ matrix.php-version }}
65+
66+
- name: Setup problem matchers for PHP
67+
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
68+
69+
- name: Setup problem matchers for PHPUnit
70+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
71+
72+
- name: Determine composer cache directory
73+
id: determine-composer-cache-directory
74+
run: echo "::set-output name=directory::$(composer config cache-dir)"
75+
76+
- name: Cache dependencies installed with composer
77+
uses: actions/cache@v2
78+
with:
79+
path: ${{ steps.determine-composer-cache-directory.outputs.directory }}
80+
key: php-${{ matrix.php-version }}-composer-${{ hashFiles('composer.json') }}
81+
restore-keys: php-${{ matrix.php-version }}-composer-
82+
83+
- name: Install dependencies
84+
run: composer install --no-interaction --no-progress
85+
86+
- name: Run phpunit/phpunit with code coverage
87+
run: vendor/bin/phpunit --coverage-text --coverage-clover=clover.xml --coverage-xml=coverage/coverage.xml --log-junit=coverage/junit.xml
88+
89+
- name: Run infection
90+
run: vendor/bin/infection --threads=4 --min-msi=81 --min-covered-msi=81 --coverage=coverage

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ vendor
22
composer.lock
33
clover.xml
44
tests/testfile_*.txt
5-
ocular.phar
65
infection-log.txt
6+
.phpunit.result.cache

.scrutinizer.yml

-6
This file was deleted.

.travis.yml

-27
This file was deleted.

README.md

+3-10
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
[![Latest Version on Packagist][ico-version]][link-packagist]
44
[![Software License][ico-license]](LICENSE.md)
5-
[![Build Status][ico-travis]][link-travis]
6-
[![Coverage Status][ico-scrutinizer]][link-scrutinizer]
7-
[![Quality Score][ico-code-quality]][link-code-quality]
5+
[![Build Status][ico-ghactions]][link-ghactions]
86

97
LineReader is a library to read large files line by line in a memory efficient (constant) way.
108

@@ -131,11 +129,6 @@ The MIT License (MIT). Please see [License File](LICENSE) for more information.
131129

132130
[ico-version]: https://img.shields.io/packagist/v/bcremer/line-reader.svg?style=flat-square
133131
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
134-
[ico-travis]: https://img.shields.io/travis/bcremer/LineReader/master.svg?style=flat-square
135-
[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/bcremer/LineReader.svg?style=flat-square
136-
[ico-code-quality]: https://img.shields.io/scrutinizer/g/bcremer/LineReader.svg?style=flat-square
137-
138132
[link-packagist]: https://packagist.org/packages/bcremer/line-reader
139-
[link-travis]: https://travis-ci.org/bcremer/LineReader
140-
[link-scrutinizer]: https://scrutinizer-ci.com/g/bcremer/LineReader/code-structure
141-
[link-code-quality]: https://scrutinizer-ci.com/g/bcremer/LineReader
133+
[ico-ghactions]: https://github.com/bcremer/LineReader/workflows/Build/badge.svg
134+
[link-ghactions]: https://github.com/bcremer/LineReader/actions?query=workflow%3ABuild

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
}
1111
],
1212
"require": {
13-
"php": "~7.1|~7.2|~7.3"
13+
"php": "^7.3|^7.4|^8.0"
1414
},
1515
"require-dev": {
16-
"phpunit/phpunit": "^7.2",
17-
"infection/infection": "^0.9"
16+
"phpunit/phpunit": "^9.4",
17+
"infection/infection": "^0.18"
1818
},
1919
"autoload": {
2020
"psr-4": {

phpunit.xml.dist

+5-6
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@
1313
failOnWarning="true"
1414
colors="true"
1515
verbose="true">
16-
16+
<coverage>
17+
<include>
18+
<directory suffix=".php">./src</directory>
19+
</include>
20+
</coverage>
1721
<testsuite name="LineReader tests">
1822
<directory>tests</directory>
1923
</testsuite>
20-
<filter>
21-
<whitelist addUncoveredFilesFromWhitelist="true">
22-
<directory suffix=".php">./src</directory>
23-
</whitelist>
24-
</filter>
2524
</phpunit>

tests/LineReaderTest.php

+11-20
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class LineReaderTest extends TestCase
99
private static $maxLines;
1010
private static $testFile;
1111

12-
public static function setUpBeforeClass()
12+
public static function setUpBeforeClass(): void
1313
{
1414
self::$maxLines = (int)getenv('TEST_MAX_LINES') ?: 10000;
1515
self::$testFile = __DIR__.'/testfile_'.self::$maxLines.'.txt';
@@ -25,29 +25,23 @@ public static function setUpBeforeClass()
2525
fclose($fh);
2626
}
2727

28-
public function testCanNotBeInstantiated()
29-
{
30-
$this->expectException(\Error::class);
31-
new LineReader();
32-
}
33-
34-
public function testReadLinesThrowsException()
28+
public function testReadLinesThrowsException(): void
3529
{
3630
$this->expectException(\InvalidArgumentException::class);
3731
$this->expectExceptionMessage('Cannot open file for reading: /tmp/invalid-file.txt');
3832

3933
LineReader::readLines('/tmp/invalid-file.txt');
4034
}
4135

42-
public function testReadLinesBackwardsThrowsException()
36+
public function testReadLinesBackwardsThrowsException(): void
4337
{
4438
$this->expectException(\InvalidArgumentException::class);
4539
$this->expectExceptionMessage('Cannot open file for reading: /tmp/invalid-file.txt');
4640

4741
LineReader::readLinesBackwards('/tmp/invalid-file.txt');
4842
}
4943

50-
public function testReadsAllLines()
44+
public function testReadsAllLines(): void
5145
{
5246
$result = LineReader::readLines(self::$testFile);
5347

@@ -59,7 +53,7 @@ public function testReadsAllLines()
5953
$this->assertLines($result, $firstLine, $lastLine, $lineCount);
6054
}
6155

62-
public function testReadsLinesByStartline()
56+
public function testReadsLinesByStartline(): void
6357
{
6458
$lineGenerator = LineReader::readLines(self::$testFile);
6559
$lineGenerator = new \LimitIterator($lineGenerator, 50);
@@ -70,7 +64,7 @@ public function testReadsLinesByStartline()
7064
$this->assertLines($lineGenerator, $firstLine, $lastLine, $lineCount);
7165
}
7266

73-
public function testReadsLinesByLimit()
67+
public function testReadsLinesByLimit(): void
7468
{
7569
$lineGenerator = LineReader::readLines(self::$testFile);
7670
$lineGenerator = new \LimitIterator($lineGenerator, 50, 100);
@@ -81,7 +75,7 @@ public function testReadsLinesByLimit()
8175
$this->assertLines($lineGenerator, $firstLine, $lastLine, $lineCount);
8276
}
8377

84-
public function testReadsLinesBackwards()
78+
public function testReadsLinesBackwards(): void
8579
{
8680
$lineGenerator = LineReader::readLinesBackwards(self::$testFile);
8781

@@ -91,7 +85,7 @@ public function testReadsLinesBackwards()
9185
$this->assertLines($lineGenerator, $firstLine, $lastLine, $lineCount);
9286
}
9387

94-
public function testReadsLinesBackwardsWithOffsetAndLimit()
88+
public function testReadsLinesBackwardsWithOffsetAndLimit(): void
9589
{
9690
$lineGenerator = LineReader::readLinesBackwards(self::$testFile);
9791
$lineGenerator = new \LimitIterator($lineGenerator, 10, 50);
@@ -102,7 +96,7 @@ public function testReadsLinesBackwardsWithOffsetAndLimit()
10296
$this->assertLines($lineGenerator, $firstLine, $lastLine, $lineCount);
10397
}
10498

105-
public function testEmptyFile()
99+
public function testEmptyFile(): void
106100
{
107101
$testFile = __DIR__.'/testfile_empty.txt';
108102
$content = '';
@@ -115,7 +109,7 @@ public function testEmptyFile()
115109
self::assertSame([], iterator_to_array($lineGenerator));
116110
}
117111

118-
public function testFileWithLeadingAndTrailingNewlines()
112+
public function testFileWithLeadingAndTrailingNewlines(): void
119113
{
120114
$testFile = __DIR__.'/testfile_space.txt';
121115

@@ -166,11 +160,8 @@ public function testFileWithLeadingAndTrailingNewlines()
166160
* Runs the generator and asserts on first, last and the total line count
167161
*
168162
* @param \Traversable $generator
169-
* @param int $firstLine
170-
* @param int $lastLine
171-
* @param int $lineCount
172163
*/
173-
private function assertLines(\Traversable $generator, $firstLine, $lastLine, $lineCount)
164+
private function assertLines(\Traversable $generator, string $firstLine, int $lastLine, int $lineCount): void
174165
{
175166
$count = 0;
176167
$line = '';

0 commit comments

Comments
 (0)