-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #225 from sandervanhooft/remove_campbell_testbench
Add Laravel 10 support, drop graham-campbell/testbench
- Loading branch information
Showing
15 changed files
with
263 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.