-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
610 additions
and
50 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
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,20 @@ | ||
<?php | ||
|
||
return [ | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Default Concurrency Driver | ||
|-------------------------------------------------------------------------- | ||
| | ||
| This option determines the default concurrency driver that will be used | ||
| by Laravel's concurrency functions. By default, concurrent work will | ||
| be sent to isolated PHP processes which will return their results. | ||
| | ||
| Supported: "process", "fork", "sync" | ||
| | ||
*/ | ||
|
||
'driver' => env('CONCURRENCY_DRIVER', 'process'), | ||
|
||
]; |
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,92 @@ | ||
<?php | ||
|
||
namespace Orchestra\Testbench\Attributes; | ||
|
||
use Attribute; | ||
use Closure; | ||
use Illuminate\Support\Arr; | ||
use Illuminate\Support\Collection; | ||
use Illuminate\Support\Facades\DB; | ||
use InvalidArgumentException; | ||
use Orchestra\Testbench\Contracts\Attributes\Actionable as ActionableContract; | ||
|
||
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] | ||
final class RequiresDatabase implements ActionableContract | ||
{ | ||
/** | ||
* Construct a new attribute. | ||
* | ||
* @param string $driver | ||
* @param string|null $versionRequirement | ||
* @param string|null $connection | ||
* @param bool|null $default | ||
*/ | ||
public function __construct( | ||
public array|string $driver, | ||
public ?string $versionRequirement = null, | ||
public ?string $connection = null, | ||
public ?bool $default = null | ||
) { | ||
if (\is_null($connection) && \is_string($driver)) { | ||
$this->default = true; | ||
} | ||
|
||
if (\is_array($driver) && $default === true) { | ||
throw new InvalidArgumentException('Unable to validate default connection when given an array of database drivers'); | ||
} | ||
} | ||
|
||
/** | ||
* Handle the attribute. | ||
* | ||
* @param \Illuminate\Foundation\Application $app | ||
* @param \Closure(string, array<int, mixed>):void $action | ||
* @return void | ||
*/ | ||
public function handle($app, Closure $action): void | ||
{ | ||
$connection = DB::connection($this->connection); | ||
|
||
if ( | ||
($this->default ?? false) === true | ||
&& \is_string($this->driver) | ||
&& $connection->getDriverName() !== $this->driver | ||
) { | ||
\call_user_func($action, 'markTestSkipped', [\sprintf('Requires %s to configured for "%s" database connection', $this->driver, $connection->getName())]); | ||
|
||
return; | ||
} | ||
|
||
$drivers = Collection::make( | ||
Arr::wrap($this->driver) | ||
)->filter(fn ($driver) => $driver === $connection->getDriverName()); | ||
|
||
if ($drivers->isEmpty()) { | ||
\call_user_func( | ||
$action, | ||
'markTestSkipped', | ||
[\sprintf('Requires [%s] to be configured for "%s" database connection', Arr::join(Arr::wrap($this->driver), '/'), $connection->getName())] | ||
); | ||
|
||
return; | ||
} | ||
|
||
if ( | ||
is_string($this->driver) | ||
&& ! \is_null($this->versionRequirement) | ||
&& preg_match('/(?P<operator>[<>=!]{0,2})\s*(?P<version>[\d\.-]+(dev|(RC|alpha|beta)[\d\.])?)[ \t]*\r?$/m', $this->versionRequirement, $matches) | ||
) { | ||
if (empty($matches['operator'])) { | ||
$matches['operator'] = '>='; | ||
} | ||
|
||
if (! version_compare($connection->getServerVersion(), $matches['version'], $matches['operator'])) { | ||
\call_user_func( | ||
$action, | ||
'markTestSkipped', | ||
[\sprintf('Requires %s:%s to be configured for "%s" database connection', $this->driver, $this->versionRequirement, $connection->getName())] | ||
); | ||
} | ||
} | ||
} | ||
} |
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,36 @@ | ||
<?php | ||
|
||
namespace Orchestra\Testbench\Concerns; | ||
|
||
trait HandlesAssertions | ||
{ | ||
/** | ||
* Mark the test as skipped when condition is not equivalent to true. | ||
* | ||
* @param (\Closure($this): bool)|bool|null $condition | ||
* @param string $message | ||
* @return void | ||
*/ | ||
protected function markTestSkippedUnless($condition, string $message): void | ||
{ | ||
/** @phpstan-ignore argument.type */ | ||
if (! value($condition)) { | ||
$this->markTestSkipped($message); | ||
} | ||
} | ||
|
||
/** | ||
* Mark the test as skipped when condition is equivalent to true. | ||
* | ||
* @param (\Closure($this): bool)|bool|null $condition | ||
* @param string $message | ||
* @return void | ||
*/ | ||
protected function markTestSkippedWhen($condition, string $message): void | ||
{ | ||
/** @phpstan-ignore argument.type */ | ||
if (value($condition)) { | ||
$this->markTestSkipped($message); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.