Skip to content

Commit

Permalink
Merge pull request #171 from storm-internet-services/lumen-9
Browse files Browse the repository at this point in the history
PHP 7.1 minimum version, Laravel 9 support
  • Loading branch information
dusterio authored Mar 28, 2022
2 parents c037dd3 + 9b736a2 commit 8b0a694
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 45 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor/
.idea/
composer.lock
.phpunit.result.cache
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ cache:
- $HOME/.composer/cache

php:
- '5.6'
- '7.0'
- '7.1'
- '8.1'

before_script:
- composer install --dev

script:
- ./vendor/bin/phpunit
- ./vendor/bin/test-reporter
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@
}
],
"require": {
"php": ">=5.6.4",
"illuminate/database": "~5.3|~5.4|~5.5|~5.6|^6.0|^7.0|^8.0",
"illuminate/support": "~5.3|~5.4|~5.5|~5.6|^6.0|^7.0|^8.0",
"php": ">=7.1",
"illuminate/database": "~5.3|~5.4|~5.5|~5.6|^6.0|^7.0|^8.0|^9.0",
"illuminate/support": "~5.3|~5.4|~5.5|~5.6|^6.0|^7.0|^8.0|^9.0",
"laravel/passport": ">=0.2.2",
"laminas/laminas-diactoros": "^2.4"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"phpunit/phpunit": "~5.0",
"codeclimate/php-test-reporter": "dev-master"
"fakerphp/faker": "^1.19",
"phpunit/phpunit": "^7.0|^8.0|^9.0"
},
"autoload": {
"psr-4": {
Expand Down
33 changes: 10 additions & 23 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>
<testsuites>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" bootstrap="tests/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Lumen Passport Test Suite">
<directory suffix=".php">tests/LumenPassport/</directory>
<directory suffix=".php">tests/LumenPassport/</directory>
</testsuite>
</testsuites>
<logging>
<log type="coverage-clover" target="build/logs/clover.xml" />
</logging>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</phpunit>
</testsuites>
</phpunit>
40 changes: 27 additions & 13 deletions tests/LumenPassport/integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,46 @@

namespace Dusterio\LumenPassport\Tests;

use Dusterio\LumenPassport\Http\Controllers\AccessTokenController;
use Dusterio\LumenPassport\LumenPassport;
use Carbon\Carbon;
use Laravel\Passport\Passport;
use Laravel\Passport\PassportServiceProvider;
use PHPUnit\Framework\TestCase;

/**
* Class IntegrationTest
* @package Dusterio\LumenPassport\Tests
*/
class IntegrationTest extends \PHPUnit_Framework_TestCase
class IntegrationTest extends TestCase
{

/**
* @test
*/
public function token_ttl_can_be_set_via_lumen_class()
public function global_token_ttl_can_be_set_via_lumen_class() {
$now = Carbon::now();
Carbon::setTestNow($now);
$expiryDate = $now->clone()->addYear();
LumenPassport::tokensExpireIn($expiryDate);
$this->assertEquals(Passport::tokensExpireIn(), Carbon::now()->diff($expiryDate));
$this->assertEquals(LumenPassport::tokensExpireIn(), Carbon::now()->diff($expiryDate));
}

/**
* @test
*/
public function client_specific_token_ttl_can_be_set_via_lumen_class()
{
// Default (global) client
LumenPassport::tokensExpireIn(Carbon::now()->addYears(1));
$this->assertTrue(Passport::tokensExpireIn() == Carbon::now()->diff(Carbon::now()->addYears(1)));
$this->assertTrue(LumenPassport::tokensExpireIn() == Carbon::now()->diff(Carbon::now()->addYears(1)));
$clientId = 2;
$now = Carbon::now();
Carbon::setTestNow($now);
$clientExpiryDate = $now->clone()->addYears(5);
$defaultGlobalExpiryDate = $now->clone()->addYears(1);

LumenPassport::tokensExpireIn($clientExpiryDate, $clientId);
$this->assertEquals(LumenPassport::tokensExpireIn(null, $clientId), Carbon::now()->diff($clientExpiryDate));

// Specific client
LumenPassport::tokensExpireIn(Carbon::now()->addYears(5), 2);
$this->assertTrue(LumenPassport::tokensExpireIn(null, 2) == Carbon::now()->diff(Carbon::now()->addYears(5)));
$this->assertTrue(LumenPassport::tokensExpireIn() == Carbon::now()->diff(Carbon::now()->addYears(1)));
$this->assertTrue(Passport::tokensExpireIn() == Carbon::now()->diff(Carbon::now()->addYears(1)));
# global TTL should still default to 1 year
$this->assertEquals(LumenPassport::tokensExpireIn(), Carbon::now()->diff($defaultGlobalExpiryDate));
$this->assertEquals(Passport::tokensExpireIn(), Carbon::now()->diff($defaultGlobalExpiryDate));
}
}

0 comments on commit 8b0a694

Please sign in to comment.