-
-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test specific provider #86
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,30 @@ | ||
name: Test Bacon QR Code Provider | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
php-version: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php-version }} | ||
tools: composer | ||
coverage: xdebug | ||
ini-values: error_reporting=E_ALL | ||
|
||
- uses: ramsey/composer-install@v1 | ||
|
||
- run: composer require bacon/bacon-qr-code | ||
|
||
- run: composer lint | ||
- run: composer test testsDependency/BaconQRCodeTest.php |
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,24 @@ | ||
<?php | ||
|
||
namespace RobThree\Auth\Providers\Qr; | ||
|
||
trait HandlesDataUri | ||
{ | ||
/** | ||
* @param string $datauri | ||
* | ||
* @return null|array | ||
*/ | ||
private function DecodeDataUri($datauri) | ||
{ | ||
if (preg_match('/data:(?P<mimetype>[\w\.\-\+\/]+);(?P<encoding>\w+),(?P<data>.*)/', $datauri, $m) === 1) { | ||
return array( | ||
'mimetype' => $m['mimetype'], | ||
'encoding' => $m['encoding'], | ||
'data' => base64_decode($m['data']) | ||
); | ||
} | ||
|
||
return null; | ||
} | ||
} |
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,61 @@ | ||
<?php | ||
|
||
namespace TestsDependency; | ||
|
||
use BaconQrCode\Renderer\Image\ImagickImageBackEnd; | ||
use PHPUnit\Framework\TestCase; | ||
use RobThree\Auth\Providers\Qr\BaconQrCodeProvider; | ||
use RobThree\Auth\TwoFactorAuth; | ||
use RobThree\Auth\Providers\Qr\HandlesDataUri; | ||
|
||
class BaconQRCodeTest extends TestCase | ||
{ | ||
use HandlesDataUri; | ||
|
||
public function testDependency() | ||
{ | ||
// php < 7.1 will install an older Bacon QR Code | ||
if (! class_exists(ImagickImageBackEnd::class)) { | ||
$this->expectException(\RuntimeException::class); | ||
|
||
$qr = new BaconQrCodeProvider(1, '#000', '#FFF', 'svg'); | ||
} else { | ||
$qr = new BaconQrCodeProvider(1, '#000', '#FFF', 'svg'); | ||
|
||
$tfa = new TwoFactorAuth('Test&Issuer', 6, 30, 'sha1', $qr); | ||
|
||
$data = $this->DecodeDataUri($tfa->getQRCodeImageAsDataUri('Test&Label', 'VMR466AB62ZBOKHE')); | ||
$this->assertEquals('image/svg+xml', $data['mimetype']); | ||
} | ||
} | ||
|
||
public function testBadTextColour() | ||
{ | ||
$this->expectException(\RuntimeException::class); | ||
|
||
new BaconQrCodeProvider(1, 'not-a-colour', '#FFF'); | ||
} | ||
|
||
public function testBadBackgroundColour() | ||
{ | ||
$this->expectException(\RuntimeException::class); | ||
|
||
new BaconQrCodeProvider(1, '#000', 'not-a-colour'); | ||
} | ||
|
||
public function testBadTextColourHexRef() | ||
{ | ||
$this->expectException(\RuntimeException::class); | ||
|
||
new BaconQrCodeProvider(1, '#AAAA', '#FFF'); | ||
} | ||
|
||
public function testBadBackgroundColourHexRef() | ||
{ | ||
$this->expectException(\RuntimeException::class); | ||
|
||
new BaconQrCodeProvider(1, '#000', '#AAAA'); | ||
} | ||
|
||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just make it a dev dependency? Same with the other third-party libraries? They're necessary to run the full test suite, and would avoid having an independent workflow across all supported PHP versions for this one (or several) external dependencies? Within the dev dependencies, you then can also specify the range you wish to test against (e.g.
"bacon/bacon-qr-code": "^1 | ^2"
) and then within the composer install line pass--prefer-lowest
when testing against PHP 5.6, where^1
is only to test that the exception throws.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in reality, the end user would only install bacon or endroid so the tests should recreate that environment
also adding them both as development dependencies could get complicated as endroid relies on bacon