Browse Source

added event class tests.

Taylor Otwell 13 years ago
parent
commit
8325f6dc5e
1 changed files with 50 additions and 0 deletions
  1. 50 0
      tests/cases/laravel/event.test.php

+ 50 - 0
tests/cases/laravel/event.test.php

@@ -0,0 +1,50 @@
+<?php
+
+class EventTest extends PHPUnit_Framework_TestCase {
+
+	/**
+	 * Tear down the testing environment.
+	 */
+	public function tearDown()
+	{
+		Event::$events = array();
+	}
+
+	/**
+	 * Test basic event firing.
+	 *
+	 * @group laravel
+	 */
+	public function testListenersAreFiredForEvents()
+	{
+		Event::listen('test.event', function()
+		{
+			return 1;
+		});
+
+		Event::listen('test.event', function()
+		{
+			return 2;
+		});
+
+		$responses = Event::fire('test.event');
+
+		$this->assertEquals(1, $responses[0]);
+		$this->assertEquals(2, $responses[1]);
+	}
+
+	/**
+	 * Test parameters can be passed to event listeners.
+	 *
+	 * @group laravel
+	 */
+	public function testParametersCanBePassedToEvents()
+	{
+		Event::listen('test.event', function($var) { return $var; });
+
+		$responses = Event::fire('test.event', array('Taylor'));
+
+		$this->assertEquals('Taylor', $responses[0]);
+	}
+
+}