Skip to content

Commit

Permalink
Merge pull request #61 from samsonasik/update-latest-phpunit-syntax
Browse files Browse the repository at this point in the history
Update to latest PHPUnit 10 syntax
  • Loading branch information
gsteel authored Nov 4, 2024
2 parents 7900a94 + 386056e commit a5dfb82
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 45 deletions.
21 changes: 21 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@
<code><![CDATA[$result]]></code>
<code><![CDATA[$result]]></code>
</MissingClosureParamType>
<PossiblyUnusedMethod>
<code><![CDATA[eventArguments]]></code>
<code><![CDATA[eventsMissingNames]]></code>
<code><![CDATA[invalidEventsForDetach]]></code>
</PossiblyUnusedMethod>
</file>
<file src="test/EventTest.php">
<InvalidArgument>
Expand Down Expand Up @@ -407,6 +412,9 @@
<MixedArgument>
<code><![CDATA[$filter]]></code>
</MixedArgument>
<PossiblyUnusedMethod>
<code><![CDATA[invalidFilters]]></code>
</PossiblyUnusedMethod>
</file>
<file src="test/LazyEventListenerTest.php">
<LessSpecificReturnStatement>
Expand Down Expand Up @@ -443,6 +451,10 @@
<code><![CDATA[$listeners]]></code>
<code><![CDATA[$test]]></code>
</MixedAssignment>
<PossiblyUnusedMethod>
<code><![CDATA[invalidListenerTypes]]></code>
<code><![CDATA[invalidListeners]]></code>
</PossiblyUnusedMethod>
</file>
<file src="test/LazyListenerTest.php">
<InvalidFunctionCall>
Expand All @@ -469,6 +481,9 @@
<MoreSpecificReturnType>
<code><![CDATA[LazyListener]]></code>
</MoreSpecificReturnType>
<PossiblyUnusedMethod>
<code><![CDATA[invalidTypes]]></code>
</PossiblyUnusedMethod>
</file>
<file src="test/SharedEventManagerTest.php">
<MissingReturnType>
Expand Down Expand Up @@ -501,6 +516,12 @@
<PossiblyInvalidCast>
<code><![CDATA[$event]]></code>
</PossiblyInvalidCast>
<PossiblyUnusedMethod>
<code><![CDATA[detachIdentifierAndEvent]]></code>
<code><![CDATA[invalidEventNames]]></code>
<code><![CDATA[invalidIdentifiersAndEvents]]></code>
<code><![CDATA[invalidListenersAndEventNamesForFetchingListeners]]></code>
</PossiblyUnusedMethod>
<RedundantCast>
<code><![CDATA[(int) $priority]]></code>
</RedundantCast>
Expand Down
22 changes: 8 additions & 14 deletions test/EventManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use Laminas\EventManager\ResponseCollection;
use Laminas\EventManager\SharedEventManager;
use Laminas\EventManager\SharedEventManagerInterface;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Depends;
use PHPUnit\Framework\TestCase;
use ReflectionProperty;
use stdClass;
Expand Down Expand Up @@ -116,9 +118,7 @@ public static function eventArguments(): array
];
}

/**
* @dataProvider eventArguments
*/
#[DataProvider('eventArguments')]
public function testAttachShouldAddReturnTheListener(string $event): void
{
$listener = static fn(): int => 0;
Expand Down Expand Up @@ -514,9 +514,7 @@ public static function invalidEventsForAttach(): array
];
}

