<commit_before><?php
/**
 * This file is part of the daikon-cqrs/cqrs project.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Daikon\Tests\EventSourcing;

use Daikon\EventSourcing\Aggregate\AggregateId;
use Daikon\EventSourcing\Aggregate\DomainEventSequenceInterface;
use Daikon\Tests\EventSourcing\Aggregate\Mock\BakePizza;
use Daikon\Tests\EventSourcing\Aggregate\Mock\Pizza;
use Daikon\Tests\EventSourcing\Aggregate\Mock\PizzaWasBaked;
use PHPUnit\Framework\TestCase;

final class AggregateRootTest extends TestCase
{
    public function testStartAggregateRootLifecycle()
    {
        $ingredients = ['mushrooms', 'tomatoes', 'onions'];
        /** @var $bakePizza BakePizza */
        $bakePizza = BakePizza::fromArray([
            'aggregateId' => 'pizza-42-6-23',
            'ingredients' => $ingredients
        ]);
        $pizza = Pizza::bake($bakePizza);

        $this->assertEquals('pizza-42-6-23', $pizza->getIdentifier());
        $this->assertEquals(1, $pizza->getRevision()->toNative());
        $this->assertEquals($ingredients, $pizza->getIngredients());
        $this->assertCount(1, $pizza->getTrackedEvents());
    }

    public function testReconstituteFromHistory()
    {
        /** @var $pizzaId AggregateId */
        $pizzaId = AggregateId::fromNative('pizza-42-6-23');
        $ingredients = ['mushrooms', 'tomatoes', 'onions'];

        $domainEventSequenceMock = $this->createMock(DomainEventSequenceInterface::class);
        $domainEventSequenceMock
            ->expects($this->once())
            ->method('getIterator')
            ->willReturn(new \ArrayIterator([PizzaWasBaked::fromArray([
                'aggregateId' => (string)$pizzaId,
                'aggregateRevision' => 1,
                'ingredients' => $ingredients
            ])]));

        /** @var $pizza Pizza */
        $pizza = Pizza::reconstituteFromHistory($pizzaId, $domainEventSequenceMock);

        $this->assertEquals($pizzaId, $pizza->getIdentifier());
        $this->assertEquals(1, $pizza->getRevision()->toNative());
        $this->assertEquals($ingredients, $pizza->getIngredients());
        $this->assertCount(0, $pizza->getTrackedEvents());
    }

    public function testMarkClean()
    {
        /** @var $bakePizza BakePizza */
        $bakePizza = BakePizza::fromArray([
            'aggregateId' => 'pizza-42-6-23',
            'ingredients' => ['mushrooms', 'tomatoes', 'onions']
        ]);
        $pizza = Pizza::bake($bakePizza)->markClean();
        $this->assertCount(0, $pizza->getTrackedEvents());
    }<commit_msg>cleanup AR test<commit_after><?php
/**
 * This file is part of the daikon-cqrs/cqrs project.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Daikon\Tests\EventSourcing;

use Daikon\EventSourcing\Aggregate\AggregateId;
use Daikon\EventSourcing\Aggregate\DomainEventSequenceInterface;
use Daikon\Tests\EventSourcing\Aggregate\Mock\BakePizza;
use Daikon\Tests\EventSourcing\Aggregate\Mock\Pizza;
use Daikon\Tests\EventSourcing\Aggregate\Mock\PizzaWasBaked;
use PHPUnit\Framework\TestCase;

final class AggregateRootTest extends TestCase
{
    public function testStartAggregateRootLifecycle()
    {
        $ingredients = ['mushrooms', 'tomatoes', 'onions'];
        /** @var $bakePizza BakePizza */
        $bakePizza = BakePizza::fromArray([
            'aggregateId' => 'pizza-42-6-23',
            'ingredients' => $ingredients
        ]);
        $pizza = Pizza::bake($bakePizza);

        $this->assertEquals('pizza-42-6-23', $pizza->getIdentifier());
        $this->assertEquals(1, $pizza->getRevision()->toNative());
        $this->assertEquals($ingredients, $pizza->getIngredients());
        $this->assertCount(1, $pizza->getTrackedEvents());
    }

    public function testReconstituteFromHistory()
    {
        /** @var $pizzaId AggregateId */
        $pizzaId = AggregateId::fromNative('pizza-42-6-23');
        $ingredients = ['mushrooms', 'tomatoes', 'onions'];
        $pizzaWasBaked = PizzaWasBaked::fromArray([
            'aggregateId' => (string)$pizzaId,
            'aggregateRevision' => 1,
            'ingredients' => $ingredients
        ]);

        $domainEventSequenceMock = $this->createMock(DomainEventSequenceInterface::class);
        $domainEventSequenceMock
            ->expects($this->once())
            ->method('getIterator')
            ->willReturn(new \ArrayIterator([ $pizzaWasBaked ]));

        /** @var $pizza Pizza */
        $pizza = Pizza::reconstituteFromHistory($pizzaId, $domainEventSequenceMock);

        $this->assertEquals($pizzaId, $pizza->getIdentifier());
        $this->assertEquals(1, $pizza->getRevision()->toNative());
        $this->assertEquals($ingredients, $pizza->getIngredients());
        $this->assertCount(0, $pizza->getTrackedEvents());
    }

    public function testMarkClean()
    {
        /** @var $bakePizza BakePizza */
        $bakePizza = BakePizza::fromArray([
            'aggregateId' => 'pizza-42-6-23',
            'ingredients' => ['mushrooms', 'tomatoes', 'onions']
        ]);
        $pizza = Pizza::bake($bakePizza)->markClean();

        $this->assertCount(0, $pizza->getTrackedEvents());
    }
{'fraction_non_alphanumeric': 0.15107646622123236, 'fraction_numerical': 0.01002227171492205, 'mean_word_length': 3.1872571872571873, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 69, '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': '5270753', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1654, 'n_words': 267}