Skip to content

Commit dd1683f

Browse files
authored
minor test improvements (#86)
* wrong (empty) directive * static data provider * fix test warn * bumped php & phpunit * migrated phpunit conf * ignore phpunit cache dir * migrate to attributes * refactor around deprecated getMockForAbstractClass * cs
1 parent daccc3b commit dd1683f

11 files changed

+91
-169
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
nbproject
99
composer.lock
1010
.phpunit.result.cache
11+
.phpunit.cache
1112
.phpcs-cache

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
"minimum-stability": "dev",
2222
"prefer-stable": true,
2323
"require": {
24-
"php": "^7.4 || ^8.0",
24+
"php": "^8.2",
2525
"ramsey/uuid": "4.1.2 || ^4.3",
2626
"beberlei/assert": "^2.7.1 || ^3.0"
2727
},
2828
"require-dev": {
2929
"php-coveralls/php-coveralls": "^2.2",
30-
"phpunit/phpunit": "^9.5.5",
30+
"phpunit/phpunit": "^11.0",
3131
"prooph/bookdown-template": "^0.2.3",
3232
"prooph/php-cs-fixer-config": "^0.5"
3333
},

phpunit.xml.dist

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" bootstrap="vendor/autoload.php" convertDeprecationsToExceptions="true" colors="true">
3-
<coverage processUncoveredFiles="true">
4-
<include>
5-
<directory suffix=".php">./src</directory>
6-
</include>
7-
</coverage>
8-
9-
<testsuite name="Prooph Common Test Suite">
10-
<directory>./tests/</directory>
11-
</testsuite>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" cacheDirectory=".phpunit.cache">
3+
<testsuite name="Prooph Common Test Suite">
4+
<directory>./tests/</directory>
5+
</testsuite>
6+
<source>
7+
<include>
8+
<directory suffix=".php">./src</directory>
9+
</include>
10+
</source>
1211
</phpunit>

tests/Event/DefaultActionEventTest.php

+12-33
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace ProophTest\Common\Event;
1515

16+
use PHPUnit\Framework\Attributes\Test;
1617
use PHPUnit\Framework\TestCase;
1718
use Prooph\Common\Event\DefaultActionEvent;
1819

@@ -26,9 +27,7 @@ private function getTestEvent()
2627
return new DefaultActionEvent('test-event', 'target', ['param1' => 'foo']);
2728
}
2829

29-
/**
30-
* @test
31-
*/
30+
#[Test]
3231
public function it_can_be_initialized_with_a_name_a_target_and_params(): void
3332
{
3433
$event = $this->getTestEvent();
@@ -38,9 +37,7 @@ public function it_can_be_initialized_with_a_name_a_target_and_params(): void
3837
$this->assertEquals(['param1' => 'foo'], $event->getParams());
3938
}
4039

41-
/**
42-
* @test
43-
*/
40+
#[Test]
4441
public function it_can_initialized_without_a_target_and_params(): void
4542
{
4643
$event = new DefaultActionEvent('test-event');
@@ -49,9 +46,7 @@ public function it_can_initialized_without_a_target_and_params(): void
4946
$this->assertEquals([], $event->getParams());
5047
}
5148

52-
/**
53-
* @test
54-
*/
49+
#[Test]
5550
public function it_returns_param_if_set(): void
5651
{
5752
$event = $this->getTestEvent();
@@ -60,25 +55,19 @@ public function it_returns_param_if_set(): void
6055
$this->assertEquals('bar', $event->getParam('param1'));
6156
}
6257

63-
/**
64-
* @test
65-
*/
58+
#[Test]
6659
public function it_returns_null_if_param_is_not_set_and_no_other_default_is_given(): void
6760
{
6861
$this->assertNull($this->getTestEvent()->getParam('unknown'));
6962
}
7063

