-
Notifications
You must be signed in to change notification settings - Fork 3
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
6 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
tests/Functional/AdviceBehavior/Include/Aspect/DatabaseModifierAspect.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,28 @@ | ||
<?php | ||
|
||
namespace Okapi\Aop\Tests\Functional\AdviceBehavior\Include\Aspect; | ||
|
||
use Okapi\Aop\Attributes\After; | ||
use Okapi\Aop\Attributes\Aspect; | ||
use Okapi\Aop\Invocation\AfterMethodInvocation; | ||
use Okapi\Aop\Tests\Functional\AdviceBehavior\Include\Target\SecureDatabaseService; | ||
|
||
#[Aspect] | ||
class DatabaseModifierAspect | ||
{ | ||
#[After( | ||
class: SecureDatabaseService::class, | ||
method: 'load', | ||
)] | ||
public function modifyData(AfterMethodInvocation $invocation): void | ||
{ | ||
/** @var SecureDatabaseService $subject */ | ||
$subject = $invocation->getSubject(); | ||
|
||
$subject->data = [ | ||
'd' => 4, | ||
'e' => 5, | ||
'f' => 6, | ||
]; | ||
} | ||
} |
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,7 @@ | ||
<?php | ||
|
||
return [ | ||
'a' => 1, | ||
'b' => 2, | ||
'c' => 3, | ||
]; |
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,41 @@ | ||
<?php | ||
|
||
namespace Okapi\Aop\Tests\Functional\AdviceBehavior\Include; | ||
|
||
use Okapi\Aop\Tests\ClassLoaderMockTrait; | ||
use Okapi\Aop\Tests\Functional\AdviceBehavior\Include\Aspect\DatabaseModifierAspect; | ||
use Okapi\Aop\Tests\Functional\AdviceBehavior\Include\Target\SecureDatabaseService; | ||
use Okapi\Aop\Tests\Util; | ||
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[RunTestsInSeparateProcesses] | ||
class IncludeTest extends TestCase | ||
{ | ||
use ClassLoaderMockTrait; | ||
|
||
/** | ||
* @see DatabaseModifierAspect::modifyData() | ||
*/ | ||
public function testIncludeFile(): void | ||
{ | ||
Util::clearCache(); | ||
Kernel::init(); | ||
|
||
$this->assertWillBeWoven(SecureDatabaseService::class); | ||
|
||
$service = new SecureDatabaseService(); | ||
$service->load(); | ||
|
||
$data = $service->getData(); | ||
|
||
$this->assertEquals( | ||
[ | ||
'd' => 4, | ||
'e' => 5, | ||
'f' => 6, | ||
], | ||
$data, | ||
); | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace Okapi\Aop\Tests\Functional\AdviceBehavior\Include; | ||
|
||
use Okapi\Aop\AopKernel; | ||
use Okapi\Aop\Tests\Functional\AdviceBehavior\Include\Aspect\DatabaseModifierAspect; | ||
use Okapi\Aop\Tests\Util; | ||
|
||
class Kernel extends AopKernel | ||
{ | ||
protected ?string $cacheDir = Util::CACHE_DIR; | ||
|
||
protected array $aspects = [ | ||
DatabaseModifierAspect::class, | ||
]; | ||
} |
26 changes: 26 additions & 0 deletions
26
tests/Functional/AdviceBehavior/Include/Target/SecureDatabaseService.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,26 @@ | ||
<?php | ||
|
||
namespace Okapi\Aop\Tests\Functional\AdviceBehavior\Include\Target; | ||
|
||
class SecureDatabaseService | ||
{ | ||
private ?array $data = null; | ||
|
||
public function load(): self | ||
{ | ||
if ($this->data === null) { | ||
$this->data = require dirname(__DIR__, 3) . '/AdviceBehavior/Include/Database/data.php'; | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function getData(): array | ||
{ | ||
if ($this->data === null) { | ||
$this->load(); | ||
} | ||
|
||
return $this->data; | ||
} | ||
} |
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