99use Spiral \Attributes \Composite \SelectiveReader ;
1010use Temporal \Internal \Declaration \Reader \ActivityReader ;
1111use Temporal \Tests \Unit \AbstractUnit ;
12- use WeakReference ;
1312
1413final class ActivityPrototypeTestCase extends AbstractUnit
1514{
1615 private ActivityReader $ activityReader ;
1716
18- protected function setUp (): void
17+ public function testNoMagicMethods (): void
1918 {
20- $ this ->activityReader = new ActivityReader (new SelectiveReader ([new AnnotationReader (), new AttributeReader ()]));
21- parent ::setUp ();
19+ $ protos = $ this ->activityReader ->fromClass (MagicActivity::class);
20+
21+ self ::assertCount (1 , $ protos );
22+ self ::assertSame ('MagicActivity.Do ' , $ protos [0 ]->getID ());
2223 }
2324
2425 public function testInstanceLeaks (): void
@@ -27,11 +28,11 @@ public function testInstanceLeaks(): void
2728 $ proto = $ this ->activityReader
2829 ->fromClass (DummyActivity::class)[0 ];
2930
30- $ refProto = WeakReference::create ($ proto );
31- $ refInstance = WeakReference::create ($ proto ->getInstance ());
32- $ refHandler = WeakReference::create ($ proto ->getHandler ());
33- $ refInstanceHandler = WeakReference::create ($ proto ->getInstance ()->getHandler ());
34- $ refActivity = WeakReference::create ($ proto ->getInstance ()->getContext ());
31+ $ refProto = \ WeakReference::create ($ proto );
32+ $ refInstance = \ WeakReference::create ($ proto ->getInstance ());
33+ $ refHandler = \ WeakReference::create ($ proto ->getHandler ());
34+ $ refInstanceHandler = \ WeakReference::create ($ proto ->getInstance ()->getHandler ());
35+ $ refActivity = \ WeakReference::create ($ proto ->getInstance ()->getContext ());
3536
3637 unset($ proto , $ instance );
3738
@@ -49,8 +50,8 @@ public function testProtoWithInstanceImmutabilityAndLeaks(): void
4950 ->fromClass (DummyActivity::class)[0 ];
5051 $ newProto = $ proto ->withInstance ($ instance );
5152 // References
52- $ refProto = WeakReference::create ($ proto );
53- $ refNewProto = WeakReference::create ($ newProto );
53+ $ refProto = \ WeakReference::create ($ proto );
54+ $ refNewProto = \ WeakReference::create ($ newProto );
5455
5556 // New object is result of clone operation
5657 $ this ->assertNotSame ($ proto , $ newProto );
@@ -80,7 +81,7 @@ public function testGetInstanceFromClass(): void
8081 public function testGetInstanceFromFactory (): void
8182 {
8283 $ proto = $ this ->activityReader ->fromClass (DummyActivity::class)[0 ];
83- $ protoWithFactory = $ proto ->withFactory (fn () => new DummyActivity ());
84+ $ protoWithFactory = $ proto ->withFactory (static fn () => new DummyActivity ());
8485
8586 $ this ->assertInstanceOf (DummyActivity::class, $ protoWithFactory ->getInstance ()->getContext ());
8687 }
@@ -97,7 +98,7 @@ public function testLocalActivityFlag(): void
9798 public function testFactoryCreatesNewInstances (): void
9899 {
99100 $ proto = $ this ->activityReader ->fromClass (DummyActivity::class)[0 ];
100- $ protoWithFactory = $ proto ->withFactory (fn () => new DummyActivity ());
101+ $ protoWithFactory = $ proto ->withFactory (static fn () => new DummyActivity ());
101102
102103 $ this ->assertEquals ($ protoWithFactory ->getInstance ()->getContext (), $ protoWithFactory ->getInstance ()->getContext ());
103104 $ this ->assertNotSame ($ protoWithFactory ->getInstance ()->getContext (), $ protoWithFactory ->getInstance ()->getContext ());
@@ -106,7 +107,7 @@ public function testFactoryCreatesNewInstances(): void
106107 public function testFactoryAcceptsReflectionClassOfActivity (): void
107108 {
108109 $ proto = $ this ->activityReader ->fromClass (DummyActivity::class)[0 ];
109- $ protoWithFactory = $ proto ->withFactory (fn (\ReflectionClass $ reflectionClass ) => $ reflectionClass ->newInstance ());
110+ $ protoWithFactory = $ proto ->withFactory (static fn (\ReflectionClass $ reflectionClass ) => $ reflectionClass ->newInstance ());
110111
111112 $ this ->assertEquals ($ protoWithFactory ->getInstance ()->getContext (), $ protoWithFactory ->getInstance ()->getContext ());
112113 $ this ->assertNotSame ($ protoWithFactory ->getInstance ()->getContext (), $ protoWithFactory ->getInstance ()->getContext ());
@@ -115,9 +116,15 @@ public function testFactoryAcceptsReflectionClassOfActivity(): void
115116 public function testGetFactory (): void
116117 {
117118 $ proto = $ this ->activityReader ->fromClass (DummyActivity::class)[0 ];
118- $ protoWithFactory = $ proto ->withFactory (fn (\ReflectionClass $ reflectionClass ) => $ reflectionClass ->newInstance ());
119+ $ protoWithFactory = $ proto ->withFactory (static fn (\ReflectionClass $ reflectionClass ) => $ reflectionClass ->newInstance ());
119120
120121 $ this ->assertNull ($ proto ->getFactory ());
121122 $ this ->assertNotNull ($ protoWithFactory ->getFactory ());
122123 }
124+
125+ protected function setUp (): void
126+ {
127+ $ this ->activityReader = new ActivityReader (new SelectiveReader ([new AnnotationReader (), new AttributeReader ()]));
128+ parent ::setUp ();
129+ }
123130}
0 commit comments