Skip to content

Commit a534ff1

Browse files
authored
Dev (#15)
* Cleanup. Additional tests for easier error-checking. * Travis build config update. * Fix for deprecated compression constant.
1 parent 8b388fa commit a534ff1

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
language: php
22

3-
sudo: false
3+
dist: xenial
4+
5+
os: linux
46

57
before_script:
68
- travis_retry composer self-update
@@ -9,7 +11,7 @@ before_script:
911
script:
1012
- composer test
1113

12-
matrix:
14+
jobs:
1315
include:
1416
- php: 7.1
1517
env:

src/Factories/Password.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace Olssonm\BackupShield\Factories;
44

55
use Illuminate\Support\Collection;
6-
76
use Olssonm\BackupShield\Encryption;
87
use PhpZip\ZipFile;
8+
use PhpZip\Constants\ZipCompressionMethod;
99
use \ZipArchive;
1010

1111
class Password
@@ -26,7 +26,9 @@ class Password
2626

2727
/**
2828
* Read the .zip, apply password and encryption, then rewrite the file
29-
* @param string $path the path to the .zip-file
29+
*
30+
* @param Encryption $encryption
31+
* @param string $path
3032
*/
3133
function __construct(Encryption $encryption, string $path)
3234
{
@@ -91,7 +93,7 @@ protected function makeZipFile(Encryption $encryption, string $path) : void
9193
);
9294

9395
$zipFile = new ZipFile();
94-
$zipFile->addFile($path, 'backup.zip', ZipFile::METHOD_DEFLATED);
96+
$zipFile->addFile($path, 'backup.zip', ZipCompressionMethod::DEFLATED);
9597
$zipFile->setPassword($this->password, $encryptionConstant);
9698
$zipFile->saveAsFile($path);
9799
$zipFile->close();

tests/BackupShieldTests.php

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public function setUp(): void
1616

1717
/**
1818
* Load the package
19+
*
1920
* @return array the packages
2021
*/
2122
protected function getPackageProviders($app)
@@ -26,7 +27,7 @@ protected function getPackageProviders($app)
2627
}
2728

2829
/** @test */
29-
public function test_config_file_is_installed()
30+
public function testConfigFileIsInstalled()
3031
{
3132
// Run the Installation command
3233
Artisan::call('vendor:publish', [
@@ -49,8 +50,10 @@ public function test_config_file_is_installed()
4950
$this->assertTrue($test2);
5051
}
5152

52-
/** @test */
53-
public function test_listener_return_data()
53+
/**
54+
* @depends testConfigFileIsInstalled
55+
*/
56+
public function testListenerReturnData()
5457
{
5558
// Set parameters for testing
5659
$path = __DIR__ . '/resources/test.zip';
@@ -68,8 +71,10 @@ public function test_listener_return_data()
6871
$this->assertEquals($pathTest, $data[0]);
6972
}
7073

71-
/** @test **/
72-
public function test_correct_encrypter_engine()
74+
/**
75+
* @depends testListenerReturnData
76+
*/
77+
public function testCorrectEncrypterEngine()
7378
{
7479
$path = __DIR__ . '/resources/processed.zip';
7580

@@ -87,8 +92,10 @@ public function test_correct_encrypter_engine()
8792
}
8893
}
8994

90-
/** @test **/
91-
public function test_encryption_protection()
95+
/**
96+
* @depends testCorrectEncrypterEngine
97+
*/
98+
public function testEncryptionProtection()
9299
{
93100
// Test that the archive actually is encrypted and password protected
94101
$path = __DIR__ . '/resources/processed.zip';
@@ -102,6 +109,19 @@ public function test_encryption_protection()
102109
$this->assertEquals(1, $zipInfo['backup.zip']->getEncryptionMethod());
103110
}
104111

112+
public function testRetrieveEncryptionConstants()
113+
{
114+
$encryption = new \Olssonm\BackupShield\Encryption();
115+
116+
// Default
117+
$this->assertEquals('257', $encryption->getEncryptionConstant(\Olssonm\BackupShield\Encryption::ENCRYPTION_DEFAULT, 'ZipArchive'));
118+
$this->assertEquals(\PhpZip\Constants\ZipEncryptionMethod::PKWARE, $encryption->getEncryptionConstant(\Olssonm\BackupShield\Encryption::ENCRYPTION_DEFAULT, 'ZipFile'));
119+
120+
// AES 256
121+
$this->assertEquals('259', $encryption->getEncryptionConstant(\Olssonm\BackupShield\Encryption::ENCRYPTION_WINZIP_AES_256, 'ZipArchive'));
122+
$this->assertEquals(\PhpZip\Constants\ZipEncryptionMethod::WINZIP_AES_256, $encryption->getEncryptionConstant(\Olssonm\BackupShield\Encryption::ENCRYPTION_WINZIP_AES_256, 'ZipFile'));
123+
}
124+
105125
/** Teardown */
106126
public static function tearDownAfterClass(): void
107127
{

0 commit comments

Comments
 (0)