1
0
mirror of https://github.com/splitbrain/php-archive.git synced 2025-02-16 05:34:37 +01:00

updated testing

* test on github not travis
* run phpunit8 (tests only on 7.2+)
* use github action to build api docs
This commit is contained in:
Andreas Gohr 2021-02-05 13:30:53 +01:00
parent d4cf2d9a2d
commit d53bf2ed77
10 changed files with 84 additions and 91 deletions

21
.github/workflows/apigen.yml vendored Normal file

@ -0,0 +1,21 @@
name: ApiGen
on:
workflow_run:
workflows: ["Unit Tests"]
branches: [master]
types:
- completed
jobs:
Document_Generator:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: 📝 ApiGen PHP Document Generator
uses: varunsridharan/action-apigen@2.1
with:
cached_apigen: 'no'
source_folder: 'src'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

36
.github/workflows/test.yml vendored Normal file

@ -0,0 +1,36 @@
name: Unit Tests
on: [push, pull_request]
jobs:
run:
name: PHP ${{ matrix.php-versions }}
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
strategy:
matrix:
php-versions: ['7.2', '7.3', '7.4', '8.0']
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
- name: Setup problem matchers
run: |
echo ::add-matcher::${{ runner.tool_cache }}/php.json
echo ::add-matcher::${{ runner.tool_cache }}/phpunit.json
- name: Setup Dependencies
run: |
composer update
composer install
- name: Run PHPUnit
run: |
./vendor/bin/phpunit --verbose

3
.gitignore vendored

@ -5,4 +5,5 @@ vendor/
composer.lock composer.lock
apigen.phar apigen.phar
docs/ docs/
nbproject/ nbproject/
.phpunit.result.cache

@ -1,16 +0,0 @@
language: php
php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4
before_script:
- composer install
script: ./vendor/bin/phpunit
after_success:
- sh generate-api.sh
env:
global:
secure: ctCQVPQgQziwIZf5QGHcnhHlXsyauG0W3AWF/6R8cTP+in2S/RygunPp7CkXiqA1YMluGr2Lo9h4DTVg7oqeXl79FXFXedijQmQEu3g3f4iDWtxbQhGf4bJQk57jXFldge4rQedlOJDzwGzJ1abrimJQlu090BZNeonzWL5cRK4=

@ -6,8 +6,6 @@ needed for compression). It can create new files or extract existing ones.
To keep things simple, the modification (adding or removing files) of existing archives is not supported. To keep things simple, the modification (adding or removing files) of existing archives is not supported.
[![Build Status](https://travis-ci.org/splitbrain/php-archive.svg)](https://travis-ci.org/splitbrain/php-archive)
Install Install
------- -------

@ -20,7 +20,7 @@
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^4.8", "phpunit/phpunit": "^8",
"mikey179/vfsstream": "^1.6", "mikey179/vfsstream": "^1.6",
"ext-zip": "*", "ext-zip": "*",
"ext-bz2": "*" "ext-bz2": "*"

@ -7,8 +7,7 @@
convertNoticesToExceptions="true" convertNoticesToExceptions="true"
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="false" processIsolation="false"
stopOnFailure="false" stopOnFailure="false">
syntaxCheck="false">
<testsuites> <testsuites>
<testsuite name="Test Suite"> <testsuite name="Test Suite">
<directory suffix=".php">./tests/</directory> <directory suffix=".php">./tests/</directory>

@ -86,11 +86,9 @@ class FileInfoTest extends TestCase
$this->assertTrue($fileinfo->matchExpression('/bang/', '/bark/')); $this->assertTrue($fileinfo->matchExpression('/bang/', '/bark/'));
} }
/**
* @expectedException \PHPUnit_Framework_Error_Notice
*/
public function testMatchDeprecation() public function testMatchDeprecation()
{ {
$this->expectException(\PHPUnit\Framework\Error\Notice::class);
$fileinfo = new FileInfo('foo/bar/baz/bang'); $fileinfo = new FileInfo('foo/bar/baz/bang');
$fileinfo->match('/bang/', '/bark/'); $fileinfo->match('/bang/', '/bark/');
} }
@ -108,11 +106,9 @@ class FileInfoTest extends TestCase
$this->assertSame(0, $fileinfo->getSize()); $this->assertSame(0, $fileinfo->getSize());
} }
/**
* @expectedException \splitbrain\PHPArchive\FileInfoException
*/
public function testFromPathWithFileNotExisted() public function testFromPathWithFileNotExisted()
{ {
$this->expectException(\splitbrain\PHPArchive\FileInfoException::class);
FileInfo::fromPath('invalid_file_path'); FileInfo::fromPath('invalid_file_path');
} }
} }

