From 3ebc1620cf1ac4033aab937cb982d239f672eb28 Mon Sep 17 00:00:00 2001 From: Sander van Hooft Date: Thu, 16 Feb 2023 12:33:02 +0100 Subject: [PATCH 1/9] Green --- composer.json | 15 ++- tests/Facades/MollieTest.php | 2 +- tests/MollieConnectProviderTest.php | 2 +- tests/MollieServiceProviderTest.php | 2 +- tests/TempHelpers/FacadeTrait.php | 91 +++++++++++++++++++ tests/TempHelpers/LaravelTrait.php | 69 ++++++++++++++ tests/TempHelpers/MockeryTrait.php | 30 ++++++ tests/TempHelpers/ServiceProviderTrait.php | 49 ++++++++++ tests/TestCase.php | 6 +- tests/Wrappers/MollieApiLaravelClientTest.php | 1 - 10 files changed, 253 insertions(+), 14 deletions(-) create mode 100644 tests/TempHelpers/FacadeTrait.php create mode 100644 tests/TempHelpers/LaravelTrait.php create mode 100644 tests/TempHelpers/MockeryTrait.php create mode 100644 tests/TempHelpers/ServiceProviderTrait.php diff --git a/composer.json b/composer.json index 9530b0d..f587e61 100644 --- a/composer.json +++ b/composer.json @@ -42,17 +42,16 @@ ], "require": { "php": "^8.0", - "illuminate/support": "^8.0|^9.0", - "mollie/mollie-api-php": "^2.49", + "illuminate/support": "^9.0|^10.0", + "mollie/mollie-api-php": "^2.50", "ext-json": "*" }, "require-dev": { - "graham-campbell/testbench": "^5.0", - "mockery/mockery": "^1.0", - "phpunit/phpunit": "^9.0", - "laravel/socialite": "^5.0", - "laravel/pint": "^1.1", - "symfony/finder": "^5.0|^6.0" + "mockery/mockery": "^1.4", + "orchestra/testbench": "^8.0", + "phpunit/phpunit": "^9.0|^10.0", + "laravel/socialite": "^5.5", + "laravel/pint": "^1.1" }, "suggest": { "laravel/socialite": "Use Mollie Connect (OAuth) to authenticate via Laravel Socialite with the Mollie API. This is needed for some endpoints." diff --git a/tests/Facades/MollieTest.php b/tests/Facades/MollieTest.php index 1feff6b..5aff9f7 100644 --- a/tests/Facades/MollieTest.php +++ b/tests/Facades/MollieTest.php @@ -2,9 +2,9 @@ namespace Mollie\Laravel\Tests\Facades; -use GrahamCampbell\TestBenchCore\FacadeTrait; use Mollie\Laravel\Facades\Mollie; use Mollie\Laravel\MollieManager; +use Mollie\Laravel\Tests\TempHelpers\FacadeTrait; use Mollie\Laravel\Tests\TestCase; /** diff --git a/tests/MollieConnectProviderTest.php b/tests/MollieConnectProviderTest.php index aefb131..b1a3cf7 100644 --- a/tests/MollieConnectProviderTest.php +++ b/tests/MollieConnectProviderTest.php @@ -2,10 +2,10 @@ namespace Mollie\Laravel\Tests; -use GrahamCampbell\TestBenchCore\MockeryTrait; use Illuminate\Support\Facades\Request; use Mockery as m; use Mollie\Laravel\MollieConnectProvider; +use Mollie\Laravel\Tests\TempHelpers\MockeryTrait; class MollieConnectProviderTest extends TestCase { diff --git a/tests/MollieServiceProviderTest.php b/tests/MollieServiceProviderTest.php index 0d3a6e5..2fdffa0 100644 --- a/tests/MollieServiceProviderTest.php +++ b/tests/MollieServiceProviderTest.php @@ -2,9 +2,9 @@ namespace Mollie\Laravel\Tests; -use GrahamCampbell\TestBenchCore\ServiceProviderTrait; use Mollie\Api\MollieApiClient; use Mollie\Laravel\MollieManager; +use Mollie\Laravel\Tests\TempHelpers\ServiceProviderTrait; use Mollie\Laravel\Wrappers\MollieApiWrapper; /** diff --git a/tests/TempHelpers/FacadeTrait.php b/tests/TempHelpers/FacadeTrait.php new file mode 100644 index 0000000..5898837 --- /dev/null +++ b/tests/TempHelpers/FacadeTrait.php @@ -0,0 +1,91 @@ +getFacadeClass(); + $reflection = new ReflectionClass($class); + $facade = new ReflectionClass(Facade::class); + + $msg = "Expected class '$class' to be a facade."; + + $this->assertTrue($reflection->isSubclassOf($facade), $msg); + } + + public function testFacadeAccessor() + { + $accessor = $this->getFacadeAccessor(); + $class = $this->getFacadeClass(); + $reflection = new ReflectionClass($class); + $method = $reflection->getMethod('getFacadeAccessor'); + $method->setAccessible(true); + + $msg = "Expected class '$class' to have an accessor of '$accessor'."; + + $this->assertSame($accessor, $method->invoke(null), $msg); + } + + public function testFacadeRoot() + { + $root = $this->getFacadeRoot(); + $class = $this->getFacadeClass(); + $reflection = new ReflectionClass($class); + $method = $reflection->getMethod('getFacadeRoot'); + $method->setAccessible(true); + + $msg = "Expected class '$class' to have a root of '$root'."; + + $this->assertInstanceOf($root, $method->invoke(null), $msg); + } + + public function testServiceProvider() + { + $accessor = $this->getFacadeAccessor(); + $provider = $this->getServiceProviderClass($this->app); + + if ($provider) { + $reflection = new ReflectionClass($provider); + $method = $reflection->getMethod('provides'); + $method->setAccessible(true); + + $msg = "Expected class '$provider' to provide '$accessor'."; + $this->assertContains($accessor, $method->invoke(new $provider($this->app)), $msg); + } + } +} \ No newline at end of file diff --git a/tests/TempHelpers/LaravelTrait.php b/tests/TempHelpers/LaravelTrait.php new file mode 100644 index 0000000..0c790f6 --- /dev/null +++ b/tests/TempHelpers/LaravelTrait.php @@ -0,0 +1,69 @@ +makeInjectableClass($name); + $this->assertInstanceOf($name, $class->getInjectedObject()); + } catch (Exception $e) { + $injectable = false; + if ($msg = $e->getMessage()) { + $message .= " $msg"; + } + } + + $this->assertTrue($injectable, $message); + } + + /** + * Register and make a stub class to inject into. + * + * @param string $name + * + * @return object + */ + protected function makeInjectableClass(string $name) + { + do { + $class = 'testBenchStub'.Str::random(); + } while (class_exists($class)); + + eval(" + class $class + { + protected \$object; + + public function __construct(\\$name \$object) + { + \$this->object = \$object; + } + + public function getInjectedObject() + { + return \$this->object; + } + } + "); + + return $this->app->make($class); + } +} \ No newline at end of file diff --git a/tests/TempHelpers/MockeryTrait.php b/tests/TempHelpers/MockeryTrait.php new file mode 100644 index 0000000..51f6598 --- /dev/null +++ b/tests/TempHelpers/MockeryTrait.php @@ -0,0 +1,30 @@ +addToAssertionCount($container->mockery_getExpectationCount()); + } + + Mockery::close(); + } + } +} diff --git a/tests/TempHelpers/ServiceProviderTrait.php b/tests/TempHelpers/ServiceProviderTrait.php new file mode 100644 index 0000000..2b627d7 --- /dev/null +++ b/tests/TempHelpers/ServiceProviderTrait.php @@ -0,0 +1,49 @@ +getServiceProviderClass($this->app); + + $reflection = new ReflectionClass($class); + + $provider = new ReflectionClass(ServiceProvider::class); + + $msg = "Expected class '$class' to be a service provider."; + + $this->assertTrue($reflection->isSubclassOf($provider), $msg); + } + + public function testProvides() + { + $class = $this->getServiceProviderClass($this->app); + $reflection = new ReflectionClass($class); + + $method = $reflection->getMethod('provides'); + $method->setAccessible(true); + + $msg = "Expected class '$class' to provide a valid list of services."; + + if (is_callable([Assert::class, 'assertIsArray'])) { + $this->assertIsArray($method->invoke(new $class($this->app)), $msg); + } else { + $this->assertInternalType('array', $method->invoke(new $class($this->app)), $msg); + } + } +} \ No newline at end of file diff --git a/tests/TestCase.php b/tests/TestCase.php index ab08c30..a51058a 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,14 +2,16 @@ namespace Mollie\Laravel\Tests; -use GrahamCampbell\TestBench\AbstractPackageTestCase; use Mollie\Laravel\MollieServiceProvider; +use Mollie\Laravel\Tests\TempHelpers\LaravelTrait; /** * This is the abstract test case class. */ -abstract class TestCase extends AbstractPackageTestCase +abstract class TestCase extends \Orchestra\Testbench\TestCase { + use LaravelTrait; + /** * Get the service provider class. * diff --git a/tests/Wrappers/MollieApiLaravelClientTest.php b/tests/Wrappers/MollieApiLaravelClientTest.php index 952e6c0..60b730f 100644 --- a/tests/Wrappers/MollieApiLaravelClientTest.php +++ b/tests/Wrappers/MollieApiLaravelClientTest.php @@ -6,7 +6,6 @@ use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\Payment; use Mollie\Laravel\Tests\TestCase; -use Mollie\Laravel\Wrappers\MollieApiWrapper; /** * Class MollieApiWrapper From e4a1d9108f9baf33eb8e33df49f9c89ebcf68abc Mon Sep 17 00:00:00 2001 From: sandervanhooft Date: Thu, 16 Feb 2023 11:33:33 +0000 Subject: [PATCH 2/9] Fix styling --- src/MollieConnectProvider.php | 1 - src/MollieManager.php | 1 - src/Wrappers/MollieApiWrapper.php | 3 --- tests/TempHelpers/FacadeTrait.php | 2 +- tests/TempHelpers/LaravelTrait.php | 4 +--- tests/TempHelpers/ServiceProviderTrait.php | 2 +- 6 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/MollieConnectProvider.php b/src/MollieConnectProvider.php index 0173bc1..dd35e3a 100644 --- a/src/MollieConnectProvider.php +++ b/src/MollieConnectProvider.php @@ -169,7 +169,6 @@ protected function getUserByToken($token) /** * Map the raw user array to a Socialite User instance. * - * @param array $user * @return \Laravel\Socialite\AbstractUser */ protected function mapUserToObject(array $user) diff --git a/src/MollieManager.php b/src/MollieManager.php index 9337efe..12f76ca 100644 --- a/src/MollieManager.php +++ b/src/MollieManager.php @@ -48,7 +48,6 @@ class MollieManager /** * MollieManager constructor. * - * @param Container $app * @return void */ public function __construct(Container $app) diff --git a/src/Wrappers/MollieApiWrapper.php b/src/Wrappers/MollieApiWrapper.php index e0b4eb7..df2d710 100644 --- a/src/Wrappers/MollieApiWrapper.php +++ b/src/Wrappers/MollieApiWrapper.php @@ -55,8 +55,6 @@ class MollieApiWrapper /** * MollieApiWrapper constructor. * - * @param Repository $config - * @param MollieApiClient $client * @return void * * @throws \Mollie\Api\Exceptions\ApiException @@ -118,7 +116,6 @@ public function usesOAuth() } /** - * @param $version_string * @return \Mollie\Laravel\Wrappers\MollieApiWrapper */ public function addVersionString($version_string) diff --git a/tests/TempHelpers/FacadeTrait.php b/tests/TempHelpers/FacadeTrait.php index 5898837..5eb6466 100644 --- a/tests/TempHelpers/FacadeTrait.php +++ b/tests/TempHelpers/FacadeTrait.php @@ -88,4 +88,4 @@ public function testServiceProvider() $this->assertContains($accessor, $method->invoke(new $provider($this->app)), $msg); } } -} \ No newline at end of file +} diff --git a/tests/TempHelpers/LaravelTrait.php b/tests/TempHelpers/LaravelTrait.php index 0c790f6..e27a49c 100644 --- a/tests/TempHelpers/LaravelTrait.php +++ b/tests/TempHelpers/LaravelTrait.php @@ -11,7 +11,6 @@ trait LaravelTrait /** * Assert that a class can be automatically injected. * - * @param string $name * * @return void */ @@ -37,7 +36,6 @@ public function assertIsInjectable(string $name) /** * Register and make a stub class to inject into. * - * @param string $name * * @return object */ @@ -66,4 +64,4 @@ public function getInjectedObject() return $this->app->make($class); } -} \ No newline at end of file +} diff --git a/tests/TempHelpers/ServiceProviderTrait.php b/tests/TempHelpers/ServiceProviderTrait.php index 2b627d7..af70050 100644 --- a/tests/TempHelpers/ServiceProviderTrait.php +++ b/tests/TempHelpers/ServiceProviderTrait.php @@ -46,4 +46,4 @@ public function testProvides() $this->assertInternalType('array', $method->invoke(new $class($this->app)), $msg); } } -} \ No newline at end of file +} From 80d25a09448a0c917ed0b45f2b79cb7155f2e070 Mon Sep 17 00:00:00 2001 From: Sander van Hooft Date: Thu, 16 Feb 2023 12:42:42 +0100 Subject: [PATCH 3/9] wip --- tests/TempHelpers/ServiceProviderTrait.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/TempHelpers/ServiceProviderTrait.php b/tests/TempHelpers/ServiceProviderTrait.php index 2b627d7..d5beb11 100644 --- a/tests/TempHelpers/ServiceProviderTrait.php +++ b/tests/TempHelpers/ServiceProviderTrait.php @@ -5,7 +5,6 @@ namespace Mollie\Laravel\Tests\TempHelpers; use Illuminate\Support\ServiceProvider; -use PHPUnit\Framework\Assert; use ReflectionClass; trait ServiceProviderTrait @@ -40,10 +39,6 @@ public function testProvides() $msg = "Expected class '$class' to provide a valid list of services."; - if (is_callable([Assert::class, 'assertIsArray'])) { - $this->assertIsArray($method->invoke(new $class($this->app)), $msg); - } else { - $this->assertInternalType('array', $method->invoke(new $class($this->app)), $msg); - } + $this->assertIsArray($method->invoke(new $class($this->app)), $msg); } } \ No newline at end of file From 9cd6d7a1458710ddf06d2fd2a46b591a604fe228 Mon Sep 17 00:00:00 2001 From: Sander van Hooft Date: Thu, 16 Feb 2023 12:49:03 +0100 Subject: [PATCH 4/9] wip --- .github/workflows/tests.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6889d2d..d85181b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,8 +12,11 @@ jobs: strategy: fail-fast: true matrix: - php: ['8.0', 8.1, 8.2] - laravel: [8, 9] + php: ['8.0', '8.1', '8.2'] + laravel: ['9.0', '10.0'] + exclude: + - laravel: '10.0' + php: '8.0' name: P${{ matrix.php }} - L${{ matrix.laravel }} From fa3e7700509dee545c9e368e010efae88bb7b51f Mon Sep 17 00:00:00 2001 From: Sander van Hooft Date: Thu, 16 Feb 2023 12:50:02 +0100 Subject: [PATCH 5/9] wip --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f587e61..89b63f4 100644 --- a/composer.json +++ b/composer.json @@ -48,7 +48,7 @@ }, "require-dev": { "mockery/mockery": "^1.4", - "orchestra/testbench": "^8.0", + "orchestra/testbench": "^7.18|^8.0", "phpunit/phpunit": "^9.0|^10.0", "laravel/socialite": "^5.5", "laravel/pint": "^1.1" From 911bd03c7b6c0235bdaf7758e74dfa9cc79ae8ba Mon Sep 17 00:00:00 2001 From: Sander van Hooft Date: Thu, 16 Feb 2023 12:52:16 +0100 Subject: [PATCH 6/9] wip --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d85181b..122de3a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -38,4 +38,4 @@ jobs: composer update --prefer-dist --no-interaction --no-progress - name: Execute tests - run: vendor/bin/phpunit --verbose + run: vendor/bin/phpunit From f2af6e85a3cd16d2027796d61a495c0268f6da1d Mon Sep 17 00:00:00 2001 From: Sander van Hooft Date: Thu, 16 Feb 2023 12:58:15 +0100 Subject: [PATCH 7/9] wip --- .github/workflows/tests.yml | 4 ++++ phpunit.xml.dist | 40 ++++++++++--------------------------- phpunit.xml.dist.bak | 31 ++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 29 deletions(-) create mode 100644 phpunit.xml.dist.bak diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 122de3a..a825e73 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -37,5 +37,9 @@ jobs: composer require "illuminate/contracts=^${{ matrix.laravel }}" --no-update composer update --prefer-dist --no-interaction --no-progress + - name: Migrate test configuration + if: laravel == '10.0' + run: vendor/bin/phpunit --migrate-configuration + - name: Execute tests run: vendor/bin/phpunit diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5d8544b..1f20019 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,31 +1,13 @@ - - - - ./src - - - - - ./tests - - + + + + ./src + + + + + ./tests + + diff --git a/phpunit.xml.dist.bak b/phpunit.xml.dist.bak new file mode 100644 index 0000000..5d8544b --- /dev/null +++ b/phpunit.xml.dist.bak @@ -0,0 +1,31 @@ + + + + + ./src + + + + + ./tests + + + From 5c91798d59c5b913b9bb7a731014b3ccc0f3b008 Mon Sep 17 00:00:00 2001 From: Sander van Hooft Date: Thu, 16 Feb 2023 13:00:10 +0100 Subject: [PATCH 8/9] wip --- .github/workflows/tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a825e73..6da862f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -37,9 +37,9 @@ jobs: composer require "illuminate/contracts=^${{ matrix.laravel }}" --no-update composer update --prefer-dist --no-interaction --no-progress - - name: Migrate test configuration - if: laravel == '10.0' - run: vendor/bin/phpunit --migrate-configuration +# - name: Migrate test configuration +# if: ${{ matrix.laravel }} == '10.0' +# run: vendor/bin/phpunit --migrate-configuration - name: Execute tests run: vendor/bin/phpunit From 86205642d8df2caba4b8bb7fbaf8adc8098d734b Mon Sep 17 00:00:00 2001 From: Sander van Hooft Date: Thu, 16 Feb 2023 13:01:21 +0100 Subject: [PATCH 9/9] wip --- .github/workflows/tests.yml | 4 ---- phpunit.xml.dist.bak | 31 ------------------------------- 2 files changed, 35 deletions(-) delete mode 100644 phpunit.xml.dist.bak diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6da862f..122de3a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -37,9 +37,5 @@ jobs: composer require "illuminate/contracts=^${{ matrix.laravel }}" --no-update composer update --prefer-dist --no-interaction --no-progress -# - name: Migrate test configuration -# if: ${{ matrix.laravel }} == '10.0' -# run: vendor/bin/phpunit --migrate-configuration - - name: Execute tests run: vendor/bin/phpunit diff --git a/phpunit.xml.dist.bak b/phpunit.xml.dist.bak deleted file mode 100644 index 5d8544b..0000000 --- a/phpunit.xml.dist.bak +++ /dev/null @@ -1,31 +0,0 @@ - - - - - ./src - - - - - ./tests - - -