Skip to content

Commit

Permalink
tests: added provider any excel version
Browse files Browse the repository at this point in the history
  • Loading branch information
ddevsr committed Aug 14, 2024
1 parent 72bbbc0 commit e739dc3
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
fi
- name: Test with PHPUnit
run: vendor/bin/phpunit tests/ --coverage-text --coverage-clover build/logs/clover.xml --coverage-php build/cov/coverage.cov --testsuite main
run: vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml --coverage-php build/cov/coverage.cov --testsuite main
env:
TERM: xterm-256color
TACHYCARDIA_MONITOR_GA: enabled
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ tests/coverage*

# Don't save phpunit under version control.
phpunit
tests/_support/result/*
!tests/_support/result/.gitkeep

#-------------------------
# Composer
Expand Down
73 changes: 67 additions & 6 deletions tests/SecureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

namespace Tests;

use DateTimeImmutable;
use PHPDevsr\Spreadsheet\Secure;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

/**
Expand All @@ -24,20 +26,79 @@ final class SecureTest extends TestCase
*/
private static string $folderSupport = '';

/**
* Result of Test
*/
private static string $folderSupportResult = '';

protected function setUp(): void
{
self::$folderSupport = './tests/_support/';
self::$folderSupport = './tests/_support/';
self::$folderSupportResult = self::$folderSupport . 'result/';

if ($handlePath = opendir(self::$folderSupportResult)) {

Check failure on line 39 in tests/SecureTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 Static Analysis

Only booleans are allowed in an if condition, resource|false given.

Check failure on line 39 in tests/SecureTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Static Analysis

Only booleans are allowed in an if condition, resource|false given.

Check failure on line 39 in tests/SecureTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Static Analysis

Only booleans are allowed in an if condition, resource|false given.
$date = new DateTimeImmutable();

while (false !== ($file = readdir($handlePath))) {
if ($file === '.' || $file === '..' || $file === '.gitkeep') {
continue;
}

if (file_exists(self::$folderSupport . 'bb.xlsx')) {
unlink(self::$folderSupport . 'bb.xlsx');
$fileLastModified = filemtime(self::$folderSupportResult . $file);

if ($date->getTimestamp() > $fileLastModified && is_file(self::$folderSupportResult . $file)) {
unlink(self::$folderSupportResult . $file);
}
}

closedir($handlePath);
}
}

public static function testEncryptor(): void
public static function dataProviderExcel(): iterable

Check failure on line 58 in tests/SecureTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 Static Analysis

Method Tests\SecureTest::dataProviderExcel() return type has no value type specified in iterable type iterable.

Check failure on line 58 in tests/SecureTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Static Analysis

Method Tests\SecureTest::dataProviderExcel() return type has no value type specified in iterable type iterable.

Check failure on line 58 in tests/SecureTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Static Analysis

Method Tests\SecureTest::dataProviderExcel() return type has no value type specified in iterable type iterable.
{
yield from [
'Excel 2024' => [
'checkFiles' => 'excel2024.xlsx',
'expectedFiles' => 'excel2024_result.xlsx',
],
'Excel 2024 - Strict' => [
'checkFiles' => 'excel2024strict.xlsx',
'expectedFiles' => 'excel2024strict_result.xlsx',
],
'Excel Macro' => [
'checkFiles' => 'excelmacro.xlsm',
'expectedFiles' => 'excelmacro_result.xlsm',
],
'Excel Binary' => [
'checkFiles' => 'excelbinary.xlsb',
'expectedFiles' => 'excelbinary_result.xlsb',
],
'Excel 97-2003' => [
'checkFiles' => 'excel97.xls',
'expectedFiles' => 'excel97_result.xls',
],
'Excel 95' => [
'checkFiles' => 'excel95.xls',
'expectedFiles' => 'excel95_result.xls',
],
'CSV UTF-8' => [
'checkFiles' => 'csvutf8.csv',
'expectedFiles' => 'csvutf8_result.csv',
],
'CSV Unknown' => [
'checkFiles' => 'csvunknown.csv',
'expectedFiles' => 'csvunknown_result.csv',
],
];
}

#[DataProvider('dataProviderExcel')]
public static function testEncryptor(string $checkFiles = '', string $expectedFiles = ''): void
{
(new Secure())->setFile(self::$folderSupport . 'Book1.xlsx')->setPassword('111')->output(self::$folderSupport . 'bb.xlsx');
(new Secure())->setFile(self::$folderSupport . $checkFiles)->setPassword('111')->output(self::$folderSupportResult . $expectedFiles);

self::assertFileExists(self::$folderSupport . 'bb.xlsx');
self::assertFileExists(self::$folderSupportResult . $expectedFiles);
}

public static function testEncryptorWithBinaryData(): void
Expand Down
Empty file added tests/_support/.gitkeep
Empty file.
20 changes: 20 additions & 0 deletions tests/_support/csvunknown.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20
2;2;;;;;;;;;;;;;;;;;;
3;;3;;;;;;;;;;;;;;;;;
4;;;4;;;;;;;;;;;;;;;;
5;;;;5;;;;;;;;;;;;;;;
6;;;;;6;;;;;;;;;;;;;;
7;;;;;;7;;;;;;;;;;;;;
8;;;;;;;8;;;;;;;;;;;;
9;;;;;;;;9;;;;;;;;;;;
10;;;;;;;;;10;;;;;;;;;;
11;;;;;;;;;;11;;;;;;;;;
12;;;;;;;;;;;12;;;;;;;;
13;;;;;;;;;;;;13;;;;;;;
14;;;;;;;;;;;;;14;;;;;;
15;;;;;;;;;;;;;;15;;;;;
16;;;;;;;;;;;;;;;16;;;;
17;;;;;;;;;;;;;;;;17;;;
18;;;;;;;;;;;;;;;;;18;;
19;;;;;;;;;;;;;;;;;;19;
20;;;;;;;;;;;;;;;;;;;20
20 changes: 20 additions & 0 deletions tests/_support/csvutf8.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20
2;2;;;;;;;;;;;;;;;;;;
3;;3;;;;;;;;;;;;;;;;;
4;;;4;;;;;;;;;;;;;;;;
5;;;;5;;;;;;;;;;;;;;;
6;;;;;6;;;;;;;;;;;;;;
7;;;;;;7;;;;;;;;;;;;;
8;;;;;;;8;;;;;;;;;;;;
9;;;;;;;;9;;;;;;;;;;;
10;;;;;;;;;10;;;;;;;;;;
11;;;;;;;;;;11;;;;;;;;;
12;;;;;;;;;;;12;;;;;;;;
13;;;;;;;;;;;;13;;;;;;;
14;;;;;;;;;;;;;14;;;;;;
15;;;;;;;;;;;;;;15;;;;;
16;;;;;;;;;;;;;;;16;;;;
17;;;;;;;;;;;;;;;;17;;;
18;;;;;;;;;;;;;;;;;18;;
19;;;;;;;;;;;;;;;;;;19;
20;;;;;;;;;;;;;;;;;;;20
Binary file added tests/_support/excel2024.xlsx
Binary file not shown.
Binary file added tests/_support/excel2024strict.xlsx
Binary file not shown.
Binary file added tests/_support/excel95.xls
Binary file not shown.
Binary file added tests/_support/excel97.xls
Binary file not shown.
Binary file added tests/_support/excelbinary.xlsb
Binary file not shown.
Binary file added tests/_support/excelmacro.xlsm
Binary file not shown.

0 comments on commit e739dc3

Please sign in to comment.