From 933e30ac430c78216ca5a581633e7103a26ff6cf Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Wed, 24 Apr 2024 09:59:25 +0200 Subject: [PATCH] Add failing tests --- .../ModelViolationReportersTest.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/Sentry/Integration/ModelViolationReportersTest.php b/test/Sentry/Integration/ModelViolationReportersTest.php index 2e94d9ad..39002384 100644 --- a/test/Sentry/Integration/ModelViolationReportersTest.php +++ b/test/Sentry/Integration/ModelViolationReportersTest.php @@ -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;