feat: migrate test suite from PHPUnit to Pest

- Replace phpunit/phpunit with pestphp/pest ^3.0
- Drop scrutinizer/ocular (incompatible with Pest's symfony/console)
- Add tests/Pest.php with MockeryPHPUnitIntegration trait binding
- Extract namespace-level function stubs (config, route, dir) to
  tests/Overrides.php, loaded via autoload-dev files
- Convert all 5 test classes to Pest closure-based syntax:
  setUp() → beforeEach(), assertions → expect(), skip() for skipped tests
- Delete tests/TestCase.php (logic moved to Pest.php)
- Stubs (TokenStub, User) unchanged
This commit is contained in:
Joel Male
2026-02-18 10:38:20 +10:00
parent 8ec2c3cc38
commit 97c04ec693
9 changed files with 426 additions and 830 deletions
+59 -108
View File
@@ -1,128 +1,79 @@
<?php
namespace Wearepixel\QuickBooks\Http\Middleware;
use Illuminate\Contracts\Routing\UrlGenerator;
use Illuminate\Contracts\Session\Session;
use Illuminate\Http\Request;
use Illuminate\Routing\Redirector;
use Mockery;
use Mockery\Mock;
use PHPUnit\Framework\Attributes\Test;
use Wearepixel\QuickBooks\Client as QuickBooks;
use Wearepixel\QuickBooks\TestCase;
use Wearepixel\QuickBooks\Http\Middleware\Filter;
/**
* Class FilterTest
*/
class FilterTest extends TestCase
{
/**
* @var Filter
*/
protected $filter;
beforeEach(function () {
$this->quickbooks_mock = Mockery::mock(QuickBooks::class);
$this->redirector_mock = Mockery::mock(Redirector::class);
$this->request_mock = Mockery::mock(Request::class);
$this->session_mock = Mockery::mock(Session::class);
$this->url_generator_mock = Mockery::mock(UrlGenerator::class);
/**
* @var Mock
*/
protected $quickbooks_mock;
$this->filter = new Filter(
$this->quickbooks_mock,
$this->redirector_mock,
$this->session_mock,
$this->url_generator_mock,
);
});
/**
* @var Mock
*/
protected $redirector_mock;
it('can be constructed', function () {
expect($this->filter)->toBeInstanceOf(Filter::class);
});
/**
* @var Mock
*/
protected $request_mock;
it('passes the request to the next middleware if account linked to quickbooks', function () {
$next_middleware = function ($request) {
expect($request)->toBe($this->request_mock);
};
/**
* @var Mock
*/
protected $session_mock;
$this->quickbooks_mock
->shouldReceive('hasValidRefreshToken')
->once()
->withNoArgs()
->andReturnTrue();
/**
* @var Mock
*/
protected $url_generator_mock;
$this->filter->handle($this->request_mock, $next_middleware);
});
protected function setUp(): void
{
$this->quickbooks_mock = Mockery::mock(QuickBooks::class);
$this->redirector_mock = Mockery::mock(Redirector::class);
$this->request_mock = Mockery::mock(Request::class);
$this->session_mock = Mockery::mock(Session::class);
$this->url_generator_mock = Mockery::mock(UrlGenerator::class);
it('redirects to quickbooks connect route after setting intended session if account not linked', function () {
$this->request_mock
->shouldReceive('path')
->once()
->withNoArgs()
->andReturn('path');
$this->filter = new Filter(
$this->quickbooks_mock,
$this->redirector_mock,
$this->session_mock,
$this->url_generator_mock,
);
}
$this->url_generator_mock
->shouldReceive('to')
->once()
->with('path')
->andReturn('http://to/path');
#[Test]
public function it_can_be_constructed()
{
$this->assertInstanceOf(Filter::class, $this->filter);
}
$this->session_mock
->shouldReceive('put')
->once()
->withArgs(['url.intended', 'http://to/path'])
->andReturnNull();
#[Test]
public function it_just_passes_the_request_to_the_next_middleware_if_account_linked_to_quickbooks()
{
$next_middleware = function ($request) {
$this->assertEquals($this->request_mock, $request);
};
$this->redirector_mock
->shouldReceive('route')
->once()
->with('quickbooks.connect')
->andReturnSelf();
$this->quickbooks_mock
->shouldReceive('hasValidRefreshToken')
->once()
->withNoArgs()
->andReturnTrue();
$next_middleware = function ($request) {
throw new RuntimeException('Next middleware should not be called');
};
$this->filter->handle($this->request_mock, $next_middleware);
}
$this->quickbooks_mock
->shouldReceive('hasValidRefreshToken')
->once()
->withNoArgs()
->andReturnFalse();
#[Test]
public function it_redirects_to_quickbooks_connect_route_after_setting_intended_session_if_account_not_linked()
{
$this->request_mock
->shouldReceive('path')
->once()
->withNoArgs()
->andReturn('path');
$this->url_generator_mock
->shouldReceive('to')
->once()
->with('path')
->andReturn('http://to/path');
$this->session_mock
->shouldReceive('put')
->once()
->withArgs(['url.intended', 'http://to/path'])
->andReturnNull();
$this->redirector_mock
->shouldReceive('route')
->once()
->with('quickbooks.connect')
->andReturnSelf();
$next_middleware = function ($request) {
// If this is called, then fail test
$this->assertTrue(false);
};
$this->quickbooks_mock
->shouldReceive('hasValidRefreshToken')
->once()
->withNoArgs()
->andReturnFalse();
$this->filter->handle($this->request_mock, $next_middleware);
}
}
$this->filter->handle($this->request_mock, $next_middleware);
});