File tree Expand file tree Collapse file tree 6 files changed +122
-0
lines changed
tests/Functional/AdviceBehavior Expand file tree Collapse file tree 6 files changed +122
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Okapi \Aop \Tests \Functional \AdviceBehavior \Include \Aspect ;
4+
5+ use Okapi \Aop \Attributes \After ;
6+ use Okapi \Aop \Attributes \Aspect ;
7+ use Okapi \Aop \Invocation \AfterMethodInvocation ;
8+ use Okapi \Aop \Tests \Functional \AdviceBehavior \Include \Target \SecureDatabaseService ;
9+
10+ #[Aspect]
11+ class DatabaseModifierAspect
12+ {
13+ #[After(
14+ class: SecureDatabaseService::class,
15+ method: 'load ' ,
16+ )]
17+ public function modifyData (AfterMethodInvocation $ invocation ): void
18+ {
19+ /** @var SecureDatabaseService $subject */
20+ $ subject = $ invocation ->getSubject ();
21+
22+ $ subject ->data = [
23+ 'd ' => 4 ,
24+ 'e ' => 5 ,
25+ 'f ' => 6 ,
26+ ];
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ return [
4+ 'a ' => 1 ,
5+ 'b ' => 2 ,
6+ 'c ' => 3 ,
7+ ];
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Okapi \Aop \Tests \Functional \AdviceBehavior \Include ;
4+
5+ use Okapi \Aop \Tests \ClassLoaderMockTrait ;
6+ use Okapi \Aop \Tests \Functional \AdviceBehavior \Include \Aspect \DatabaseModifierAspect ;
7+ use Okapi \Aop \Tests \Functional \AdviceBehavior \Include \Target \SecureDatabaseService ;
8+ use Okapi \Aop \Tests \Util ;
9+ use PHPUnit \Framework \Attributes \RunTestsInSeparateProcesses ;
10+ use PHPUnit \Framework \TestCase ;
11+
12+ #[RunTestsInSeparateProcesses]
13+ class IncludeTest extends TestCase
14+ {
15+ use ClassLoaderMockTrait;
16+
17+ /**
18+ * @see DatabaseModifierAspect::modifyData()
19+ */
20+ public function testIncludeFile (): void
21+ {
22+ Util::clearCache ();
23+ Kernel::init ();
24+
25+ $ this ->assertWillBeWoven (SecureDatabaseService::class);
26+
27+ $ service = new SecureDatabaseService ();
28+ $ service ->load ();
29+
30+ $ data = $ service ->getData ();
31+
32+ $ this ->assertEquals (
33+ [
34+ 'd ' => 4 ,
35+ 'e ' => 5 ,
36+ 'f ' => 6 ,
37+ ],
38+ $ data ,
39+ );
40+ }
41+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Okapi \Aop \Tests \Functional \AdviceBehavior \Include ;
4+
5+ use Okapi \Aop \AopKernel ;
6+ use Okapi \Aop \Tests \Functional \AdviceBehavior \Include \Aspect \DatabaseModifierAspect ;
7+ use Okapi \Aop \Tests \Util ;
8+
9+ class Kernel extends AopKernel
10+ {
11+ protected ?string $ cacheDir = Util::CACHE_DIR ;
12+
13+ protected array $ aspects = [
14+ DatabaseModifierAspect::class,
15+ ];
16+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Okapi \Aop \Tests \Functional \AdviceBehavior \Include \Target ;
4+
5+ class SecureDatabaseService
6+ {
7+ private ?array $ data = null ;
8+
9+ public function load (): self
10+ {
11+ if ($ this ->data === null ) {
12+ $ this ->data = require dirname (__DIR__ , 3 ) . '/AdviceBehavior/Include/Database/data.php ' ;
13+ }
14+
15+ return $ this ;
16+ }
17+
18+ public function getData (): array
19+ {
20+ if ($ this ->data === null ) {
21+ $ this ->load ();
22+ }
23+
24+ return $ this ->data ;
25+ }
26+ }
Original file line number Diff line number Diff line change 33namespace Okapi \Aop \Tests \Functional \AdviceBehavior \Readonly ;
44
55use Okapi \Aop \Tests \ClassLoaderMockTrait ;
6+ use Okapi \Aop \Tests \Functional \AdviceBehavior \Readonly \Aspect \ReadonlyAspect ;
67use Okapi \Aop \Tests \Functional \AdviceBehavior \Readonly \Target \ReadonlyClass ;
78use Okapi \Aop \Tests \Functional \AdviceBehavior \Readonly \Target \ReadonlyPromotedProperties ;
89use Okapi \Aop \Tests \Util ;
@@ -14,6 +15,9 @@ class ReadonlyTest extends TestCase
1415{
1516 use ClassLoaderMockTrait;
1617
18+ /**
19+ * @see ReadonlyAspect::doNothing()
20+ */
1721 public function testReadonlyClass (): void
1822 {
1923 if (PHP_VERSION_ID < 80200 ) {
You can’t perform that action at this time.
0 commit comments