<commit_before><?php

namespace spec\AppBundle\EventSubscriber;

use AppBundle\Entity\Article;
use AppBundle\Entity\Post;
use AppBundle\Entity\Topic;
use AppBundle\EventSubscriber\CreateTopicForArticleSubscriber;
use AppBundle\Factory\TopicFactory;
use AppBundle\Repository\TopicRepository;
use Doctrine\Common\Persistence\ObjectManager;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Component\Customer\Model\CustomerInterface;
use Symfony\Component\EventDispatcher\GenericEvent;

class CreateTopicForArticleSubscriberSpec extends ObjectBehavior
{
    function let(
        ObjectManager $manager,
        TopicRepository $topicRepository,
        TopicFactory $topicFactory
    ) {
        $this->beConstructedWith($manager, $topicRepository, $topicFactory);
    }

    function it_is_initializable()
    {
        $this->shouldHaveType(CreateTopicForArticleSubscriber::class);
    }

    function it_creates_topic_for_article(
        GenericEvent $event,
        Post $post,
        Topic $topic,
        Article $article,
        TopicRepository $topicRepository,
        TopicFactory $topicFactory,
        CustomerInterface $author
    ): void
    {
        $event->getSubject()->willReturn($post);
        $post->getArticle()->willReturn($article);
        $topicRepository->findOneByArticle($article)->willReturn(null);
        $topicFactory->createForArticle($article)->willReturn($topic);
        $post->getAuthor()->willReturn($author);

        $topicFactory->createForArticle($article)->shouldBeCalled();

        $this->onCreate($event);
    }
}<commit_msg>add a test on create topic for article subscriber<commit_after><?php

namespace spec\AppBundle\EventSubscriber;

use AppBundle\Entity\Article;
use AppBundle\Entity\Post;
use AppBundle\Entity\Topic;
use AppBundle\EventSubscriber\CreateTopicForArticleSubscriber;
use AppBundle\Factory\TopicFactory;
use AppBundle\Repository\TopicRepository;
use Doctrine\Common\Persistence\ObjectManager;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Component\Customer\Model\CustomerInterface;
use Symfony\Component\EventDispatcher\GenericEvent;

class CreateTopicForArticleSubscriberSpec extends ObjectBehavior
{
    function let(
        ObjectManager $manager,
        TopicRepository $topicRepository,
        TopicFactory $topicFactory
    ) {
        $this->beConstructedWith($manager, $topicRepository, $topicFactory);
    }

    function it_is_initializable()
    {
        $this->shouldHaveType(CreateTopicForArticleSubscriber::class);
    }

    function it_creates_topic_for_article(
        GenericEvent $event,
        Post $post,
        Topic $topic,
        Article $article,
        TopicRepository $topicRepository,
        TopicFactory $topicFactory,
        CustomerInterface $author
    ): void
    {
        $event->getSubject()->willReturn($post);
        $post->getArticle()->willReturn($article);
        $topicRepository->findOneByArticle($article)->willReturn(null);
        $topicFactory->createForArticle($article)->willReturn($topic);
        $post->getAuthor()->willReturn($author);

        $topicFactory->createForArticle($article)->shouldBeCalled();

        $this->onCreate($event);
    }

    function it_does_not_create_new_topic_for_article_if_exist(
        GenericEvent $event,
        Post $post,
        Topic $topic,
        Article $article,
        TopicRepository $topicRepository,
        TopicFactory $topicFactory,
        CustomerInterface $author
    ): void
    {
        $event->getSubject()->willReturn($post);
        $post->getArticle()->willReturn($article);
        $topicRepository->findOneByArticle($article)->willReturn($topic);
        $post->getAuthor()->willReturn($author);

        $topicFactory->createForArticle($article)->shouldNotBeCalled();

        $this->onCreate($event);
    }
}
{'fraction_non_alphanumeric': 0.10917144346013549, 'fraction_numerical': 0.0, 'mean_word_length': 3.7927590511860174, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 44, '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': '3141583', 'n_tokens_mistral': 1057, 'n_tokens_neox': 1014, 'n_words': 165}