-
-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dddfca2
commit d98e52e
Showing
7 changed files
with
102 additions
and
15 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: PHPUnit Tests on Multiple PHP Versions | ||
|
||
on: [ push ] | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
php: [ "7.1", "7.4", "8.0", "8.2" ] | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
extensions: zip, openssl | ||
|
||
- name: Install Composer dependencies | ||
run: composer install --prefer-dist --no-progress --no-interaction | ||
|
||
- name: Run PHPUnit | ||
run: vendor/bin/phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/vendor | ||
composer.lock | ||
/Certificates.p12 | ||
/Certificates.p12 | ||
.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php declare(strict_types=1); | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use PKPass\PKPass; | ||
|
||
final class BasicTest extends TestCase | ||
{ | ||
private function validatePass($pass, $expected_files = []) | ||
{ | ||
// basic string validation | ||
$this->assertIsString($pass); | ||
$this->assertGreaterThan(100, strlen($pass)); | ||
$this->assertStringContainsString('icon.png', $pass); | ||
$this->assertStringContainsString('manifest.json', $pass); | ||
|
||
// try to read the ZIP file | ||
$temp_name = tempnam(sys_get_temp_dir(), 'pkpass'); | ||
file_put_contents($temp_name, $pass); | ||
$zip = new ZipArchive(); | ||
$res = $zip->open($temp_name); | ||
$this->assertTrue($res, 'Invalid ZIP file.'); | ||
$this->assertEquals(count($expected_files), $zip->numFiles); | ||
|
||
// extract zip to temp dir | ||
$temp_dir = $temp_name . '_dir'; | ||
mkdir($temp_dir); | ||
$zip->extractTo($temp_dir); | ||
$zip->close(); | ||
echo $temp_dir; | ||
foreach ($expected_files as $file) { | ||
$this->assertFileExists($temp_dir . DIRECTORY_SEPARATOR . $file); | ||
} | ||
} | ||
|
||
public function testBasicGeneration() | ||
{ | ||
$pass = new PKPass(__DIR__ . '/fixtures/example-certificate.p12', 'password'); | ||
$data = [ | ||
'description' => 'Demo pass', | ||
'formatVersion' => 1, | ||
'organizationName' => 'Flight Express', | ||
'passTypeIdentifier' => 'pass.com.scholica.flights', // Change this! | ||
'serialNumber' => '12345678', | ||
'teamIdentifier' => 'KN44X8ZLNC', // Change this! | ||
'barcode' => [ | ||
'format' => 'PKBarcodeFormatQR', | ||
'message' => 'Flight-GateF12-ID6643679AH7B', | ||
'messageEncoding' => 'iso-8859-1', | ||
], | ||
'backgroundColor' => 'rgb(32,110,247)', | ||
'logoText' => 'Flight info', | ||
'relevantDate' => date('Y-m-d\TH:i:sP') | ||
]; | ||
$pass->setData($data); | ||
$pass->addFile(__DIR__ . '/fixtures/icon.png'); | ||
$value = $pass->create(); | ||
|
||
$this->validatePass($value, [ | ||
'icon.png', | ||
'manifest.json', | ||
'pass.json', | ||
'signature', | ||
]); | ||
} | ||
} |
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.