<commit_before><?php

namespace CQRSTest\CommandHandling;

use CQRS\CommandHandling\Locator\CommandHandlerLocatorInterface;
use CQRS\CommandHandling\SequentialCommandBus;
use CQRS\CommandHandling\TransactionManager\TransactionManagerInterface;
use CQRS\EventHandling\Publisher\EventPublisherInterface;
use PHPUnit_Framework_TestCase;
use Psr\Log\NullLogger;

class SequentialCommandBusTest extends PHPUnit_Framework_TestCase
{
    /** @var SequentialCommandBus */
    protected $commandBus;
    /** @var SequentialCommandHandler */
    protected $handler;
    /** @var SequentialTransactionManager */
    protected $transactionManager;
    /** @var SequentialEventPublisher */
    protected $eventPublisher;

    public function setUp()
    {
        $this->handler = new SequentialCommandHandler();

        $locator = new SequentialCommandHandlerLocator();
        $locator->handler = $this->handler;

        $this->transactionManager = new SequentialTransactionManager();

        $this->eventPublisher = new SequentialEventPublisher();

        $this->commandBus = new SequentialCommandBus($locator, $this->transactionManager, $this->eventPublisher, new NullLogger());
        $this->handler->commandBus = $this->commandBus;
    }

    public function testHandlingOfSequentialCommand()
    {
        $this->commandBus->dispatch(new DoSequentialCommand());

        $this->assertEquals(1, $this->handler->sequential);
        $this->assertEquals(1, $this->handler->simple);

        $this->assertEquals(1, $this->transactionManager->begin);
        $this->assertEquals(1, $this->transactionManager->commit);
        $this->assertEquals(0, $this->transactionManager->rollback);

        $this->assertEquals(1, $this->eventPublisher->published);
    }

    public function testItRollbacksTransactionOnFailure()
    {
        $this->setExpectedException('CQRSTest\CommandHandling\CommandFailureTestException');

        try {
            $this->commandBus->dispatch(new DoFailureCommand());
        } catch (CommandFailureTestException $e) {

            $this->assertEquals(1, $this->transactionManager->begin);
            $this->assertEquals(0, $this->transactionManager->commit);
            $this->assertEquals(1, $this->transactionManager->rollback);

            $this->assertEquals(0, $this->eventPublisher->published);

            throw $e;
        }
    }

    public function testItIgnoresErrorOnSequentialFailure()
    {
        $this->commandBus->dispatch(new DoSequentialFailureCommand());

        $this->assertEquals(1, $this->transactionManager->begin);
        $this->assertEquals(1, $this->transactionManager->commit);
        $this->assertEquals(0, $this->transactionManager->rollback);
<commit_msg>Do not suppress exceptions in command handling - adjust test<commit_after><?php

namespace CQRSTest\CommandHandling;

use CQRS\CommandHandling\Locator\CommandHandlerLocatorInterface;
use CQRS\CommandHandling\SequentialCommandBus;
use CQRS\CommandHandling\TransactionManager\TransactionManagerInterface;
use CQRS\EventHandling\Publisher\EventPublisherInterface;
use PHPUnit_Framework_TestCase;
use Psr\Log\NullLogger;

class SequentialCommandBusTest extends PHPUnit_Framework_TestCase
{
    /** @var SequentialCommandBus */
    protected $commandBus;
    /** @var SequentialCommandHandler */
    protected $handler;
    /** @var SequentialTransactionManager */
    protected $transactionManager;
    /** @var SequentialEventPublisher */
    protected $eventPublisher;

    public function setUp()
    {
        $this->handler = new SequentialCommandHandler();

        $locator = new SequentialCommandHandlerLocator();
        $locator->handler = $this->handler;

        $this->transactionManager = new SequentialTransactionManager();

        $this->eventPublisher = new SequentialEventPublisher();

        $this->commandBus = new SequentialCommandBus($locator, $this->transactionManager, $this->eventPublisher, new NullLogger());
        $this->handler->commandBus = $this->commandBus;
    }

    public function testHandlingOfSequentialCommand()
    {
        $this->commandBus->dispatch(new DoSequentialCommand());

        $this->assertEquals(1, $this->handler->sequential);
        $this->assertEquals(1, $this->handler->simple);

        $this->assertEquals(1, $this->transactionManager->begin);
        $this->assertEquals(1, $this->transactionManager->commit);
        $this->assertEquals(0, $this->transactionManager->rollback);

        $this->assertEquals(1, $this->eventPublisher->published);
    }

    public function testItRollbacksTransactionOnFailure()
    {
        $this->setExpectedException('CQRSTest\CommandHandling\CommandFailureTestException');

        try {
            $this->commandBus->dispatch(new DoFailureCommand());
        } catch (CommandFailureTestException $e) {

            $this->assertEquals(1, $this->transactionManager->begin);
            $this->assertEquals(0, $this->transactionManager->commit);
            $this->assertEquals(1, $this->transactionManager->rollback);

            $this->assertEquals(0, $this->eventPublisher->published);

            throw $e;
        }
    }

    public function testItDoesntIgnoreErrorOnSequentialFailure()
    {
        $this->setExpectedException('CQRSTest\CommandHandling\CommandFailureTestException');

        $this->commandBus->dispatch(new DoSequentialFailureCommand());

        $this->assertEquals(1, $this->transactionManager->begin);
        $this->assertEquals(1, $this->transactionManager->commit);
        $this->assertEquals(0, $this->transactionManager->rollback);

{'fraction_non_alphanumeric': 0.12437365783822477, 'fraction_numerical': 0.0046528274874731565, 'mean_word_length': 3.8854895104895104, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 118, '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': '3520388', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1427, 'n_words': 227}