expectException(ShortCodeCannotBeRegeneratedException::class); $this->expectExceptionMessage($expectedMessage); $shortUrl->regenerateShortCode(); } public function provideInvalidShortUrls(): iterable { yield 'with custom slug' => [ new ShortUrl('', ShortUrlMeta::fromRawData(['customSlug' => 'custom-slug'])), 'The short code cannot be regenerated on ShortUrls where a custom slug was provided.', ]; yield 'already persisted' => [ (new ShortUrl(''))->setId('1'), 'The short code can be regenerated only on new ShortUrls which have not been persisted yet.', ]; } /** @test */ public function regenerateShortCodeProperlyChangesTheValueOnValidShortUrls(): void { $shortUrl = new ShortUrl(''); $firstShortCode = $shortUrl->getShortCode(); $shortUrl->regenerateShortCode(); $secondShortCode = $shortUrl->getShortCode(); $this->assertNotEquals($firstShortCode, $secondShortCode); } }