From 2e7b73e19ccbeeb8387fa7c4f2282984d4326c1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Wed, 2 Nov 2016 23:37:00 +0100 Subject: [PATCH] Add constants for event's priorities --- src/EventListener/EventPriorities.php | 31 +++++++++++++++++++ tests/EventListener/EventPrioritiesTest.php | 34 +++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 src/EventListener/EventPriorities.php create mode 100644 tests/EventListener/EventPrioritiesTest.php diff --git a/src/EventListener/EventPriorities.php b/src/EventListener/EventPriorities.php new file mode 100644 index 00000000000..85471300cc2 --- /dev/null +++ b/src/EventListener/EventPriorities.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ApiPlatform\Core\EventListener; + +/** + * Constants for common priorities. + * + * @author Kévin Dunglas + */ +final class EventPriorities +{ + const PRE_READ = 5; + const POST_READ = 3; + const PRE_DESERIALIZE = 3; + const POST_DESERIALIZE = 1; + const PRE_VALIDATE = 65; + const POST_VALIDATE = 63; + const PRE_WRITE = 33; + const POST_WRITE = 31; + const PRE_RESPOND = 9; + const POST_RESPOND = 7; +} diff --git a/tests/EventListener/EventPrioritiesTest.php b/tests/EventListener/EventPrioritiesTest.php new file mode 100644 index 00000000000..4d842015ae7 --- /dev/null +++ b/tests/EventListener/EventPrioritiesTest.php @@ -0,0 +1,34 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ApiPlatform\Core\Tests\EventListener; + +use ApiPlatform\Core\EventListener\EventPriorities; + +/** + * @author Kévin Dunglas + */ +class EventPrioritiesTest extends \PHPUnit_Framework_TestCase +{ + public function testConstants() + { + $this->assertEquals(5, EventPriorities::PRE_READ); + $this->assertEquals(3, EventPriorities::POST_READ); + $this->assertEquals(3, EventPriorities::PRE_DESERIALIZE); + $this->assertEquals(1, EventPriorities::POST_DESERIALIZE); + $this->assertEquals(65, EventPriorities::PRE_VALIDATE); + $this->assertEquals(63, EventPriorities::POST_VALIDATE); + $this->assertEquals(33, EventPriorities::PRE_WRITE); + $this->assertEquals(31, EventPriorities::POST_WRITE); + $this->assertEquals(9, EventPriorities::PRE_RESPOND); + $this->assertEquals(7, EventPriorities::POST_RESPOND); + } +}