feat: add Laravel 11/12 and PHP 8.3+ support

- Widen illuminate/* deps to ^10.0|^11.0|^12.0, require PHP ^8.3
- Upgrade PHPUnit to ^10.5|^11.0, Mockery to ^1.6
- Rewrite phpunit.xml.dist for PHPUnit 10+ format (source/include
  replaces filter/whitelist, removed deprecated attributes)
- Replace $dates with $casts on Token model
- Implement DeferrableProvider interface instead of $defer property
  on ClientServiceProvider
- Use FQCN route definitions instead of string-based namespace()
- Fix migration getColumnType() check for Laravel 11+ native types
- Replace @test doc annotations with #[Test] attributes
- Fix dynamic property deprecation in ControllerTest
This commit is contained in:
Joel Male
2026-02-18 10:29:34 +10:00
parent 32f5c22846
commit 8ec2c3cc38
12 changed files with 86 additions and 157 deletions
+9 -9
View File
@@ -16,19 +16,19 @@
}
],
"require": {
"php": "^8.0.2",
"illuminate/database": "^10.0",
"illuminate/http": "^10.0",
"illuminate/routing": "^10.0",
"illuminate/support": "^10.0",
"nesbot/carbon": "^2.62.1",
"php": "^8.3",
"illuminate/database": "^10.0|^11.0|^12.0",
"illuminate/http": "^10.0|^11.0|^12.0",
"illuminate/routing": "^10.0|^11.0|^12.0",
"illuminate/support": "^10.0|^11.0|^12.0",
"nesbot/carbon": "^2.62.1|^3.0",
"quickbooks/v3-php-sdk": "^5.4.6"
},
"require-dev": {
"laravel/pint": "^1.2",
"mockery/mockery": "^1.5.1",
"phpunit/phpunit": "^9.3.3",
"psy/psysh": "^0.11",
"mockery/mockery": "^1.6",
"phpunit/phpunit": "^10.5|^11.0",
"psy/psysh": "^0.12",
"scrutinizer/ocular": "^1.9"
},
"autoload": {
@@ -15,10 +15,9 @@
public function up()
{
Schema::create('quickbooks_tokens', function (Blueprint $table) {
$user_id_type =
DB::getSchemaBuilder()->getColumnType('users', 'id') === 'bigint'
? 'unsignedBigInteger'
: 'unsignedInteger';
$user_id_type = str_contains(DB::getSchemaBuilder()->getColumnType('users', 'id'), 'bigint')
? 'unsignedBigInteger'
: 'unsignedInteger';
$table->bigIncrements('id');
$table->{$user_id_type}('user_id');
+10 -27
View File
@@ -8,15 +8,11 @@
-->
<phpunit backupGlobals="false"
backupStaticAttributes="false"
backupStaticProperties="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
verbose="true">
stopOnFailure="false">
<testsuites>
<testsuite name="Wearepixel's Laravel QuickBooks Client">
@@ -28,26 +24,13 @@
<!-- <env name="VARIABLE" value="value"/> -->
</php>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<source>
<include>
<directory suffix=".php">./src</directory>
<exclude>
<directory>./src/Http/Exceptions</directory>
<directory>./src/Providers</directory>
</exclude>
</whitelist>
</filter>
<logging>
<log type="coverage-html"
target="./build/phpunit/coverage"
lowUpperBound="35"
highLowerBound="70"/>
<log type="coverage-text"
target="php://stdout"
showOnlySummary="true"
showUncoveredFiles="false"/>
<log type="coverage-clover" target="build/phpunit/logs/clover.xml"/>
<log type="junit" target="./build/phpunit/logs/junit.xml"/>
</logging>
</include>
<exclude>
<directory>./src/Http/Exceptions</directory>
<directory>./src/Providers</directory>
</exclude>
</source>
</phpunit>
+1 -2
View File
@@ -22,8 +22,7 @@ public function __construct(
protected Redirector $redirector,
protected Session $session,
protected UrlGenerator $url_generator,
) {
}
) {}
/**
* Handle an incoming request.
+2 -6
View File
@@ -3,19 +3,15 @@
namespace Wearepixel\QuickBooks\Providers;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
use Wearepixel\QuickBooks\Client;
/**
* Class ClientServiceProvider
*/
class ClientServiceProvider extends LaravelServiceProvider
class ClientServiceProvider extends LaravelServiceProvider implements DeferrableProvider
{
/**
* Indicates if loading of the provider is deferred.
*/
protected bool $defer = true;
/**
* Get the services provided by the provider.
*/
+9 -8
View File
@@ -2,8 +2,8 @@
namespace Wearepixel\QuickBooks\Providers;
use Illuminate\Routing\Router;
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
use Wearepixel\QuickBooks\Http\Controllers\Controller;
use Wearepixel\QuickBooks\Http\Middleware\Filter;
/**
@@ -89,19 +89,20 @@ protected function registerRoutes(): void
->prefix($config['prefix'])
->as('quickbooks.')
->middleware($config['middleware']['default'])
->namespace('Wearepixel\QuickBooks\Http\Controllers')
->group(function (Router $router) use ($config) {
$router
->get($config['paths']['connect'], 'Controller@connect')
->group(function () use ($config) {
$this->app->router
->get($config['paths']['connect'], [Controller::class, 'connect'])
->middleware($config['middleware']['authenticated'])
->name('connect');
$router
->delete($config['paths']['disconnect'], 'Controller@disconnect')
$this->app->router
->delete($config['paths']['disconnect'], [Controller::class, 'disconnect'])
->middleware($config['middleware']['authenticated'])
->name('disconnect');
$router->get($config['paths']['token'], 'Controller@token')->name('token');
$this->app->router
->get($config['paths']['token'], [Controller::class, 'token'])
->name('token');
});
}
+6 -3
View File
@@ -34,11 +34,14 @@ class Token extends Model
protected $table = 'quickbooks_tokens';
/**
* The attributes that should be mutated to dates.
* The attributes that should be cast.
*
* @var array
* @var array<string, string>
*/
protected $dates = ['access_token_expires_at', 'refresh_token_expires_at'];
protected $casts = [
'access_token_expires_at' => 'datetime',
'refresh_token_expires_at' => 'datetime',
];
/**
* The attributes that are mass assignable.
+10 -27
View File
@@ -4,6 +4,7 @@
use Mockery;
use Mockery\Mock;
use PHPUnit\Framework\Attributes\Test;
use QuickBooksOnline\API\DataService\DataService;
use QuickBooksOnline\API\Exception\ServiceException;
@@ -53,17 +54,13 @@ private function makeClient($configs = null)
return new Client($this->configs, $this->token_mock);
}
/**
* @test
*/
#[Test]
public function it_can_be_constructed()
{
$this->assertInstanceOf(Client::class, $this->client);
}
/**
* @test
*/
#[Test]
public function it_returns_a_data_service_configured_to_request_oauth_token_when_token_is_empty()
{
$this->token_mock
@@ -86,9 +83,7 @@ public function it_returns_a_data_service_configured_to_request_oauth_token_when
);
}
/**
* @test
*/
#[Test]
public function it_caches_the_data_service_once_it_is_made()
{
$this->token_mock
@@ -107,9 +102,7 @@ public function it_caches_the_data_service_once_it_is_made()
$this->assertEquals(DataService::class, get_class($this->client->getDataService()));
}
/**
* @test
*/
#[Test]
public function it_returns_a_data_service_with_oauth_token_when_valid_access_token_exist()
{
$this->token_mock
@@ -144,9 +137,7 @@ public function it_returns_a_data_service_with_oauth_token_when_valid_access_tok
);
}
/**
* @test
*/
#[Test]
public function it_returns_a_data_service_with_refreshed_token_when_access_token_expired_but_refresh_token_valid()
{
$this->expectException(ServiceException::class);
@@ -189,9 +180,7 @@ public function it_returns_a_data_service_with_refreshed_token_when_access_token
);
}
/**
* @test
*/
#[Test]
public function it_returns_a_report_service_using_the_data_service()
{
$this->markTestSkipped(
@@ -199,9 +188,7 @@ public function it_returns_a_report_service_using_the_data_service()
);
}
/**
* @test
*/
#[Test]
public function it_has_logging_off_by_default()
{
$this->markTestSkipped('Have to figure out how to test this with the new code in 5.x');
@@ -227,9 +214,7 @@ public function it_has_logging_off_by_default()
);
}
/**
* @test
*/
#[Test]
public function it_allows_logging_turned_on_and_pointed_to_expected_file()
{
$this->markTestSkipped('Have to figure out how to test this with the new code in 5.x');
@@ -273,9 +258,7 @@ public function it_allows_logging_turned_on_and_pointed_to_expected_file()
);
}
/**
* @test
*/
#[Test]
public function it_returns_self_after_deleting_token()
{
$this->token_mock
+5 -8
View File
@@ -2,6 +2,7 @@
namespace Wearepixel\QuickBooks;
use PHPUnit\Framework\Attributes\Test;
use Wearepixel\QuickBooks\Stubs\User;
/**
@@ -18,21 +19,17 @@ protected function setUp(): void
{
parent::setUp();
$this->user = new User();
$this->user = new User;
}
/**
* @test
*/
#[Test]
public function it_can_be_constructed()
{
$this->assertInstanceOf(User::class, $this->user);
}
/**
* @test
*/
public function it_has_a_hasOne_relationship_to_token()
#[Test]
public function it_has_a_has_one_relationship_to_token()
{
$this->assertInstanceOf(Token::class, $this->user->quickBooksToken()->getModel());
}
+13 -17
View File
@@ -11,6 +11,7 @@
use Illuminate\Session\Store;
use Mockery;
use Mockery\Mock;
use PHPUnit\Framework\Attributes\Test;
use QuickBooksOnline\API\DataService\DataService;
use Wearepixel\QuickBooks\Client as QuickBooks;
use Wearepixel\QuickBooks\TestCase;
@@ -50,6 +51,11 @@ class ControllerTest extends TestCase
*/
protected $session_mock;
/**
* @var Mock
*/
protected $url_generator_mock;
/**
* @var Mock
*/
@@ -67,23 +73,20 @@ protected function setUp(): void
$this->redirector_mock = Mockery::mock(Redirector::class);
$this->request_mock = Mockery::mock(Request::class);
$this->session_mock = Mockery::mock(Store::class);
$this->url_generator_mock = Mockery::mock(UrlGenerator::class);
$this->view_factory_mock = Mockery::mock(ViewFactory::class);
$this->view_mock = Mockery::mock(View::class);
$this->controller = new Controller();
$this->controller = new Controller;
}
/**
* @test
*/
#[Test]
public function it_can_be_constructed()
{
$this->assertInstanceOf(Controller::class, $this->controller);
}
/**
* @test
*/
#[Test]
public function it_shows_view_to_connect_if_account_not_linked()
{
$this->data_service_mock
@@ -126,9 +129,7 @@ public function it_shows_view_to_connect_if_account_not_linked()
$this->controller->connect($this->quickbooks_mock, $this->view_factory_mock);
}
/**
* @test
*/
#[Test]
public function it_shows_view_to_disconnect_if_account_linked()
{
$this->quickbooks_mock
@@ -158,9 +159,7 @@ public function it_shows_view_to_disconnect_if_account_linked()
$this->controller->connect($this->quickbooks_mock, $this->view_factory_mock);
}
/**
* @test
*/
#[Test]
public function it_disconnects_from_quickbooks_when_requested()
{
$this->request_mock
@@ -192,12 +191,9 @@ public function it_disconnects_from_quickbooks_when_requested()
$this->assertInstanceOf(RedirectResponse::class, $result);
}
/**
* @test
*/
#[Test]
public function it_finishes_connecting_to_quickbooks_when_given_a_valid_token_by_quickbooks()
{
$this->url_generator_mock = Mockery::mock(UrlGenerator::class);
$realmId = random_int(1, 9999);
$this->quickbooks_mock
+4 -9
View File
@@ -8,6 +8,7 @@
use Illuminate\Routing\Redirector;
use Mockery;
use Mockery\Mock;
use PHPUnit\Framework\Attributes\Test;
use Wearepixel\QuickBooks\Client as QuickBooks;
use Wearepixel\QuickBooks\TestCase;
@@ -62,17 +63,13 @@ protected function setUp(): void
);
}
/**
* @test
*/
#[Test]
public function it_can_be_constructed()
{
$this->assertInstanceOf(Filter::class, $this->filter);
}
/**
* @test
*/
#[Test]
public function it_just_passes_the_request_to_the_next_middleware_if_account_linked_to_quickbooks()
{
$next_middleware = function ($request) {
@@ -88,9 +85,7 @@ public function it_just_passes_the_request_to_the_next_middleware_if_account_lin
$this->filter->handle($this->request_mock, $next_middleware);
}
/**
* @test
*/
#[Test]
public function it_redirects_to_quickbooks_connect_route_after_setting_intended_session_if_account_not_linked()
{
$this->request_mock
+14 -37
View File
@@ -5,6 +5,7 @@
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Mockery;
use PHPUnit\Framework\Attributes\Test;
use QuickBooksOnline\API\Core\OAuth\OAuth2\OAuth2AccessToken;
use Wearepixel\QuickBooks\Stubs\TokenStub;
use Wearepixel\QuickBooks\Stubs\User;
@@ -21,52 +22,40 @@ class TokenTest extends TestCase
protected function setUp(): void
{
$this->token = new TokenStub();
$this->token = new TokenStub;
}
/**
* @test
*/
#[Test]
public function it_can_be_constructed()
{
$this->assertInstanceOf(Token::class, $this->token);
}
/**
* @test
*/
#[Test]
public function it_has_accessor_for_valid_access_token()
{
$this->assertNotNull($this->token->getHasValidAccessTokenAttribute());
}
/**
* @test
*/
#[Test]
public function it_has_accessor_for_valid_refresh_token()
{
$this->assertNotNull($this->token->getHasValidRefreshTokenAttribute());
}
/**
* @test
*/
#[Test]
public function it_knows_that_the_access_token_expires_at_has_to_be_valid()
{
$this->assertFalse($this->token->getHasValidAccessTokenAttribute());
}
/**
* @test
*/
#[Test]
public function it_knows_that_the_refresh_token_expires_at_has_to_be_valid()
{
$this->assertFalse($this->token->getHasValidRefreshTokenAttribute());
}
/**
* @test
*/
#[Test]
public function it_know_if_access_token_expires_at_is_less_than_now_it_is_not_expired()
{
$now = Carbon::now();
@@ -77,9 +66,7 @@ public function it_know_if_access_token_expires_at_is_less_than_now_it_is_not_ex
$this->assertTrue($this->token->getHasValidAccessTokenAttribute());
}
/**
* @test
*/
#[Test]
public function it_know_if_refresh_token_expires_at_is_less_than_now_it_is_not_expired()
{
$now = Carbon::now();
@@ -90,9 +77,7 @@ public function it_know_if_refresh_token_expires_at_is_less_than_now_it_is_not_e
$this->assertTrue($this->token->getHasValidRefreshTokenAttribute());
}
/**
* @test
*/
#[Test]
public function it_know_if_access_token_expires_at_is_greater_than_or_equal_to_now_it_is_expired()
{
$now = Carbon::now();
@@ -107,9 +92,7 @@ public function it_know_if_access_token_expires_at_is_greater_than_or_equal_to_n
$this->assertFalse($this->token->getHasValidAccessTokenAttribute());
}
/**
* @test
*/
#[Test]
public function it_know_if_refresh_token_expires_at_is_greater_than_or_equal_to_now_it_is_expired()
{
$now = Carbon::now();
@@ -124,9 +107,7 @@ public function it_know_if_refresh_token_expires_at_is_greater_than_or_equal_to_
$this->assertFalse($this->token->getHasValidRefreshTokenAttribute());
}
/**
* @test
*/
#[Test]
public function it_stores_the_oauth_token_parts_in_expected_properties()
{
$oauth_token_mock = Mockery::mock(OAuth2AccessToken::class);
@@ -164,9 +145,7 @@ public function it_stores_the_oauth_token_parts_in_expected_properties()
$this->token->parseOauthToken($oauth_token_mock);
}
/**
* @test
*/
#[Test]
public function it_allows_itself_to_be_deleted_and_returns_new_token()
{
$this->token->user = Mockery::mock(User::class);
@@ -191,9 +170,7 @@ public function it_allows_itself_to_be_deleted_and_returns_new_token()
$this->assertEquals($token_mock, $this->token->remove());
}
/**
* @test
*/
#[Test]
public function it_get_related_user_model_from_configuration()
{
$this->assertInstanceOf(User::class, $this->token->user()->getModel());