Skip to content

Commit e84181d

Browse files
committed
add tests
1 parent 359ac34 commit e84181d

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
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":{

tests/PrototypesTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
}

0 commit comments

Comments
 (0)