71-
/**
72-
* @test
73-
*/
64+
#[Test]
7465
public function it_returns_default_if_param_is_not_set(): void
7566
{
7667
$this->assertEquals('default', $this->getTestEvent()->getParam('unknown', 'default'));
7768
}
7869

79-
/**
80-
* @test
81-
*/
70+
#[Test]
8271
public function it_changes_name_when_new_one_is_set(): void
8372
{
8473
$event = $this->getTestEvent();
@@ -88,9 +77,7 @@ public function it_changes_name_when_new_one_is_set(): void
8877
$this->assertEquals('new name', $event->getName());
8978
}
9079

91-
/**
92-
* @test
93-
*/
80+
#[Test]
9481
public function it_overrides_params_array_if_new_one_is_set(): void
9582
{
9683
$event = $this->getTestEvent();
@@ -100,9 +87,7 @@ public function it_overrides_params_array_if_new_one_is_set(): void
10087
$this->assertEquals(['param_new' => 'bar'], $event->getParams());
10188
}
10289

103-
/**
104-
* @test
105-
*/
90+
#[Test]
10691
public function it_allows_object_implementing_array_access_as_params(): void
10792
{
10893
$arrayLikeObject = new \ArrayObject(['object_param' => 'baz']);
@@ -114,9 +99,7 @@ public function it_allows_object_implementing_array_access_as_params(): void
11499
$this->assertSame($arrayLikeObject, $event->getParams());
115100
}
116101

117-
/**
118-
* @test
119-
*/
102+
#[Test]
120103
public function it_does_not_allow_params_object_that_is_not_of_type_array_access(): void
121104
{
122105
$this->expectException(\InvalidArgumentException::class);
@@ -128,9 +111,7 @@ public function it_does_not_allow_params_object_that_is_not_of_type_array_access
128111
$this->getTestEvent()->setParams($stdObj);
129112
}
130113

131-
/**
132-
* @test
133-
*/
114+
#[Test]
134115
public function it_changes_target_if_new_is_set(): void
135116
{
136117
$event = $this->getTestEvent();
@@ -142,9 +123,7 @@ public function it_changes_target_if_new_is_set(): void
142123
$this->assertSame($target, $event->getTarget());
143124
}
144125

145-
/**
146-
* @test
147-
*/
126+
#[Test]
148127
public function it_indicates_that_propagation_should_be_stopped(): void
149128
{
150129
$event = $this->getTestEvent();

tests/Event/ProophActionEventEmitterTest.php

+22-41
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace ProophTest\Common\Event;
1515

16+
use PHPUnit\Framework\Attributes\Test;
1617
use PHPUnit\Framework\TestCase;
1718
use Prooph\Common\Event\ActionEvent;
1819
use Prooph\Common\Event\ListenerHandler;
@@ -29,9 +30,7 @@ protected function setUp(): void
2930
$this->proophActionEventEmitter = new ProophActionEventEmitter();
3031
}
3132

32-
/**
33-
* @test
34-
*/
33+
#[Test]
3534
public function it_attaches_action_event_listeners_and_dispatch_event_to_them(): void
3635
{
3736
$lastEvent = null;
@@ -52,9 +51,7 @@ public function it_attaches_action_event_listeners_and_dispatch_event_to_them():
5251
$this->assertSame($lastEvent, $listener1->lastEvent);
5352
}
5453

55-
/**
56-
* @test
57-
*/
54+
#[Test]
5855
public function it_detaches_a_listener(): void
5956
{
6057
$lastEvent = null;
@@ -78,9 +75,7 @@ public function it_detaches_a_listener(): void
7875
$this->assertSame($actionEvent, $lastEvent);
7976
}
8077

81-
/**
82-
* @test
83-
*/
78+
#[Test]
8479
public function it_triggers_listeners_until_callback_returns_true(): void
8580
{
8681
$lastEvent = null;
@@ -103,9 +98,7 @@ public function it_triggers_listeners_until_callback_returns_true(): void
10398
$this->assertSame($actionEvent, $listener1->lastEvent);
10499
}
105100

