Skip to content

Commit 0443bcf

Browse files
authored
Merge pull request #23 from peter279k/test_enhancement
Test enhancement
2 parents 2a63b8c + d65719b commit 0443bcf

File tree

8 files changed

+431
-125
lines changed

8 files changed

+431
-125
lines changed

.travis.yml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
dist: trusty
21
language: php
3-
sudo: false
42
php:
5-
- 5.4
6-
- 5.5
7-
- 5.6
8-
- 7.0
9-
- 7.1
10-
- nightly
11-
- hhvm
3+
- 5.4
4+
- 5.5
5+
- 5.6
6+
- 7.0
7+
- 7.1
8+
- 7.2
9+
- nightly
10+
- hhvm
1211
before_script:
13-
- composer self-update
14-
- composer install --prefer-source --no-interaction --dev
12+
- composer install
1513
script: ./vendor/bin/phpunit
1614
after_success:
17-
- sh generate-api.sh
15+
- sh generate-api.sh
1816
env:
1917
global:
2018
secure: ctCQVPQgQziwIZf5QGHcnhHlXsyauG0W3AWF/6R8cTP+in2S/RygunPp7CkXiqA1YMluGr2Lo9h4DTVg7oqeXl79FXFXedijQmQEu3g3f4iDWtxbQhGf4bJQk57jXFldge4rQedlOJDzwGzJ1abrimJQlu090BZNeonzWL5cRK4=

composer.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"license": "MIT",
1212

1313
"require": {
14-
"php": ">=5.3.0"
14+
"php": ">=5.4"
1515
},
1616

1717
"suggest": {
@@ -20,12 +20,21 @@
2020
},
2121

2222
"require-dev": {
23-
"phpunit/phpunit": "4.5.*"
23+
"phpunit/phpunit": "^4.8",
24+
"mikey179/vfsStream": "^1.6",
25+
"ext-zip": "*",
26+
"ext-bz2": "*"
2427
},
2528

2629
"autoload": {
2730
"psr-4": {
2831
"splitbrain\\PHPArchive\\": "src"
2932
}
33+
},
34+
35+
"autoload-dev": {
36+
"psr-4": {
37+
"splitbrain\\PHPArchive\\": "tests"
38+
}
3039
}
3140
}

phpunit.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@
1414
<directory suffix=".php">./tests/</directory>
1515
</testsuite>
1616
</testsuites>
17-
</phpunit>
17+
<filter>
18+
<whitelist processUncoveredFilesFromWhitelist="false">
19+
<directory suffix=".php">src</directory>
20+
</whitelist>
21+
</filter>
22+
</phpunit>

src/Tar.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function extract($outdir, $strip = '', $exclude = '', $include = '')
164164

165165
// extract data
166166
if (!$fileinfo->getIsdir()) {
167-
$fp = fopen($output, "wb");
167+
$fp = @fopen($output, "wb");
168168
if (!$fp) {
169169
throw new ArchiveIOException('Could not open file for writing: '.$output);
170170
}
@@ -245,7 +245,7 @@ public function addFile($file, $fileinfo = '')
245245
throw new ArchiveIOException('Archive has been closed, files can no longer be added');
246246
}
247247

248-
$fp = fopen($file, 'rb');
248+
$fp = @fopen($file, 'rb');
249249
if (!$fp) {
250250
throw new ArchiveIOException('Could not open file for reading: '.$file);
251251
}
@@ -379,7 +379,7 @@ public function save($file)
379379
$this->setCompression($this->complevel, $this->filetype($file));
380380
}
381381

382-
if (!file_put_contents($file, $this->getArchive())) {
382+
if (!@file_put_contents($file, $this->getArchive())) {
383383
throw new ArchiveIOException('Could not write to file: '.$file);
384384
}
385385
}
@@ -433,7 +433,7 @@ protected function writebytes($data)
433433
*
434434
* @param int $bytes seek to this position
435435
*/
436-
function skipbytes($bytes)
436+
protected function skipbytes($bytes)
437437
{
438438
if ($this->comptype === Archive::COMPRESS_GZIP) {
439439
@gzseek($this->fh, $bytes, SEEK_CUR);
@@ -645,7 +645,7 @@ public function filetype($file)
645645
{
646646
// for existing files, try to read the magic bytes
647647
if(file_exists($file) && is_readable($file) && filesize($file) > 5) {
648-
$fh = fopen($file, 'rb');
648+
$fh = @fopen($file, 'rb');
649649
if(!$fh) return false;
650650
$magic = fread($fh, 5);
651651
fclose($fh);

src/Zip.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function contents()
111111
* @throws ArchiveIOException
112112
* @return FileInfo[]
113113
*/
114-
function extract($outdir, $strip = '', $exclude = '', $include = '')
114+
public function extract($outdir, $strip = '', $exclude = '', $include = '')
115115
{
116116
if ($this->closed || !$this->file) {
117117
throw new ArchiveIOException('Can not read from a closed archive');
@@ -163,7 +163,7 @@ function extract($outdir, $strip = '', $exclude = '', $include = '')
163163
}
164164

165165
// open file for writing
166-
$fp = fopen($extractto, "wb");
166+
$fp = @fopen($extractto, "wb");
167167
if (!$fp) {
168168
throw new ArchiveIOException('Could not open file for writing: '.$extractto);
169169
}
@@ -419,7 +419,7 @@ public function getArchive()
419419
*/
420420
public function save($file)
421421
{
422-
if (!file_put_contents($file, $this->getArchive())) {
422+
if (!@file_put_contents($file, $this->getArchive())) {
423423
throw new ArchiveIOException('Could not write to file: '.$file);
424424
}
425425
}

tests/FileInfo.test.php renamed to tests/FileInfoTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<?php
22

3+
namespace splitbrain\PHPArchive;
4+
35
use splitbrain\PHPArchive\FileInfo;
6+
use PHPUnit\Framework\TestCase;
47

5-
class FileInfoTest extends PHPUnit_Framework_TestCase
8+
class FileInfoTest extends TestCase
69
{
710

811
public function testDefaults()
@@ -96,4 +99,12 @@ public function testFromPath()
9699
$this->assertTrue($fileinfo->getIsdir());
97100
$this->assertSame(0, $fileinfo->getSize());
98101
}
99-
}
102+
103+
/**
104+
* @expectedException splitbrain\PHPArchive\FileInfoException
105+
*/
106+
public function testFromPathWithFileNotExisted()
107+
{
108+
$fileinfo = FileInfo::fromPath('invalid_file_path');
109+
}
110+
}

0 commit comments

Comments
 (0)