/**
* @dataProvider invalidEventsForAttach
*/
#[DataProvider('invalidEventsForAttach')]
public function testAttachRaisesExceptionForInvalidEventType(mixed $event): void
{
$callback = static function (): void {
Expand Down Expand Up @@ -591,9 +589,9 @@ public function testWillTriggerSharedWildcardListeners(): void
}

/**
* @depends testAttachShouldAddListenerToEvent
* @psalm-param array{event: 'test', events: EventManager, listener: callable} $dependencies
*/
#[Depends('testAttachShouldAddListenerToEvent')]
public function testCanDetachListenerFromNamedEvent(array $dependencies): void
{
$event = $dependencies['event'];
Expand Down Expand Up @@ -655,9 +653,9 @@ public function testCanDetachWildcardListeners(): array
}

/**
* @depends testCanDetachWildcardListeners
* @psalm-param array{event_names: list<string>, events: EventManager, not_contains: string} $dependencies
*/
#[Depends('testCanDetachWildcardListeners')]
public function testDetachedWildcardListenerWillNotBeTriggered(array $dependencies): void
{
$eventNames = $dependencies['event_names'];
Expand Down Expand Up @@ -739,9 +737,7 @@ public static function invalidEventsForDetach(): array
return $events;
}

/**
* @dataProvider invalidEventsForDetach
*/
#[DataProvider('invalidEventsForDetach')]
public function testPassingInvalidEventTypeToDetachRaisesException(mixed $event): void
{
$listener = static function (): void {
Expand Down Expand Up @@ -789,9 +785,7 @@ public static function eventsMissingNames(): array
// @codingStandardsIgnoreEnd
}

/**
* @dataProvider eventsMissingNames
*/
#[DataProvider('eventsMissingNames')]
public function testTriggeringAnEventWithAnEmptyNameRaisesAnException(
string|null $event,
string $method,
Expand Down
3 changes: 0 additions & 3 deletions test/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
use PHPUnit\Framework\TestCase;
use stdClass;

/**
* @group Laminas_Stdlib
*/
class EventTest extends TestCase
{
public function testConstructorWithArguments(): void
Expand Down
6 changes: 2 additions & 4 deletions test/FilterIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

use Laminas\EventManager\Exception\InvalidArgumentException;
use Laminas\EventManager\Filter\FilterIterator;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

/**
* @group Laminas_Stdlib
*/
class FilterIteratorTest extends TestCase
{
public function testNextReturnsNullOnEmptyChain(): void
Expand Down Expand Up @@ -94,9 +92,9 @@ public static function invalidFilters(): array
}

/**
* @dataProvider invalidFilters
* @param mixed $filter
*/
#[DataProvider('invalidFilters')]
public function testInsertShouldRaiseExceptionOnNonCallableDatum($filter)
{
$iterator = new FilterIterator();
Expand Down
12 changes: 5 additions & 7 deletions test/LazyEventListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Laminas\EventManager\Exception\InvalidArgumentException;
use Laminas\EventManager\LazyEventListener;
use Laminas\EventManager\LazyListener;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Depends;

class LazyEventListenerTest extends LazyListenerTest
{
Expand All @@ -31,9 +33,9 @@ public function testConstructorRaisesExceptionForMissingEvent(): void
}

/**
* @dataProvider invalidTypes
* @param mixed $event
*/
#[DataProvider('invalidTypes')]
public function testConstructorRaisesExceptionForInvalidEventType($event)
{
$class = $this->listenerClass;
Expand Down Expand Up @@ -62,17 +64,13 @@ public function testCanInstantiateLazyListenerWithValidDefinition(): LazyListene
return $listener;
}

/**
* @depends testCanInstantiateLazyListenerWithValidDefinition
*/
#[Depends('testCanInstantiateLazyListenerWithValidDefinition')]
public function testCanRetrieveEventFromListener(LazyEventListener $listener)
{
self::assertEquals('event', $listener->getEvent());
}

/**
* @depends testCanInstantiateLazyListenerWithValidDefinition
*/
#[Depends('testCanInstantiateLazyListenerWithValidDefinition')]
public function testCanRetrievePriorityFromListener(LazyEventListener $listener)
{
self::assertEquals(5, $listener->getPriority());
Expand Down
8 changes: 5 additions & 3 deletions test/LazyListenerAggregateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Laminas\EventManager\Exception\InvalidArgumentException;
use Laminas\EventManager\LazyEventListener;
use Laminas\EventManager\LazyListenerAggregate;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Depends;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
Expand Down Expand Up @@ -69,9 +71,9 @@ public static function invalidListeners(): array
}

/**
* @dataProvider invalidListenerTypes
* @param mixed $listener
*/
#[DataProvider('invalidListenerTypes')]
public function testPassingInvalidListenerTypesAtInstantiationRaisesException($listener)
{
$this->expectException(InvalidArgumentException::class);
Expand All @@ -80,9 +82,9 @@ public function testPassingInvalidListenerTypesAtInstantiationRaisesException($l
}

/**
* @dataProvider invalidListeners
* @param mixed $listener
*/
#[DataProvider('invalidListeners')]
public function testPassingInvalidListenersAtInstantiationRaisesException($listener)
{
$this->expectException(InvalidArgumentException::class);
Expand Down Expand Up @@ -130,14 +132,14 @@ public function testCanPassMixOfValidLazyEventListenerInstancesAndDefinitionsAtI
}

/**
* @depends testCanPassMixOfValidLazyEventListenerInstancesAndDefinitionsAtInstantiation
* @psalm-param array<array-key, callable|array{
* event: string,
* listener: string|object,
* method: string,
* priority: int
* }> $listeners
*/
#[Depends('testCanPassMixOfValidLazyEventListenerInstancesAndDefinitionsAtInstantiation')]
public function testAttachAttachesLazyListenersViaClosures(array $listeners)
{
$aggregate = new LazyListenerAggregate($listeners, $this->container);
Expand Down
10 changes: 5 additions & 5 deletions test/LazyListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Laminas\EventManager\EventInterface;
use Laminas\EventManager\Exception\InvalidArgumentException;
use Laminas\EventManager\LazyListener;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Depends;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
Expand Down Expand Up @@ -57,9 +59,9 @@ public function testConstructorRaisesExceptionForMissingListener(): void
}

/**
* @dataProvider invalidTypes
* @param mixed $listener
*/
#[DataProvider('invalidTypes')]
public function testConstructorRaisesExceptionForInvalidListenerType($listener)
{
$class = $this->listenerClass;
Expand All @@ -86,9 +88,9 @@ public function testConstructorRaisesExceptionForMissingMethod(): void
}

/**
* @dataProvider invalidTypes
* @param mixed $method
*/
#[DataProvider('invalidTypes')]
public function testConstructorRaisesExceptionForInvalidMethodType($method)
{
$class = $this->listenerClass;
Expand All @@ -115,9 +117,7 @@ public function testCanInstantiateLazyListenerWithValidDefinition(): LazyListene
return $listener;
}

/**
* @depends testCanInstantiateLazyListenerWithValidDefinition
*/
#[Depends('testCanInstantiateLazyListenerWithValidDefinition')]
public function testInstatiationSetsListenerMethod(LazyListener $listener)
{
self::assertAttributeEquals('method', 'method', $listener);
Expand Down
17 changes: 8 additions & 9 deletions test/SharedEventManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Laminas\EventManager\EventInterface;
use Laminas\EventManager\Exception;
use Laminas\EventManager\SharedEventManager;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

use function array_shift;
Expand Down Expand Up @@ -62,9 +63,9 @@ public static function invalidIdentifiers(): array
}

/**
* @dataProvider invalidIdentifiers
* @param mixed $identifier
*/
#[DataProvider('invalidIdentifiers')]
public function testAttachRaisesExceptionForInvalidIdentifer($identifier)
{
$this->expectException(Exception\InvalidArgumentException::class);
Expand All @@ -90,9 +91,9 @@ public static function invalidEventNames(): array
}

/**
* @dataProvider invalidEventNames
* @param mixed $event
*/
#[DataProvider('invalidEventNames')]
public function testAttachRaisesExceptionForInvalidEvent($event)
{
$this->expectException(Exception\InvalidArgumentException::class);
Expand All @@ -119,9 +120,7 @@ public static function detachIdentifierAndEvent(): array
];
}

/**
* @dataProvider detachIdentifierAndEvent
*/
#[DataProvider('detachIdentifierAndEvent')]
public function testCanDetachFromSharedManagerUsingIdentifierAndEvent(?string $identifier, ?string $event)
{
$this->manager->attach('IDENTIFIER', 'EVENT', $this->callback);
Expand Down Expand Up @@ -280,9 +279,9 @@ public static function invalidIdentifiersAndEvents(): array
}

/**
* @dataProvider invalidIdentifiersAndEvents
* @param mixed $identifier
*/
#[DataProvider('invalidIdentifiersAndEvents')]
public function testDetachingWithInvalidIdentifierTypeRaisesException($identifier)
{
$this->expectException(Exception\InvalidArgumentException::class);
Expand All @@ -291,9 +290,9 @@ public function testDetachingWithInvalidIdentifierTypeRaisesException($identifie
}

/**
* @dataProvider invalidIdentifiersAndEvents
* @param mixed $eventName
*/
#[DataProvider('invalidIdentifiersAndEvents')]
public function testDetachingWithInvalidEventTypeRaisesException($eventName)
{
$this->manager->attach('IDENTIFIER', '*', $this->callback);
Expand All @@ -311,9 +310,9 @@ public static function invalidListenersAndEventNamesForFetchingListeners(): arra
}

/**
* @dataProvider invalidListenersAndEventNamesForFetchingListeners
* @param mixed $eventName
*/
#[DataProvider('invalidListenersAndEventNamesForFetchingListeners')]
public function testGetListenersRaisesExceptionForInvalidEventName($eventName)
{
$this->expectException(Exception\InvalidArgumentException::class);
Expand All @@ -322,9 +321,9 @@ public function testGetListenersRaisesExceptionForInvalidEventName($eventName)
}

/**
* @dataProvider invalidListenersAndEventNamesForFetchingListeners
* @param mixed $identifier
*/
#[DataProvider('invalidListenersAndEventNamesForFetchingListeners')]
public function testGetListenersRaisesExceptionForInvalidIdentifier($identifier)
{
$this->expectException(Exception\InvalidArgumentException::class);
Expand Down

0 comments on commit a5dfb82

Please sign in to comment.