File tree Expand file tree Collapse file tree 2 files changed +54
-1
lines changed
Expand file tree Collapse file tree 2 files changed +54
-1
lines changed Original file line number Diff line number Diff line change 1010 }
1111 ],
1212 "require" :{
13- "php" :" ^7.4 | ^8.0 "
13+ "php" :" ^7.4 | ^8"
1414 },
1515 "require-dev" : {
16+ "php" :" ^8" ,
1617 "phpunit/phpunit" :" ^9"
1718 },
1819 "autoload" :{
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace skrtdev \Prototypes ;
4+
5+ use PHPUnit \Framework \TestCase ;
6+
7+ class DemoClass {
8+ use Prototypeable;
9+
10+ public function existentMethod (): void
11+ {
12+
13+ }
14+ }
15+
16+ class PrototypesTest extends TestCase
17+ {
18+ public function testPrototypeCanBeCreated (): void
19+ {
20+ $ this ->assertNull (DemoClass::addMethod ('prototypeMethod ' , fn () => true ));
21+ }
22+
23+ public function testErrorIsThrownInNonExistentMethods (): void
24+ {
25+ $ this ->expectException (\Error::class);
26+ (new DemoClass )->nonExistentMethod ();
27+ }
28+
29+ public function testCantOverridePrototypes (): void
30+ {
31+ $ this ->expectException (Exception::class);
32+ DemoClass::addMethod ('prototypeMethod ' , fn () => true );
33+ }
34+
35+ public function testCantOverrideMethods (): void
36+ {
37+ $ this ->expectException (Exception::class);
38+ DemoClass::addMethod ('existentMethod ' , fn () => true );
39+ }
40+
41+ public function testNonExistentClass (): void
42+ {
43+ $ this ->expectException (Exception::class);
44+ Prototypes::addClassMethod ('RandomClass ' , 'RandomMethod ' , fn () => true );
45+ }
46+
47+ public function testNonPrototypeableClass (): void
48+ {
49+ $ this ->expectException (Exception::class);
50+ Prototypes::addClassMethod (\stdClass::class, 'RandomMethod ' , fn () => true );
51+ }
52+ }
You can’t perform that action at this time.
0 commit comments