Skip to content

Commit

Permalink
Add failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stayallive committed Apr 24, 2024
1 parent 44345a9 commit 933e30a
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/Sentry/Integration/ModelViolationReportersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,36 @@ public function testModelViolationReportersCanBeRegistered(): void
Model::handleDiscardedAttributeViolationUsing(Integration::discardedAttributeViolationReporter());
}

public function testViolationReporterAcceptsSingleProperty(): void
{
$reporter = Integration::discardedAttributeViolationReporter(null, true, false);

$reporter(new ViolationReporterTestModel, 'foo');

$this->assertCount(1, $this->getCapturedSentryEvents());

$violation = $this->getLastSentryEvent()->getContexts()['violation'];

$this->assertSame('foo', $violation['attribute']);
$this->assertSame('discarded_attribute', $violation['kind']);
$this->assertSame(ViolationReporterTestModel::class, $violation['model']);
}

public function testViolationReporterAcceptsListOfProperties(): void
{
$reporter = Integration::discardedAttributeViolationReporter(null, true, false);

$reporter(new ViolationReporterTestModel, ['foo', 'bar']);

$this->assertCount(1, $this->getCapturedSentryEvents());

$violation = $this->getLastSentryEvent()->getContexts()['violation'];

$this->assertSame('foo, bar', $violation['attribute']);
$this->assertSame('discarded_attribute', $violation['kind']);
$this->assertSame(ViolationReporterTestModel::class, $violation['model']);
}

public function testViolationReporterPassesThroughToCallback(): void
{
$callbackCalled = false;
Expand Down

0 comments on commit 933e30a

Please sign in to comment.