<commit_before><?php

namespace Enqueue\AmqpLib\Tests\Spec;

use Enqueue\AmqpLib\AmqpConnectionFactory;
use Enqueue\AmqpLib\AmqpContext;
use Interop\Amqp\AmqpTopic;
use Interop\Amqp\Impl\AmqpBind;
use Interop\Queue\PsrContext;
use Interop\Queue\Spec\SendToTopicAndReceiveFromQueueSpec;

/**
 * @group functional
 */
class AmqpSendToTopicAndReceiveFromQueueWithBasicConsumeMethodTest extends SendToTopicAndReceiveFromQueueSpec
{
    private $topic;

    /**
     * {@inheritdoc}
     */
    protected function createContext()
    {
        $factory = new AmqpConnectionFactory(getenv('AMQP_DSN').'?receive_method=basic_consume');

        return $factory->createContext();
    }

    /**
     * {@inheritdoc}
     *
     * @param AmqpContext $context
     */
    protected function createQueue(PsrContext $context, $queueName)
    {
        $queueName .= '_basic_consume';

//        $queue = $context->createQueue($queueName);
        $queue = $context->createQueue('send_to_topic_and_receive_from_queue_spec_basic_consume4');

        try {
            $context->deleteQueue($queue);
        } catch (\Exception $e) {}

        $context->declareQueue($queue);
        $context->purgeQueue($queue);

        $context->bind(new AmqpBind($this->topic, $queue));

        return $queue;
    }

    /**
     * {@inheritdoc}
     *
     * @param AmqpContext $context
     */
    protected function createTopic(PsrContext $context, $topicName)
    {
        $topicName .= '_basic_consume';

//        $topic = $context->createTopic($topicName);
        $topic = $context->createTopic('send_to_topic_and_receive_from_queue_spec_basic_consume4');
        $topic->setType(AmqpTopic::TYPE_FANOUT);
        $topic->addFlag(AmqpTopic::FLAG_DURABLE);

        try {
            $context->deleteQueue($topic);
        } catch (\Exception $e) {}

        $context->declareTopic($topic);

        return $this->topic = $topic;
    }
}<commit_msg>fix tests<commit_after><?php

namespace Enqueue\AmqpLib\Tests\Spec;

use Enqueue\AmqpLib\AmqpConnectionFactory;
use Interop\Amqp\AmqpTopic;
use Interop\Amqp\Impl\AmqpBind;
use Interop\Queue\PsrMessage;
use Interop\Queue\Spec\SendToTopicAndReceiveFromQueueSpec;

/**
 * @group functional
 */
class AmqpSendToTopicAndReceiveFromQueueWithBasicConsumeMethodTest extends SendToTopicAndReceiveFromQueueSpec
{
    private $topic;

    /**
     * {@inheritdoc}
     */
    protected function createContext()
    {
        $factory = new AmqpConnectionFactory(getenv('AMQP_DSN').'?receive_method=basic_consume');

        return $factory->createContext();
    }

    public function test()
    {
        $context = $this->createContext();

        $topic = $context->createTopic('send_to_topic_and_receive_from_queue_spec_basic_consume');
        $topic->setType(AmqpTopic::TYPE_FANOUT);
        $topic->addFlag(AmqpTopic::FLAG_DURABLE);
        $context->declareTopic($topic);

        $queue = $context->createQueue('send_to_topic_and_receive_from_queue_spec_basic_consume');
        $context->declareQueue($queue);
        $context->purgeQueue($queue);

        $context->bind(new AmqpBind($topic, $queue));

        $consumer = $context->createConsumer($queue);

        // guard
        $this->assertNull($consumer->receiveNoWait());

        $expectedBody = __CLASS__.time();

        $context->createProducer()->send($topic, $context->createMessage($expectedBody));

        $message = $consumer->receive(2000); // 2 sec

        $this->assertInstanceOf(PsrMessage::class, $message);
        $consumer->acknowledge($message);

        $this->assertSame($expectedBody, $message->getBody());
    }
}
{'fraction_non_alphanumeric': 0.13544827586206898, 'fraction_numerical': 0.0019310344827586207, 'mean_word_length': 3.384522370012092, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '5221624', 'n_tokens_mistral': 1144, 'n_tokens_neox': 1089, 'n_words': 150}