Skip to content

Commit 67e0d1b

Browse files
EventTrait must not have a public constructor.
1 parent d944228 commit 67e0d1b

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/Traits/EventTrait.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818

1919
trait EventTrait
2020
{
21+
/**
22+
* @codeCoverageIgnore
23+
*/
24+
private function __construct()
25+
{
26+
}
27+
2128
public function __call(string $method, array $parameters)
2229
{
2330
return Dispatcher::invoke(

tests/PhpUnit/Traits/EventTraitTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use ScaleUpStack\EasyObject\Tests\Resources\Traits\ForEventTraitTesting;
1616
use ScaleUpStack\EasyObject\Traits\EventTrait;
1717
use ScaleUpStack\EasyObject\Tests\Resources\TestCase;
18+
use ScaleUpStack\Reflection\Reflection;
1819

1920
/**
2021
* @coversDefaultClass \ScaleUpStack\EasyObject\Traits\EventTrait
@@ -37,4 +38,16 @@ public function it_uses_magic_methods_for_named_constructor_and_virtual_getters(
3738
// then the property is accessible via the virtual getter
3839
$this->assertSame($someProperty, $event->someProperty());
3940
}
41+
42+
/**
43+
* @test
44+
*/
45+
public function it_cannot_be_constructed_via_new()
46+
{
47+
// the constructor must not be public
48+
$this->assertFalse(
49+
Reflection::methodOfClass(ForEventTraitTesting::class, '__construct')->isPublic(),
50+
'__construct() must not be public'
51+
);
52+
}
4053
}

0 commit comments

Comments
 (0)