Fix SweetAlertBuilder::question() bug and improve code quality

This commit is contained in:
Younes ENNAJI
2026-03-07 17:50:16 +00:00
parent bd8169619e
commit e4337b0b63
7 changed files with 81 additions and 134 deletions
@@ -194,4 +194,34 @@ final class FilterCriteriaTest extends TestCase
$this->assertCount(1, $result);
$this->assertSame('test', $result[0]->getMessage());
}
public function testApplyThrowsExceptionWhenCallbackReturnsNonArray(): void
{
$criteria = new FilterCriteria(fn ($e) => 'not an array');
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Filter callback must return an array, got "string".');
$criteria->apply([new Envelope(new Notification())]);
}
public function testApplyThrowsExceptionWhenCallbackReturnsNull(): void
{
$criteria = new FilterCriteria(fn ($e) => null);
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Filter callback must return an array, got "null".');
$criteria->apply([new Envelope(new Notification())]);
}
public function testApplyThrowsExceptionWhenCallbackReturnsObject(): void
{
$criteria = new FilterCriteria(fn ($e) => new \stdClass());
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Filter callback must return an array, got "stdClass".');
$criteria->apply([new Envelope(new Notification())]);
}
}
@@ -29,7 +29,7 @@ final class SweetAlertBuilderTest extends TestCase
$envelope = $this->sweetAlertBuilder->getEnvelope();
$options = $envelope->getNotification()->getOptions();
$this->assertSame(['showCancelButton' => true, 'text' => 'Are you sure?'], $options);
$this->assertSame(['showCancelButton' => true, 'text' => 'Are you sure?', 'option1' => 'value1'], $options);
}
public function testTitle(): void