<commit_before><?php

use Mockery as m;
use Illuminate\Bus\Dispatcher;
use Illuminate\Container\Container;

class BusDispatcherTest extends PHPUnit_Framework_TestCase {

	public function tearDown()
	{
		m::close();
	}


	public function testBasicDispatchingOfCommandsToHandlers()
	{
		$container = new Container;
		$handler = m::mock('StdClass');
		$handler->shouldReceive('handle')->once()->andReturn('foo');
		$container->instance('Handler', $handler);
		$dispatcher = new Dispatcher($container);
		$dispatcher->mapUsing(function() { return 'Handler@handle'; });

		$result = $dispatcher->dispatch(new BusDispatcherTestBasicCommand);
		$this->assertEquals('foo', $result);
	}


	public function testCommandsThatShouldBeQueuedAreQueued()
	{
		$container = new Container;
		$dispatcher = new Dispatcher($container, function() {
			$mock = m::mock('Illuminate\Contracts\Queue\Queue');
			$mock->shouldReceive('push')->once();
			return $mock;
		});

		$dispatcher->dispatch(m::mock('Illuminate\Contracts\Queue\ShouldBeQueued'));
	}


	public function testDispatchNowShouldNeverQueue()
	{
		$container = new Container;
		$handler = m::mock('StdClass');
		$handler->shouldReceive('handle')->once()->andReturn('foo');
		$container->instance('Handler', $handler);
		$dispatcher = new Dispatcher($container);
		$dispatcher->mapUsing(function() { return 'Handler@handle'; });

		$result = $dispatcher->dispatch(m::mock('Illuminate\Contracts\Queue\ShouldBeQueued'));
		$this->assertEquals('foo', $result);
	}

}

class BusDispatcherTestBasicCommand {

}

class BusDispatcherTestBasicHandler {
	public function handle(BusDispatcherTestBasicCommand $command)
	{

	}
}
<commit_msg>Test queued handlers.<commit_after><?php

use Mockery as m;
use Illuminate\Bus\Dispatcher;
use Illuminate\Container\Container;

class BusDispatcherTest extends PHPUnit_Framework_TestCase {

	public function tearDown()
	{
		m::close();
	}


	public function testBasicDispatchingOfCommandsToHandlers()
	{
		$container = new Container;
		$handler = m::mock('StdClass');
		$handler->shouldReceive('handle')->once()->andReturn('foo');
		$container->instance('Handler', $handler);
		$dispatcher = new Dispatcher($container);
		$dispatcher->mapUsing(function() { return 'Handler@handle'; });

		$result = $dispatcher->dispatch(new BusDispatcherTestBasicCommand);
		$this->assertEquals('foo', $result);
	}


	public function testCommandsThatShouldBeQueuedAreQueued()
	{
		$container = new Container;
		$dispatcher = new Dispatcher($container, function() {
			$mock = m::mock('Illuminate\Contracts\Queue\Queue');
			$mock->shouldReceive('push')->once();
			return $mock;
		});

		$dispatcher->dispatch(m::mock('Illuminate\Contracts\Queue\ShouldBeQueued'));
	}


	public function testHandlersThatShouldBeQueuedAreQueued()
	{
		$container = new Container;
		$dispatcher = new Dispatcher($container, function() {
			$mock = m::mock('Illuminate\Contracts\Queue\Queue');
			$mock->shouldReceive('push')->once();
			return $mock;
		});
		$dispatcher->mapUsing(function() { return 'BusDispatcherTestQueuedHandler@handle'; });

		$dispatcher->dispatch(new BusDispatcherTestBasicCommand);
	}


	public function testDispatchNowShouldNeverQueue()
	{
		$container = new Container;
		$handler = m::mock('StdClass');
		$handler->shouldReceive('handle')->once()->andReturn('foo');
		$container->instance('Handler', $handler);
		$dispatcher = new Dispatcher($container);
		$dispatcher->mapUsing(function() { return 'Handler@handle'; });

		$result = $dispatcher->dispatch(m::mock('Illuminate\Contracts\Queue\ShouldBeQueued'));
		$this->assertEquals('foo', $result);
	}

}

class BusDispatcherTestBasicCommand {

}

class BusDispatcherTestBasicHandler {
	public function handle(BusDispatcherTestBasicCommand $command)
	{

	}
}

class BusDispatcherTestQueuedHandler implements Illuminate\Contracts\Queue\ShouldBeQueued {

}

{'fraction_non_alphanumeric': 0.15464184122058444, 'fraction_numerical': 0.0, 'mean_word_length': 6.2164179104477615, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3722877', 'n_tokens_mistral': 1244, 'n_tokens_neox': 1155, 'n_words': 194}