-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the bug where the second compilation for Artisan commands fails
This is because Artisan commands are loaded when Laravel starts up, causing Ray.Aop's compiler to skip compilation.
- Loading branch information
Showing
11 changed files
with
209 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ngmy\LaravelAop\Tests\utils\Assertions; | ||
|
||
use Illuminate\Testing\PendingCommand; | ||
use Ngmy\LaravelAop\Tests\TestCase; | ||
|
||
/** | ||
* @require-extends TestCase | ||
*/ | ||
trait ArtisanAssertions | ||
{ | ||
/** | ||
* Assert the compile command. | ||
*/ | ||
protected function assertCompileCommand(): void | ||
{ | ||
$_SERVER['argv'] = ['artisan', 'aop:compile']; | ||
|
||
/** @var PendingCommand $command */ | ||
$command = $this->artisan('aop:compile'); | ||
$command->run(); | ||
$command->assertSuccessful(); | ||
|
||
/** @var string $compiledPath */ | ||
$compiledPath = config('aop.compiled'); | ||
|
||
self::assertDirectoryExists($compiledPath); | ||
} | ||
|
||
/** | ||
* Assert the watch command. | ||
*/ | ||
protected function assertWatchCommand(): void | ||
{ | ||
$_SERVER['argv'] = ['artisan', 'aop:watch']; | ||
|
||
/** @var PendingCommand $command */ | ||
$command = $this->artisan('aop:watch'); | ||
$command->run(); | ||
$command->expectsOutput('Watching...'); | ||
$command->assertSuccessful(); | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
tests/utils/Attributes/DoesNotDeleteCompiledDirectoryAfter.php
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,8 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ngmy\LaravelAop\Tests\utils\Attributes; | ||
|
||
#[\Attribute(\Attribute::TARGET_METHOD)] | ||
class DoesNotDeleteCompiledDirectoryAfter {} |
8 changes: 8 additions & 0 deletions
8
tests/utils/Attributes/DoesNotDeleteCompiledDirectoryBefore.php
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,8 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ngmy\LaravelAop\Tests\utils\Attributes; | ||
|
||
#[\Attribute(\Attribute::TARGET_METHOD)] | ||
class DoesNotDeleteCompiledDirectoryBefore {} |
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 Ngmy\LaravelAop\Tests\utils\Helpers; | ||
|
||
use Ngmy\LaravelAop\Tests\TestCase; | ||
use PHPUnit\Runner\Version; | ||
|
||
/** | ||
* @require-extends TestCase | ||
*/ | ||
trait AttributeHelpers | ||
{ | ||
/** | ||
* Get the attributes of the test method. | ||
* | ||
* @template T of object | ||
* | ||
* @param null|class-string<T> $name The name of the attribute | ||
* @param int $flags The flags to pass to ReflectionFunctionAbstract::getAttributes() | ||
* | ||
* @return list<\ReflectionAttribute<T>> The attributes of the test method | ||
*/ | ||
protected function getAttributes(?string $name = null, int $flags = 0): array | ||
{ | ||
$reflection = new \ReflectionClass($this); | ||
$method = $reflection->getMethod($this->_getName()); | ||
|
||
return $method->getAttributes($name, $flags); | ||
} | ||
|
||
/** | ||
* Whether the test method has the specified attributes. | ||
* | ||
* @param null|class-string $name The name of the attribute | ||
* @param int $flags The flags to pass to ReflectionFunctionAbstract::getAttributes() | ||
* | ||
* @return bool True if the test method has the specified attributes, false otherwise | ||
*/ | ||
protected function hasAttributes(?string $name = null, int $flags = 0): bool | ||
{ | ||
return !empty($this->getAttributes($name, $flags)); | ||
} | ||
|
||
/** | ||
* Get the name of the test method. | ||
* | ||
* @return string The name of the test method | ||
* | ||
* @todo Remove this method when PHPUnit 10 is the minimum required version | ||
*/ | ||
private function _getName(): string | ||
{ | ||
$version = (int) Version::id(); | ||
|
||
if ($version >= 10) { | ||
\assert(method_exists($this, 'name')); | ||
$methodName = $this->name(); | ||
} else { | ||
\assert(method_exists($this, 'getName')); | ||
$methodName = $this->getName(); | ||
} | ||
|
||
return $methodName; | ||
} | ||
} |
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