From 8843d8411717065ef40a44edf4ae9e66f5cecc84 Mon Sep 17 00:00:00 2001 From: Kirk Bushell Date: Wed, 28 Oct 2015 12:46:49 +0000 Subject: [PATCH] Added validation handler tests --- .../ValidationExceptionHandlerTest.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 framework/core/tests/Flarum/Api/Handler/ValidationExceptionHandlerTest.php diff --git a/framework/core/tests/Flarum/Api/Handler/ValidationExceptionHandlerTest.php b/framework/core/tests/Flarum/Api/Handler/ValidationExceptionHandlerTest.php new file mode 100644 index 000000000..22d9c78a7 --- /dev/null +++ b/framework/core/tests/Flarum/Api/Handler/ValidationExceptionHandlerTest.php @@ -0,0 +1,30 @@ +handler = new ValidationExceptionHandler; + } + + public function test_it_handles_recognisable_exceptions() + { + $this->assertFalse($this->handler->manages(new \Exception)); + $this->assertTrue($this->handler->manages(new ValidationException([]))); + } + + public function test_managing_exceptions() + { + $response = $this->handler->handle(new ValidationException(['There was an error'])); + + $this->assertEquals(422, $response->getStatus()); + $this->assertEquals([['source' => ['pointer' => '/data/attributes/0'], 'detail' => 'There was an error']], $response->getErrors()); + } +}