diff --git a/composer.json b/composer.json index ca82be8..bcb6bff 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/database/migrations/2018_03_11_141103_create_quick_books_tokens_table.php b/database/migrations/2018_03_11_141103_create_quick_books_tokens_table.php index 0d7af8b..999bcb9 100644 --- a/database/migrations/2018_03_11_141103_create_quick_books_tokens_table.php +++ b/database/migrations/2018_03_11_141103_create_quick_books_tokens_table.php @@ -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'); diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 18bcf37..8a0887f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,15 +8,11 @@ --> + stopOnFailure="false"> @@ -28,26 +24,13 @@ - - + + ./src - - ./src/Http/Exceptions - ./src/Providers - - - - - - - - - - + + + ./src/Http/Exceptions + ./src/Providers + + diff --git a/src/Http/Middleware/Filter.php b/src/Http/Middleware/Filter.php index 3399b91..357c69e 100644 --- a/src/Http/Middleware/Filter.php +++ b/src/Http/Middleware/Filter.php @@ -22,8 +22,7 @@ public function __construct( protected Redirector $redirector, protected Session $session, protected UrlGenerator $url_generator, - ) { - } + ) {} /** * Handle an incoming request. diff --git a/src/Providers/ClientServiceProvider.php b/src/Providers/ClientServiceProvider.php index 657fd74..d762d8c 100644 --- a/src/Providers/ClientServiceProvider.php +++ b/src/Providers/ClientServiceProvider.php @@ -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. */ diff --git a/src/Providers/ServiceProvider.php b/src/Providers/ServiceProvider.php index bae144b..5a17a53 100644 --- a/src/Providers/ServiceProvider.php +++ b/src/Providers/ServiceProvider.php @@ -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'); }); } diff --git a/src/Token.php b/src/Token.php index 0b75ba4..0b1548d 100644 --- a/src/Token.php +++ b/src/Token.php @@ -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 */ - 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. diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 9206da2..aa7f1a4 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -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 diff --git a/tests/HasQuickBooksTokenTest.php b/tests/HasQuickBooksTokenTest.php index 3920330..fcc0fb3 100644 --- a/tests/HasQuickBooksTokenTest.php +++ b/tests/HasQuickBooksTokenTest.php @@ -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()); } diff --git a/tests/Http/Controllers/ControllerTest.php b/tests/Http/Controllers/ControllerTest.php index 3df4311..95b57f0 100644 --- a/tests/Http/Controllers/ControllerTest.php +++ b/tests/Http/Controllers/ControllerTest.php @@ -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 diff --git a/tests/Http/Middleware/FilterTest.php b/tests/Http/Middleware/FilterTest.php index beb18e4..1843bfb 100644 --- a/tests/Http/Middleware/FilterTest.php +++ b/tests/Http/Middleware/FilterTest.php @@ -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 diff --git a/tests/TokenTest.php b/tests/TokenTest.php index 1db9418..44878f8 100644 --- a/tests/TokenTest.php +++ b/tests/TokenTest.php @@ -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());