<commit_before><?php

namespace Tienvx\Bundle\MbtBundle\Tests\Message;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Exception;
use Tienvx\Bundle\MbtBundle\Entity\Bug;
use Tienvx\Bundle\MbtBundle\Entity\Generator;
use Tienvx\Bundle\MbtBundle\Entity\Model;
use Tienvx\Bundle\MbtBundle\Entity\Reducer;
use Tienvx\Bundle\MbtBundle\Entity\Reporter;
use Tienvx\Bundle\MbtBundle\Entity\Task;
use Tienvx\Bundle\MbtBundle\Workflow\BugWorkflow;
use Tienvx\Bundle\MbtBundle\Workflow\TaskWorkflow;

class TaskMessageTest extends MessageTestCase
{
    /**
     * @throws Exception
     * @dataProvider consumeMessageData
     */
    public function testExecute(string $model, string $generator, string $reducer, bool $takeScreenshots, bool $reportBug)
    {
        $this->clearMessages();
        $this->clearEmails();
        $this->removeScreenshots();

        /** @var EntityManagerInterface $entityManager */
        $entityManager = self::$container->get(EntityManagerInterface::class);

        $task = new Task();
        $task->setTitle('Test task title');
        $task->setModel(new Model($model));
        $task->setGenerator(new Generator($generator));
        $task->setReducer(new Reducer($reducer));
        $task->setTakeScreenshots($takeScreenshots);
        // Use default generator options.
        //$task->setGeneratorOptions($generatorOptions);
        if ($reportBug) {
            $task->setReporters([new Reporter('email')]);
        }
        $entityManager->persist($task);
        $entityManager->flush();

        $this->consumeMessages();

        $task = $entityManager->getRepository(Task::class)->findOneBy(['id' => $task->getId()]);

        /** @var EntityRepository $entityRepository */
        $entityRepository = $entityManager->getRepository(Bug::class);
        /** @var Bug[] $bugs */
        $bugs = $entityRepository->findAll();

        if (count($bugs)) {
            $this->assertEquals(1, count($bugs));
            if ('shopping_cart' === $model) {
                $ids = [];
                foreach ($bugs[0]->getSteps() as $step) {
                    if ($step->getData() && $step->getData()->has('product')) {
                        $ids[] = $step->getData()->get('product');
                    }
                }
                if ('You added an out-of-stock product into cart! Can not checkout' === $bugs[0]->getBugMessage()) {
                    $this->assertContains(49, $ids);
                } elseif ('You need to specify options for this product! Can not add product' === $bugs[0]->getBugMessage()) {
                    $this->assertGreaterThanOrEqual(1, count(array_intersect([42, 30, 35], $ids)));<commit_msg>Cast string to int<commit_after><?php

namespace Tienvx\Bundle\MbtBundle\Tests\Message;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Exception;
use Tienvx\Bundle\MbtBundle\Entity\Bug;
use Tienvx\Bundle\MbtBundle\Entity\Generator;
use Tienvx\Bundle\MbtBundle\Entity\Model;
use Tienvx\Bundle\MbtBundle\Entity\Reducer;
use Tienvx\Bundle\MbtBundle\Entity\Reporter;
use Tienvx\Bundle\MbtBundle\Entity\Task;
use Tienvx\Bundle\MbtBundle\Workflow\BugWorkflow;
use Tienvx\Bundle\MbtBundle\Workflow\TaskWorkflow;

class TaskMessageTest extends MessageTestCase
{
    /**
     * @throws Exception
     * @dataProvider consumeMessageData
     */
    public function testExecute(string $model, string $generator, string $reducer, bool $takeScreenshots, bool $reportBug)
    {
        $this->clearMessages();
        $this->clearEmails();
        $this->removeScreenshots();

        /** @var EntityManagerInterface $entityManager */
        $entityManager = self::$container->get(EntityManagerInterface::class);

        $task = new Task();
        $task->setTitle('Test task title');
        $task->setModel(new Model($model));
        $task->setGenerator(new Generator($generator));
        $task->setReducer(new Reducer($reducer));
        $task->setTakeScreenshots($takeScreenshots);
        // Use default generator options.
        //$task->setGeneratorOptions($generatorOptions);
        if ($reportBug) {
            $task->setReporters([new Reporter('email')]);
        }
        $entityManager->persist($task);
        $entityManager->flush();

        $this->consumeMessages();

        $task = $entityManager->getRepository(Task::class)->findOneBy(['id' => $task->getId()]);

        /** @var EntityRepository $entityRepository */
        $entityRepository = $entityManager->getRepository(Bug::class);
        /** @var Bug[] $bugs */
        $bugs = $entityRepository->findAll();

        if (count($bugs)) {
            $this->assertEquals(1, count($bugs));
            if ('shopping_cart' === $model) {
                $ids = [];
                foreach ($bugs[0]->getSteps() as $step) {
                    if ($step->getData() && $step->getData()->has('product')) {
                        $ids[] = (int) $step->getData()->get('product');
                    }
                }
                if ('You added an out-of-stock product into cart! Can not checkout' === $bugs[0]->getBugMessage()) {
                    $this->assertContains(49, $ids);
                } elseif ('You need to specify options for this product! Can not add product' === $bugs[0]->getBugMessage()) {
                    $this->assertGreaterThanOrEqual(1, count(array_intersect([42, 30, 35], $ids)));
{'fraction_non_alphanumeric': 0.1518005540166205, 'fraction_numerical': 0.004801477377654663, 'mean_word_length': 2.800701754385965, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 65, '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': '2471149', 'n_tokens_mistral': 1619, 'n_tokens_neox': 1518, 'n_words': 285}