Skip to content

Commit

Permalink
Test for objects that do not implement SluggableInterface (Case 17831…
Browse files Browse the repository at this point in the history
…3) (#17)

- Test for objects that do not implement SluggableInterface
- Rename test for more preciseness
- Reorder test do group "no redirect" cases
  • Loading branch information
MalteWunsch authored Jan 6, 2025
1 parent b35a956 commit 27ffcc0
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions tests/EventListener/ValidateSlugListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ public function listenerDoesNotRedirectIfRequestContainsNoObjects(): void
$this->assertListenerDoesNotRedirectForEvent($event);
}

/**
* @test
*/
public function listenerDoesNotRedirectIfRequestContainsAnObjectThatDoesNotImplementSluggableInterface(): void
{
$event = $this->createEvent([new \stdClass()]);

$this->assertListenerDoesNotRedirectForEvent($event);
}

/**
* @test
*/
Expand All @@ -64,6 +74,20 @@ public function listenerDoesNotRedirectIfRequestContainsValidSlugForObject(): vo
$this->assertListenerDoesNotRedirectForEvent($event);
}

/**
* Ensures that the listener does not redirect if there is no slug defined
* for the object, despite it's class implementing the SluggableInterface.
*
* @test
*/
public function listenerDoesNotRedirectIfObjectHasNullSlug(): void
{
$sluggable = $this->createSluggable(null);
$event = $this->createEvent([$sluggable], 'invalid-slug');

$this->assertListenerDoesNotRedirectForEvent($event);
}

/**
* @test
*/
Expand Down Expand Up @@ -96,20 +120,6 @@ public function listenerStopsEventPropagationIfRedirectIsNecessary(): void
self::assertTrue($event->isPropagationStopped());
}

/**
* Ensures that the listener does not redirect if there is no slug defined
* for the object.
*
* @test
*/
public function listenerDoesNotRedirectIfObjectHasNoSlug(): void
{
$sluggable = $this->createSluggable(null);
$event = $this->createEvent([$sluggable], 'invalid-slug');

$this->assertListenerDoesNotRedirectForEvent($event);
}

/**
* Simulates an object that provides the given slug.
*/
Expand Down

0 comments on commit 27ffcc0

Please sign in to comment.