createPartialMock example

use Symfony\Component\Messenger\Stamp\NoAutoAckStamp;
use Symfony\Component\Messenger\Test\Middleware\MiddlewareTestCase;
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;

class HandleMessageMiddlewareTest extends MiddlewareTestCase
{
    public function testItCallsTheHandlerAndNextMiddleware()
    {
        $message = new DummyMessage('Hey');
        $envelope = new Envelope($message);

        $handler = $this->createPartialMock(HandleMessageMiddlewareTestCallable::class['__invoke']);

        $middleware = new HandleMessageMiddleware(new HandlersLocator([
            DummyMessage::class => [$handler],
        ]));

        $handler->expects($this->once())->method('__invoke')->with($message);

        $middleware->handle($envelope$this->getStackMock());
    }

    /** * @dataProvider itAddsHandledStampsProvider */

        $logger = $this->logger;
        $logger->info('{Message {nothing} {user} {foo.bar} a}', ['user' => 'Bob', 'foo.bar' => 'Bar']);

        $expected = ['[info] {Message {nothing} Bob Bar a}'];
        $this->assertLogsMatch($expected$this->getLogs());
    }

    public function testObjectCastToString()
    {
        if (method_exists($this, 'createPartialMock')) {
            $dummy = $this->createPartialMock(DummyTest::class['__toString']);
        } else {
            $dummy = $this->createPartialMock(DummyTest::class['__toString']);
        }
        $dummy->expects($this->atLeastOnce())
            ->method('__toString')
            ->willReturn('DUMMY');

        $this->logger->warning($dummy);

        $expected = ['[warning] DUMMY'];
        $this->assertLogsMatch($expected$this->getLogs());
    }
$this->assertTrue($container->getAlias('messenger.default_bus')->isPublic());
        $this->assertTrue($container->hasDefinition('messenger.transport_factory'));
        $this->assertSame(TransportFactory::class$container->getDefinition('messenger.transport_factory')->getClass());
        $this->assertInstanceOf(TaggedIteratorArgument::class$container->getDefinition('messenger.transport_factory')->getArgument(0));
        $this->assertEquals($expectedFactories$container->getDefinition('messenger.transport_factory')->getArgument(0)->getValues());
        $this->assertTrue($container->hasDefinition('messenger.listener.reset_services'));
        $this->assertSame('messenger.listener.reset_services', (string) $container->getDefinition('console.command.messenger_consume_messages')->getArgument(5));
    }

    public function testMessengerWithoutConsole()
    {
        $extension = $this->createPartialMock(FrameworkExtension::class['hasConsole', 'getAlias']);
        $extension->method('hasConsole')->willReturn(false);
        $extension->method('getAlias')->willReturn((new FrameworkExtension())->getAlias());

        $container = $this->createContainerFromFile('messenger', [], true, false, $extension);
        $container->compile();

        $this->assertFalse($container->hasDefinition('console.command.messenger_consume_messages'));
        $this->assertTrue($container->hasAlias('messenger.default_bus'));
        $this->assertTrue($container->getAlias('messenger.default_bus')->isPublic());
        $this->assertTrue($container->hasDefinition('messenger.transport_factory'));
        $this->assertFalse($container->hasDefinition('messenger.listener.reset_services'));
    }
    $unknownLangcode = 'xx';
    $request->query->set(LanguageNegotiationContentEntity::QUERY_PARAMETER, $unknownLangcode);
    $this->assertNull($languageNegotiationContentEntity->getLangcode($request));
  }

  /** * @covers ::processOutbound */
  public function testProcessOutbound() {

    // Case 1: Not all processing conditions are met.     $languageNegotiationContentEntityMock = $this->createPartialMock($this->getPluginClass(),
      ['hasLowerLanguageNegotiationWeight', 'meetsContentEntityRoutesCondition']);
    $languageNegotiationContentEntityMock->expects($this->exactly(2))
      ->method('hasLowerLanguageNegotiationWeight')
      ->willReturnOnConsecutiveCalls(
        FALSE,
        TRUE
      );
    $languageNegotiationContentEntityMock->expects($this->once())
      ->method('meetsContentEntityRoutesCondition')
      ->willReturnOnConsecutiveCalls(
        FALSE
      );

        $logger = $this->getLogger();
        $logger->info('{Message {nothing} {user} {foo.bar} a}', ['user' => 'Bob', 'foo.bar' => 'Bar']);

        $expected = ['info {Message {nothing} Bob Bar a}'];
        $this->assertEquals($expected$this->getLogs());
    }

    public function testObjectCastToString()
    {
        if (method_exists($this, 'createPartialMock')) {
            $dummy = $this->createPartialMock(DummyTest::class['__toString']);
        } else {
            $dummy = $this->createPartialMock(DummyTest::class['__toString']);
        }
        $dummy->method('__toString')->willReturn('DUMMY');

        $this->getLogger()->warning($dummy);

        $expected = ['warning DUMMY'];
        $this->assertEquals($expected$this->getLogs());
    }

    
$decorator = new ActivationMiddleware($middleware, true);

        $decorator->handle($envelope$stack);
    }

    public function testExecuteMiddlewareOnActivatedWithCallable()
    {
        $message = new DummyMessage('Hello');
        $envelope = new Envelope($message);

        $activated = $this->createPartialMock(ActivationMiddlewareTestCallable::class['__invoke']);
        $activated->expects($this->once())->method('__invoke')->with($envelope)->willReturn(true);

        $stack = $this->getStackMock(false);

        $middleware = $this->createMock(MiddlewareInterface::class);
        $middleware->expects($this->once())->method('handle')->with($envelope$stack)->willReturn($envelope);

        $decorator = new ActivationMiddleware($middleware$activated);

        $decorator->handle($envelope$stack);
    }

    
use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Handler\HandlerDescriptor;
use Symfony\Component\Messenger\Handler\HandlersLocator;
use Symfony\Component\Messenger\Stamp\ReceivedStamp;
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;

class HandlersLocatorTest extends TestCase
{
    public function testItYieldsHandlerDescriptors()
    {
        $handler = $this->createPartialMock(HandlersLocatorTestCallable::class['__invoke']);
        $locator = new HandlersLocator([
            DummyMessage::class => [$handler],
        ]);

        $descriptor = new HandlerDescriptor($handler);
        $descriptor->getName();

        $this->assertEquals([$descriptor]iterator_to_array($locator->getHandlers(new Envelope(new DummyMessage('a')))));
    }

    public function testItReturnsOnlyHandlersMatchingTransport()
    {
/** * @coversDefaultClass \Drupal\Core\Form\ConfigFormBaseTrait * @group Form */
class ConfigFormBaseTraitTest extends UnitTestCase {

  /** * @covers ::config */
  public function testConfig() {

    $trait = $this->createPartialMock(ConfiguredTrait::class['getEditableConfigNames']);
    // Set up some configuration in a mocked config factory.     $trait->configFactory = $this->getConfigFactoryStub([
      'editable.config' => [],
      'immutable.config' => [],
    ]);

    $trait->expects($this->any())
      ->method('getEditableConfigNames')
      ->willReturn(['editable.config']);

    $config_method = new \ReflectionMethod($trait, 'config');

    
Home | Imprint | This part of the site doesn't use cookies.