Skip to content

Commit

Permalink
Merge pull request #225 from sandervanhooft/remove_campbell_testbench
Browse files Browse the repository at this point in the history
Add Laravel 10 support, drop graham-campbell/testbench
  • Loading branch information
sandervanhooft authored Feb 16, 2023
2 parents a40783a + 8620564 commit 5e461cb
Show file tree
Hide file tree
Showing 15 changed files with 263 additions and 51 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand All @@ -35,4 +38,4 @@ jobs:
composer update --prefer-dist --no-interaction --no-progress
- name: Execute tests
run: vendor/bin/phpunit --verbose
run: vendor/bin/phpunit
15 changes: 7 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "^7.18|^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."
Expand Down
40 changes: 11 additions & 29 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
verbose="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
>
<coverage processUncoveredFiles="false">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Laravel Mollie Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" bootstrap="vendor/autoload.php" colors="true" failOnRisky="true" failOnWarning="true" processIsolation="false" stopOnError="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Laravel Mollie Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
</phpunit>
1 change: 0 additions & 1 deletion src/MollieConnectProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/MollieManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class MollieManager
/**
* MollieManager constructor.
*
* @param Container $app
* @return void
*/
public function __construct(Container $app)
Expand Down
3 changes: 0 additions & 3 deletions src/Wrappers/MollieApiWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ class MollieApiWrapper
/**
* MollieApiWrapper constructor.
*
* @param Repository $config
* @param MollieApiClient $client
* @return void
*
* @throws \Mollie\Api\Exceptions\ApiException
Expand Down Expand Up @@ -118,7 +116,6 @@ public function usesOAuth()
}

/**
* @param $version_string
* @return \Mollie\Laravel\Wrappers\MollieApiWrapper
*/
public function addVersionString($version_string)
Expand Down
2 changes: 1 addition & 1 deletion tests/Facades/MollieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/MollieConnectProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion tests/MollieServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
91 changes: 91 additions & 0 deletions tests/TempHelpers/FacadeTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

declare(strict_types=1);

namespace Mollie\Laravel\Tests\TempHelpers;

use Illuminate\Support\Facades\Facade;
use ReflectionClass;

trait FacadeTrait
{
/**
* Get the facade accessor.
*
* @return string
*/
abstract protected function getFacadeAccessor();

/**
* Get the facade class.
*
* @return string
*/
abstract protected function getFacadeClass();

/**
* Get the facade root.
*
* @return string
*/
abstract protected function getFacadeRoot();

/**
* Get the service provider class.
*
* @return string
*/
abstract protected function getServiceProviderClass();

public function testIsAFacade()
{
$class = $this->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);
}
}
}
67 changes: 67 additions & 0 deletions tests/TempHelpers/LaravelTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

declare(strict_types=1);

namespace Mollie\Laravel\Tests\TempHelpers;

use Illuminate\Support\Str;

trait LaravelTrait
{
/**
* Assert that a class can be automatically injected.
*
*
* @return void
*/
public function assertIsInjectable(string $name)
{
$injectable = true;

$message = "The class '$name' couldn't be automatically injected.";

try {
$class = $this->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.
*
*
* @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);
}
}
30 changes: 30 additions & 0 deletions tests/TempHelpers/MockeryTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace Mollie\Laravel\Tests\TempHelpers;

use Mockery;

trait MockeryTrait
{
/**
* Tear down mockery.
*
* @after
*
* @return void
*/
public function tearDownMockery()
{
if (class_exists(Mockery::class, false)) {
$container = Mockery::getContainer();

if ($container) {
$this->addToAssertionCount($container->mockery_getExpectationCount());
}

Mockery::close();
}
}
}
44 changes: 44 additions & 0 deletions tests/TempHelpers/ServiceProviderTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace Mollie\Laravel\Tests\TempHelpers;

use Illuminate\Support\ServiceProvider;
use ReflectionClass;

trait ServiceProviderTrait
{
/**
* Get the service provider class.
*
* @return string
*/
abstract protected function getServiceProviderClass();

public function testIsAServiceProvider()
{
$class = $this->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.";

$this->assertIsArray($method->invoke(new $class($this->app)), $msg);
}
}
Loading

0 comments on commit 5e461cb

Please sign in to comment.