diff --git a/.travis.yml b/.travis.yml
index ba19be3..b2bc460 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,4 +8,4 @@ install:
- export PATH="$HOME/.composer/vendor/bin:$PATH"
- composer install
-script: phpunit --coverage-text --configuration tests/phpunit.xml
+script: phpunit --coverage-text --configuration phpunit.xml
diff --git a/PHPGangsta/GoogleAuthenticator.php b/PHPGangsta/GoogleAuthenticator.php
index bf7d116..f333b82 100644
--- a/PHPGangsta/GoogleAuthenticator.php
+++ b/PHPGangsta/GoogleAuthenticator.php
@@ -1,5 +1,7 @@
_base32Decode($secret);
// Pack time into binary string
- $time = chr(0).chr(0).chr(0).chr(0).pack('N*', $timeSlice);
+ $time = chr(0) . chr(0) . chr(0) . chr(0) . pack('N*', $timeSlice);
// Hash it with users secret key
$hm = hash_hmac('SHA1', $time, $secretkey, true);
// Use last nipple of result as index/offset
@@ -100,13 +102,13 @@ public function getCode($secret, $timeSlice = null)
*/
public function getQRCodeGoogleUrl($name, $secret, $title = null, $params = array())
{
- $width = !empty($params['width']) && (int) $params['width'] > 0 ? (int) $params['width'] : 200;
- $height = !empty($params['height']) && (int) $params['height'] > 0 ? (int) $params['height'] : 200;
+ $width = !empty($params['width']) && (int)$params['width'] > 0 ? (int)$params['width'] : 200;
+ $height = !empty($params['height']) && (int)$params['height'] > 0 ? (int)$params['height'] : 200;
$level = !empty($params['level']) && array_search($params['level'], array('L', 'M', 'Q', 'H')) !== false ? $params['level'] : 'M';
- $urlencoded = urlencode('otpauth://totp/'.$name.'?secret='.$secret.'');
+ $urlencoded = urlencode('otpauth://totp/' . $name . '?secret=' . $secret . '');
if (isset($title)) {
- $urlencoded .= urlencode('&issuer='.urlencode($title));
+ $urlencoded .= urlencode('&issuer=' . urlencode($title));
}
return "https://api.qrserver.com/v1/create-qr-code/?data=$urlencoded&size=${width}x${height}&ecc=$level";
@@ -178,8 +180,10 @@ protected function _base32Decode($secret)
return false;
}
for ($i = 0; $i < 4; ++$i) {
- if ($paddingCharCount == $allowedValues[$i] &&
- substr($secret, -($allowedValues[$i])) != str_repeat($base32chars[32], $allowedValues[$i])) {
+ if (
+ $paddingCharCount == $allowedValues[$i] &&
+ substr($secret, -($allowedValues[$i])) != str_repeat($base32chars[32], $allowedValues[$i])
+ ) {
return false;
}
}
diff --git a/README.md b/README.md
index 0f86d21..87749f7 100644
--- a/README.md
+++ b/README.md
@@ -24,7 +24,7 @@ See following example:
createSecret();
echo "Secret is: ".$secret."\n\n";
@@ -64,15 +64,14 @@ Installation:
- [Composer](https://getcomposer.org/doc/01-basic-usage.md) will take care of autoloading
the library. Just include the following at the top of your file
- `require_once __DIR__ . '/../vendor/autoload.php';`
+ `require_once __DIR__ . '/vendor/autoload.php';`
Run Tests:
----------
- All tests are inside `tests` folder.
-- Execute `composer install` and then run the tests from project root
- directory
-- Run as `phpunit tests` from the project root directory
+- Execute `composer install`
+- Run as `./vendor/bin/phpunit` from the project root directory
ToDo:
diff --git a/composer.json b/composer.json
index 9de7cc1..acdd727 100644
--- a/composer.json
+++ b/composer.json
@@ -21,10 +21,11 @@
"php": ">=5.3"
},
"autoload": {
- "classmap": ["PHPGangsta/GoogleAuthenticator.php"]
- }
+ "psr-4": {
+ "PHPGangsta\\": "PHPGangsta/"
+ }
+ },
+ "require-dev": {
+ "phpunit/phpunit": "^8.1"
+ }
}
-
-
-
-
diff --git a/phpunit.xml b/phpunit.xml
new file mode 100644
index 0000000..c0c77df
--- /dev/null
+++ b/phpunit.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+ ./tests/
+
+
+
+
+
+ ./PHPGangsta/
+
+
+
diff --git a/tests/GoogleAuthenticatorTest.php b/tests/GoogleAuthenticatorTest.php
index 4e13b5c..f512e0b 100644
--- a/tests/GoogleAuthenticatorTest.php
+++ b/tests/GoogleAuthenticatorTest.php
@@ -1,15 +1,22 @@
googleAuthenticator = new PHPGangsta_GoogleAuthenticator();
+ $this->googleAuthenticator = new GoogleAuthenticator();
}
public function codeProvider()
@@ -24,9 +31,9 @@ public function codeProvider()
public function testItCanBeInstantiated()
{
- $ga = new PHPGangsta_GoogleAuthenticator();
+ $ga = new GoogleAuthenticator();
- $this->assertInstanceOf('PHPGangsta_GoogleAuthenticator', $ga);
+ $this->assertInstanceOf('PHPGangsta\GoogleAuthenticator', $ga);
}
public function testCreateSecretDefaultsToSixteenCharacters()
@@ -71,7 +78,7 @@ public function testGetQRCodeGoogleUrlReturnsCorrectUrl()
$this->assertEquals($urlParts['host'], 'api.qrserver.com');
$this->assertEquals($urlParts['path'], '/v1/create-qr-code/');
- $expectedChl = 'otpauth://totp/'.$name.'?secret='.$secret;
+ $expectedChl = 'otpauth://totp/' . $name . '?secret=' . $secret;
$this->assertEquals($queryStringArray['data'], $expectedChl);
}
@@ -97,7 +104,7 @@ public function testVerifyCodeWithLeadingZero()
$result = $this->googleAuthenticator->verifyCode($secret, $code);
$this->assertEquals(true, $result);
- $code = '0'.$code;
+ $code = '0' . $code;
$result = $this->googleAuthenticator->verifyCode($secret, $code);
$this->assertEquals(false, $result);
}
@@ -106,6 +113,6 @@ public function testSetCodeLength()
{
$result = $this->googleAuthenticator->setCodeLength(6);
- $this->assertInstanceOf('PHPGangsta_GoogleAuthenticator', $result);
+ $this->assertInstanceOf('PHPGangsta\GoogleAuthenticator', $result);
}
}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
deleted file mode 100644
index e91cc12..0000000
--- a/tests/bootstrap.php
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-
-
-
- ./
-
-
-
-
-
- src/
-
-
-