106-
/**
107-
* @test
108-
*/
101+
#[Test]
109102
public function it_stops_dispatching_when_event_propagation_is_stopped(): void
110103
{
111104
$lastEvent = null;
@@ -131,9 +124,7 @@ public function it_stops_dispatching_when_event_propagation_is_stopped(): void
131124
$this->assertSame($actionEvent, $listener1->lastEvent);
132125
}
133126

134-
/**
135-
* @test
136-
*/
127+
#[Test]
137128
public function it_stops_dispatching_when_event_propagation_is_stopped_2(): void
138129
{
139130
$lastEvent = null;
@@ -160,9 +151,7 @@ public function it_stops_dispatching_when_event_propagation_is_stopped_2(): void
160151
$this->assertSame($actionEvent, $listener1->lastEvent);
161152
}
162153

163-
/**
164-
* @test
165-
*/
154+
#[Test]
166155
public function it_triggers_listeners_with_high_priority_first(): void
167156
{
168157
$lastEvent = null;
@@ -188,9 +177,7 @@ public function it_triggers_listeners_with_high_priority_first(): void
188177
$this->assertNull($listener1->lastEvent);
189178
}
190179

191-
/**
192-
* @test
193-
*/
180+
#[Test]
194181
public function it_attaches_a_listener_aggregate(): void
195182
{
196183
$listener1 = new ActionEventListenerMock();
@@ -207,9 +194,7 @@ public function it_attaches_a_listener_aggregate(): void
207194
$this->assertNull($listener1->lastEvent);
208195
}
209196

210-
/**
211-
* @test
212-
*/
197+
#[Test]
213198
public function it_detaches_listener_aggregate(): void
214199
{
215200
$listener1 = new ActionEventListenerMock();
@@ -227,48 +212,44 @@ public function it_detaches_listener_aggregate(): void
227212
$this->assertSame($actionEvent, $listener1->lastEvent);
228213
}
229214

230-
/**
231-
* @test
232-
*/
215+
#[Test]
233216
public function it_uses_default_event_name_if_none_given(): void
234217
{
235218
$event = $this->proophActionEventEmitter->getNewActionEvent();
236219
$this->assertEquals('action_event', $event->getName());
237220
}
238221

239-
/**
240-
* @test
241-
*/
222+
#[Test]
242223
public function it_returns_false_when_unattached_listener_handler_gets_detached(): void
243224
{
244-
$listener = $this->getMockForAbstractClass(ListenerHandler::class);
225+
$listener = $this->getMockBuilder(ListenerHandler::class)
226+
->onlyMethods(['getActionEventListener'])
227+
->getMock();
245228

246229
$this->assertFalse($this->proophActionEventEmitter->detachListener($listener));
247230
}
248231

249-
/**
250-
* @test
251-
*/
252-
public function it_dispatches_until_whith_no_listeners_attached(): void
232+
#[Test]
233+
public function it_dispatches_until_with_no_listeners_attached(): void
253234
{
235+
$this->expectNotToPerformAssertions();
236+
254237
$actionEventMock = $this->createMock(ActionEvent::class);
255238

256239
$this->proophActionEventEmitter->dispatchUntil($actionEventMock, fn () => true);
257240
}
258241

259-
/**
260-
* @test
261-
*/
242+
#[Test]
262243
public function it_attaches_to_known_event_names(): void
263244
{
245+
$this->expectNotToPerformAssertions();
246+
264247
$proophActionEventEmitter = new ProophActionEventEmitter(['foo']);
265248
$proophActionEventEmitter->attachListener('foo', function (): void {
266249
});
267250
}
268251

269-
/**
270-
* @test
271-
*/
252+
#[Test]
272253
public function it_does_not_attach_to_unknown_event_names(): void
273254
{
274255
$this->expectException(\InvalidArgumentException::class);

0 commit comments

Comments
 (0)