generated from pestphp/pest-plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds
--without-exception-handling
and `without-deprecation-ha…
…ndling`
- Loading branch information
1 parent
8fc3221
commit b120301
Showing
10 changed files
with
158 additions
and
32 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
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,89 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Pest\Laravel; | ||
|
||
use Illuminate\Foundation\Testing\Concerns\InteractsWithDeprecationHandling; | ||
use Illuminate\Foundation\Testing\Concerns\InteractsWithExceptionHandling; | ||
use Pest\Contracts\Plugins\HandlesArguments; | ||
use Pest\Plugins\Concerns\HandleArguments; | ||
use Pest\TestSuite; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class Plugin implements HandlesArguments | ||
{ | ||
use HandleArguments; | ||
|
||
public function handleArguments(array $arguments): array | ||
{ | ||
if ($this->hasArgument('--with-exception-handling', $arguments)) { | ||
$arguments = $this->popArgument('--with-exception-handling', $arguments); | ||
|
||
$interactsWithExceptionHandling = function (TestCase $testCase): bool { | ||
return function_exists('trait_uses_recursive') && trait_uses_recursive($testCase, InteractsWithExceptionHandling::class); | ||
}; | ||
|
||
uses()->beforeEach(function () use ($interactsWithExceptionHandling) { | ||
/** @var TestCase $this */ | ||
if ($interactsWithExceptionHandling($this)) { | ||
/** @var TestCase&InteractsWithExceptionHandling $this */ | ||
$this->withExceptionHandling(); | ||
} | ||
})->in(TestSuite::getInstance()->rootPath); | ||
} | ||
|
||
if ($this->hasArgument('--without-exception-handling', $arguments)) { | ||
$arguments = $this->popArgument('--without-exception-handling', $arguments); | ||
|
||
$interactsWithExceptionHandling = function (TestCase $testCase): bool { | ||
return function_exists('trait_uses_recursive') && trait_uses_recursive($testCase, InteractsWithExceptionHandling::class); | ||
}; | ||
|
||
uses()->beforeEach(function () use ($interactsWithExceptionHandling) { | ||
/** @var TestCase $this */ | ||
if ($interactsWithExceptionHandling($this)) { | ||
/** @var TestCase&InteractsWithExceptionHandling $this */ | ||
$this->withoutExceptionHandling(); | ||
} | ||
})->in(TestSuite::getInstance()->rootPath); | ||
} | ||
|
||
if ($this->hasArgument('--with-deprecation-handling', $arguments)) { | ||
$arguments = $this->popArgument('--with-deprecation-handling', $arguments); | ||
|
||
$interactsWithDeprecationHandling = function (TestCase $testCase): bool { | ||
return function_exists('trait_uses_recursive') && trait_uses_recursive($testCase, InteractsWithDeprecationHandling::class); | ||
}; | ||
|
||
uses()->beforeEach(function () use ($interactsWithDeprecationHandling) { | ||
/** @var TestCase $this */ | ||
if ($interactsWithDeprecationHandling($this)) { | ||
/** @var TestCase&InteractsWithDeprecationHandling $this */ | ||
$this->withDeprecationHandling(); | ||
} | ||
})->in(TestSuite::getInstance()->rootPath); | ||
} | ||
|
||
if ($this->hasArgument('--without-deprecation-handling', $arguments)) { | ||
$arguments = $this->popArgument('--without-deprecation-handling', $arguments); | ||
|
||
$interactsWithDeprecationHandling = function (TestCase $testCase): bool { | ||
return function_exists('trait_uses_recursive') && trait_uses_recursive($testCase, InteractsWithDeprecationHandling::class); | ||
}; | ||
|
||
uses()->beforeEach(function () use ($interactsWithDeprecationHandling) { | ||
/** @var TestCase $this */ | ||
if ($interactsWithDeprecationHandling($this)) { | ||
/** @var TestCase&InteractsWithDeprecationHandling $this */ | ||
$this->withoutDeprecationHandling(); | ||
} | ||
})->in(TestSuite::getInstance()->rootPath); | ||
} | ||
|
||
return $arguments; | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Route; | ||
|
||
uses()->group('options'); | ||
|
||
test('--without-deprecation-handling', function () { | ||
Route::get('/exception', function () { | ||
str_replace(null, null, null); | ||
}); | ||
|
||
$this->get('/exception'); | ||
})->throws(Exception::class, 'str_replace(): Passing null to parameter #1 ($search) of type array|string is deprecated'); |
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,13 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Route; | ||
|
||
uses()->group('options'); | ||
|
||
test('--without-exception-handling', function () { | ||
Route::get('/exception', function () { | ||
throw new Exception('Exception message'); | ||
}); | ||
|
||
$this->get('/exception'); | ||
})->throws(Exception::class, 'Exception message'); |