Skip to content

Commit

Permalink
Use typed properties in tests as much as possible
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Jul 25, 2023
1 parent a246917 commit 8a9a52c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 45 deletions.
26 changes: 8 additions & 18 deletions Tests/EventDispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,15 @@ class EventDispatcherTest extends TestCase
private const postFoo = 'post.foo';
private const preBar = 'pre.bar';

/**
* @var EventDispatcher
*/
private $dispatcher;

private $listener;
private EventDispatcher $dispatcher;
private TestEventListener $listener;

protected function setUp(): void
{
$this->dispatcher = $this->createEventDispatcher();
$this->listener = new TestEventListener();
}

protected function tearDown(): void
{
$this->dispatcher = null;
$this->listener = null;
}

protected function createEventDispatcher()
{
return new EventDispatcher();
Expand Down Expand Up @@ -446,9 +436,9 @@ public function __invoke()

class TestEventListener
{
public $name;
public $preFooInvoked = false;
public $postFooInvoked = false;
public string $name;
public bool $preFooInvoked = false;
public bool $postFooInvoked = false;

/* Listener methods */

Expand All @@ -473,9 +463,9 @@ public function __invoke()

class TestWithDispatcher
{
public $name;
public $dispatcher;
public $invoked = false;
public ?string $name = null;
public ?EventDispatcher $dispatcher = null;
public bool $invoked = false;

public function foo($e, $name, $dispatcher)
{
Expand Down
20 changes: 2 additions & 18 deletions Tests/GenericEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,15 @@
*/
class GenericEventTest extends TestCase
{
/**
* @var GenericEvent
*/
private $event;

private $subject;
private GenericEvent $event;
private \stdClass $subject;

/**
* Prepares the environment before running a test.
*/
protected function setUp(): void
{
$this->subject = new \stdClass();
$this->event = new GenericEvent($this->subject, ['name' => 'Event']);
}

/**
* Cleans up the environment after running a test.
*/
protected function tearDown(): void
{
$this->subject = null;
$this->event = null;
}

public function testConstruct()
{
$this->assertEquals($this->event, new GenericEvent($this->subject, ['name' => 'Event']));
Expand Down
11 changes: 2 additions & 9 deletions Tests/ImmutableEventDispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,8 @@
*/
class ImmutableEventDispatcherTest extends TestCase
{
/**
* @var MockObject&EventDispatcherInterface
*/
private $innerDispatcher;

/**
* @var ImmutableEventDispatcher
*/
private $dispatcher;
private MockObject&EventDispatcherInterface $innerDispatcher;
private ImmutableEventDispatcher $dispatcher;

protected function setUp(): void
{
Expand Down

0 comments on commit 8a9a52c

Please sign in to comment.