@ -16,7 +16,7 @@ class TarTestCase extends TestCase
protected $extensions = array('tar'); protected $extensions = array('tar');
/** @inheritdoc */ /** @inheritdoc */
protected function setUp() protected function setUp() : void
{ {
parent::setUp(); parent::setUp();
if (extension_loaded('zlib')) { if (extension_loaded('zlib')) {
@ -31,7 +31,7 @@ class TarTestCase extends TestCase
} }
/** @inheritdoc */ /** @inheritdoc */
protected function tearDown() protected function tearDown() : void
{ {
parent::tearDown(); parent::tearDown();
$this->extensions[] = null; $this->extensions[] = null;
@ -62,11 +62,9 @@ class TarTestCase extends TestCase
$this->assertTrue(function_exists('bzopen')); $this->assertTrue(function_exists('bzopen'));
} }
/**
* @expectedException \splitbrain\PHPArchive\ArchiveIOException
*/
public function testTarFileIsNotExisted() public function testTarFileIsNotExisted()
{ {
$this->expectException(ArchiveIOException::class);
$tar = new Tar(); $tar = new Tar();
$tar->open('non_existed_file.tar'); $tar->open('non_existed_file.tar');
} }
@ -609,20 +607,16 @@ class TarTestCase extends TestCase
} }
} }
/**
* @expectedException \splitbrain\PHPArchive\ArchiveIOException
*/
public function testContentsWithInvalidArchiveStream() public function testContentsWithInvalidArchiveStream()
{ {
$this->expectException(ArchiveIOException::class);
$tar = new Tar(); $tar = new Tar();
$tar->contents(); $tar->contents();
} }
/**
* @expectedException \splitbrain\PHPArchive\ArchiveIOException
*/
public function testExtractWithInvalidOutDir() public function testExtractWithInvalidOutDir()
{ {
$this->expectException(ArchiveIOException::class);
$dir = dirname(__FILE__) . '/tar'; $dir = dirname(__FILE__) . '/tar';
$out = '/root/invalid_out_dir'; $out = '/root/invalid_out_dir';
@ -632,11 +626,9 @@ class TarTestCase extends TestCase
$tar->extract($out); $tar->extract($out);
} }
/**
* @expectedException \splitbrain\PHPArchive\ArchiveIOException
*/
public function testExtractWithArchiveStreamIsClosed() public function testExtractWithArchiveStreamIsClosed()
{ {
$this->expectException(ArchiveIOException::class);
$dir = dirname(__FILE__) . '/tar'; $dir = dirname(__FILE__) . '/tar';
$out = '/root/invalid_out_dir'; $out = '/root/invalid_out_dir';
@ -647,11 +639,9 @@ class TarTestCase extends TestCase
$tar->extract($out); $tar->extract($out);
} }
/**
* @expectedException \splitbrain\PHPArchive\ArchiveIOException
*/
public function testCreateWithInvalidFile() public function testCreateWithInvalidFile()
{ {
$this->expectException(ArchiveIOException::class);
$dir = dirname(__FILE__) . '/tar'; $dir = dirname(__FILE__) . '/tar';
$tar = new Tar(); $tar = new Tar();
@ -659,11 +649,9 @@ class TarTestCase extends TestCase
$tar->create('/root/invalid_file'); $tar->create('/root/invalid_file');
} }
/**
* @expectedException \splitbrain\PHPArchive\ArchiveIOException
*/
public function testAddFileWithArchiveStreamIsClosed() public function testAddFileWithArchiveStreamIsClosed()
{ {
$this->expectException(ArchiveIOException::class);
$archive = sys_get_temp_dir() . '/dwtartest' . md5(time()) . '.tar'; $archive = sys_get_temp_dir() . '/dwtartest' . md5(time()) . '.tar';
$tar = new Tar(); $tar = new Tar();
@ -672,11 +660,9 @@ class TarTestCase extends TestCase
$tar->addFile('archive_file', false); $tar->addFile('archive_file', false);
} }
/**
* @expectedException \splitbrain\PHPArchive\ArchiveIOException
*/
public function testAddFileWithInvalidFile() public function testAddFileWithInvalidFile()
{ {
$this->expectException(ArchiveIOException::class);
$archive = sys_get_temp_dir() . '/dwtartest' . md5(time()) . '.tar'; $archive = sys_get_temp_dir() . '/dwtartest' . md5(time()) . '.tar';
$tar = new Tar(); $tar = new Tar();
@ -684,11 +670,9 @@ class TarTestCase extends TestCase
$tar->addFile('archive_file', false); $tar->addFile('archive_file', false);
} }
/**
* @expectedException \splitbrain\PHPArchive\ArchiveIOException
*/
public function testAddDataWithArchiveStreamIsClosed() public function testAddDataWithArchiveStreamIsClosed()
{ {
$this->expectException(ArchiveIOException::class);
$archive = sys_get_temp_dir() . '/dwtartest' . md5(time()) . '.tar'; $archive = sys_get_temp_dir() . '/dwtartest' . md5(time()) . '.tar';
$tar = new Tar(); $tar = new Tar();
@ -721,7 +705,7 @@ class TarTestCase extends TestCase
$tar->addFile("$dir/zero.txt", 'zero.txt'); $tar->addFile("$dir/zero.txt", 'zero.txt');
$file = $tar->getArchive(); $file = $tar->getArchive();
$this->assertInternalType('string', $file); // 1 header block + 2 footer blocks $this->assertIsString($file); // 1 header block + 2 footer blocks
} }
public function testSaveWithCompressionAuto() public function testSaveWithCompressionAuto()
@ -736,11 +720,9 @@ class TarTestCase extends TestCase
$this->assertTrue(true); // succeed if no exception, yet $this->assertTrue(true); // succeed if no exception, yet
} }
/**
* @expectedException \splitbrain\PHPArchive\ArchiveIOException
*/
public function testSaveWithInvalidDestinationFile() public function testSaveWithInvalidDestinationFile()
{ {
$this->expectException(ArchiveIOException::class);
$dir = dirname(__FILE__) . '/tar'; $dir = dirname(__FILE__) . '/tar';
$tar = new Tar(); $tar = new Tar();
$tar->setCompression(); $tar->setCompression();

@ -11,7 +11,7 @@ class ZipTestCase extends TestCase
protected $counter = 0; protected $counter = 0;
/** @inheritdoc */ /** @inheritdoc */
protected function setUp() protected function setUp() : void
{ {
vfsStream::setup('home_root_path'); vfsStream::setup('home_root_path');
} }
@ -33,11 +33,9 @@ class ZipTestCase extends TestCase
$this->assertTrue(function_exists('zip_open')); $this->assertTrue(function_exists('zip_open'));
} }
/**
* @expectedException \splitbrain\PHPArchive\ArchiveIOException
*/
public function testMissing() public function testMissing()
{ {
$this->expectException(ArchiveIOException::class);
$tar = new Zip(); $tar = new Zip();
$tar->open('nope.zip'); $tar->open('nope.zip');
} }
@ -125,41 +123,29 @@ class ZipTestCase extends TestCase
$this->assertTrue(strpos($data, "foobar") === false, 'Path not in ZIP'); $this->assertTrue(strpos($data, "foobar") === false, 'Path not in ZIP');
} }
/**
* @expectedException \splitbrain\PHPArchive\ArchiveIOException
*/
public function testCreateWithInvalidFilePath() public function testCreateWithInvalidFilePath()
{ {
$this->expectException(ArchiveIOException::class);
$zip = new Zip(); $zip = new Zip();
$tmp = vfsStream::url('invalid_root_path/test.zip'); $tmp = vfsStream::url('invalid_root_path/test.zip');
$zip->create($tmp); $zip->create($tmp);
} }
/**
* @expectedException \splitbrain\PHPArchive\ArchiveIOException
*/
public function testAddFileWithArchiveStreamIsClosed() public function testAddFileWithArchiveStreamIsClosed()
{ {
$this->expectException(ArchiveIOException::class);
$zip = new Zip(); $zip = new Zip();
$dir = dirname(__FILE__) . '/zip'; $dir = dirname(__FILE__) . '/zip';
$zip->setCompression(0); $zip->setCompression(0);
$zip->close(); $zip->close();
$zip->addFile("$dir/testdata1.txt", "$dir/testdata1.txt"); $zip->addFile("$dir/testdata1.txt", "$dir/testdata1.txt");
} }
/**
* @expectedException \splitbrain\PHPArchive\ArchiveIOException
*/
public function testAddFileWithInvalidFile() public function testAddFileWithInvalidFile()
{ {
$this->expectException(ArchiveIOException::class);
$zip = new Zip(); $zip = new Zip();
$tmp = vfsStream::url('home_root_path/test.zip'); $tmp = vfsStream::url('home_root_path/test.zip');
$zip->create($tmp); $zip->create($tmp);
$zip->setCompression(0); $zip->setCompression(0);
$zip->addFile('invalid_file', false); $zip->addFile('invalid_file', false);
@ -188,16 +174,12 @@ class ZipTestCase extends TestCase
$this->assertEquals(13, $content[4]->getSize(), "Contents of $file"); $this->assertEquals(13, $content[4]->getSize(), "Contents of $file");
} }
/**
* @expectedException \splitbrain\PHPArchive\ArchiveIOException
*/
public function testZipContentWithArchiveStreamIsClosed() public function testZipContentWithArchiveStreamIsClosed()
{ {
$this->expectException(ArchiveIOException::class);
$dir = dirname(__FILE__) . '/zip'; $dir = dirname(__FILE__) . '/zip';
$zip = new Zip(); $zip = new Zip();
$file = "$dir/test.zip"; $file = "$dir/test.zip";
$zip->open($file); $zip->open($file);
$zip->close(); $zip->close();
$zip->contents(); $zip->contents();
@ -273,11 +255,9 @@ class ZipTestCase extends TestCase
unlink($archive); unlink($archive);
} }
/**
* @expectedException \splitbrain\PHPArchive\ArchiveIOException
*/
public function testAddDataWithArchiveStreamIsClosed() public function testAddDataWithArchiveStreamIsClosed()
{ {
$this->expectException(ArchiveIOException::class);
$archive = sys_get_temp_dir() . '/dwziptest' . md5(time()) . '.zip'; $archive = sys_get_temp_dir() . '/dwziptest' . md5(time()) . '.zip';
$zip = new Zip(); $zip = new Zip();
@ -310,11 +290,9 @@ class ZipTestCase extends TestCase
$this->assertTrue(true); // succeed if no exception, yet $this->assertTrue(true); // succeed if no exception, yet
} }
/**
* @expectedException \splitbrain\PHPArchive\ArchiveIOException
*/
public function testSaveWithInvalidFilePath() public function testSaveWithInvalidFilePath()
{ {
$this->expectException(ArchiveIOException::class);
$archive = sys_get_temp_dir() . '/dwziptest' . md5(time()) . '.zip'; $archive = sys_get_temp_dir() . '/dwziptest' . md5(time()) . '.zip';
$zip = new Zip(); $zip = new Zip();
@ -396,11 +374,9 @@ class ZipTestCase extends TestCase
self::RDelete($out); self::RDelete($out);
} }
/**
* @expectedException \splitbrain\PHPArchive\ArchiveIOException
*/
public function testZipExtractWithArchiveStreamIsClosed() public function testZipExtractWithArchiveStreamIsClosed()
{ {
$this->expectException(ArchiveIOException::class);
$dir = dirname(__FILE__) . '/zip'; $dir = dirname(__FILE__) . '/zip';
$out = sys_get_temp_dir() . '/dwziptest' . md5(time()); $out = sys_get_temp_dir() . '/dwziptest' . md5(time());