From 409a63d77a259318d99c22cb9c31e336abf80323 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 tests/Flarum/Api/Handler/ValidationExceptionHandlerTest.php diff --git a/tests/Flarum/Api/Handler/ValidationExceptionHandlerTest.php b/tests/Flarum/Api/Handler/ValidationExceptionHandlerTest.php new file mode 100644 index 000000000..22d9c78a7 --- /dev/null +++ b/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()); + } +}