expectExceptionMessageMatches example

static::assertNull($response->getContext());
    }

    public function testSetData(): void
    {
        $response = new StorefrontResponse();

        $response->setData([]);
        static::assertEmpty($response->getData());

        /** @deprecated tag:v6.6.0 - This can be removed if parameter `$data` will be strictly typed to `array` in `setData` */
        $this->expectExceptionMessageMatches('/deprecated functionality:/');
        $response->setData(null);
    }

    public function testSetContext(): void
    {
        $response = new StorefrontResponse();

        $salesChannelContext = $this->createSalesChannelContext();
        $response->setContext($salesChannelContext);
        $retrievedSalesChannelContext = $response->getContext();

        
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures/controller']));
        $routeCollection = $loader->load('routing.xml');

        $route = $routeCollection->get('app_blog');

        $this->assertSame('AppBundle:Blog:list', $route->getDefault('_controller'));
    }

    public function testOverrideControllerInDefaults()
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessageMatches('/The routing file "[^"]*" must not specify both the "controller" attribute and the defaults key "_controller" for "app_blog"/');
        $loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures/controller']));
        $loader->load('override_defaults.xml');
    }

    /** * @dataProvider provideFilesImportingRoutesWithControllers */
    public function testImportRouteWithController($file)
    {
        $loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures/controller']));
        $routeCollection = $loader->load($file);

        
// Expect no exception was thrown         $this->addToAssertionCount(1);
    }

    public function testEncodeChaingingStateMachineStateIdNotAllowedWhenWrongScope(): void
    {
        $payload = $this->createOrderPayload();
        $this->orderRepository->create([$payload]$this->context);

        $this->expectException(WriteException::class);
        $this->expectExceptionMessageMatches('|There are 1 error\\(s\\) while writing data\\.|');
        $this->expectExceptionMessageMatches(
            '|\\[/0/stateId\\] Changing the state-machine-state of this entity is not allowed for scope user\\. '
            . 'Either change the state-machine-state via a state-transition or use a different scope\\.|'
        );

        $this->context->scope(Context::USER_SCOPE, function DContext $context) use ($payload): void {
            $this->orderRepository->update([
                [
                    'id' => $payload['id'],
                    'stateId' => $this->fetchOrderStateId(OrderStates::STATE_COMPLETED),
                ],
            ],

        $this->getResponseTester(new Response('', 302))->assertResponseRedirects(null, 302);
        $this->expectException(AssertionFailedError::class);
        $this->expectExceptionMessage('is redirected and status code is 301.');
        $this->getResponseTester(new Response('', 302))->assertResponseRedirects(null, 301);
    }

    public function testAssertResponseRedirectsWithLocationAndStatusCode()
    {
        $this->getResponseTester(new Response('', 302, ['Location' => 'https://example.com/']))->assertResponseRedirects('https://example.com/', 302);
        $this->expectException(AssertionFailedError::class);
        $this->expectExceptionMessageMatches('#(:?\( )?is redirected and has header "Location" with value "https://example\.com/" (:?\) )?and status code is 301\.#');
        $this->getResponseTester(new Response('', 302))->assertResponseRedirects('https://example.com/', 301);
    }

    public function testAssertResponseFormat()
    {
        $this->getResponseTester(new Response('', 200, ['Content-Type' => 'application/vnd.myformat']))->assertResponseFormatSame('custom');
        $this->getResponseTester(new Response('', 200, ['Content-Type' => 'application/ld+json']))->assertResponseFormatSame('jsonld');
        $this->getResponseTester(new Response())->assertResponseFormatSame(null);
        $this->expectException(AssertionFailedError::class);
        $this->expectExceptionMessage("Failed asserting that the Response format is jsonld.\nHTTP/1.0 200 OK");
        $this->getResponseTester(new Response())->assertResponseFormatSame('jsonld');
    }
$this->assertSame('file://'.$this->file, $resource->getResource(), '->getResource() returns the path to the schemed resource');
    }

    public function testToString()
    {
        $this->assertSame(realpath($this->file)(string) $this->resource);
    }

    public function testResourceDoesNotExist()
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessageMatches('/The file ".*" does not exist./');
        new FileResource('/____foo/foobar'.mt_rand(1, 999999));
    }

    public function testIsFresh()
    {
        $this->assertTrue($this->resource->isFresh($this->time), '->isFresh() returns true if the resource has not changed in same second');
        $this->assertTrue($this->resource->isFresh($this->time + 10), '->isFresh() returns true if the resource has not changed');
        $this->assertFalse($this->resource->isFresh($this->time - 86400), '->isFresh() returns false if the resource has been updated');
    }

    public function testIsFreshForDeletedResources()
    {
$this->assertSame(array_shift($series)$axis);
            })
        ;

        $this->propertyAccessor->setValue($car, 'structure.axes', $axesAfter);
    }

    public function testSetValueFailsIfNoAdderNorRemoverFound()
    {
        $this->expectException(NoSuchPropertyException::class);
        $this->expectExceptionMessageMatches('/Could not determine access type for property "axes" in class "Mock_PropertyAccessorCollectionTestCase_CarNoAdderAndRemover_[^"]*"./');
        $car = $this->createMock(__CLASS__.'_CarNoAdderAndRemover');
        $axesBefore = $this->getContainer([1 => 'second', 3 => 'fourth']);
        $axesAfter = $this->getContainer([0 => 'first', 1 => 'second', 2 => 'third']);

        $car->expects($this->any())
            ->method('getAxes')
            ->willReturn($axesBefore);

        $this->propertyAccessor->setValue($car, 'axes', $axesAfter);
    }

    


    public static function unsupportedMessagesProvider(): iterable
    {
        yield [new SmsMessage('0611223344', 'Hello!')];
        yield [new DummyMessage()];
    }

    public function testSendWithErrorResponseThrowsTransportException()
    {
        $this->expectException(TransportException::class);
        $this->expectExceptionMessageMatches('/post.+testDescription.+400/');

        $response = $this->createMock(ResponseInterface::class);
        $response->expects($this->exactly(2))
            ->method('getStatusCode')
            ->willReturn(400);
        $response->expects($this->once())
            ->method('getContent')
            ->willReturn(json_encode(['description' => 'testDescription', 'error_code' => 400]));

        $client = new MockHttpClient(static fn (): ResponseInterface => $response);

        
/** * Tests that JavaScript console errors will result in a test failure. */
  public function testJavascriptErrors(): void {
    // Visit page that will throw a JavaScript console error.     $this->drupalGet('js_errors_test');
    // Ensure that errors from previous page loads will be     // detected.     $this->drupalGet('user');

    $this->expectException(AssertionFailedError::class);
    $this->expectExceptionMessageMatches('/^Error: A manually thrown error/');

    // Manually call the method under test, as it cannot be caught by PHPUnit     // when triggered from assertPostConditions().     $this->failOnJavaScriptErrors();
  }

  /** * Tests JavaScript console errors during asynchronous calls. */
  public function testJavascriptErrorsAsync(): void {
    // Visit page that will throw a JavaScript console error in async context.
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures/controller']));
        $routeCollection = $loader->load('routing.yml');

        $route = $routeCollection->get('app_blog');

        $this->assertSame('AppBundle:Blog:list', $route->getDefault('_controller'));
    }

    public function testOverrideControllerInDefaults()
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessageMatches('/The routing file "[^"]*" must not specify both the "controller" key and the defaults key "_controller" for "app_blog"/');
        $loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures/controller']));
        $loader->load('override_defaults.yml');
    }

    /** * @dataProvider provideFilesImportingRoutesWithControllers */
    public function testImportRouteWithController($file)
    {
        $loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures/controller']));
        $routeCollection = $loader->load($file);

        

        $this->expectException(ParseException::class);
        $this->expectExceptionMessage('The enum "Symfony\Component\Yaml\Tests\Fixtures\FooUnitEnum::BAR" defines no value next to its name');
        Inline::parse('!php/enum Symfony\Component\Yaml\Tests\Fixtures\FooUnitEnum::BAR->value', Yaml::PARSE_CONSTANT);
    }

    public function testParsePhpConstantThrowsExceptionOnInvalidType()
    {
        $this->assertNull(Inline::parse('!php/const PHP_INT_MAX'));

        $this->expectException(ParseException::class);
        $this->expectExceptionMessageMatches('#The string "!php/const PHP_INT_MAX" could not be parsed as a constant.*#');
        Inline::parse('!php/const PHP_INT_MAX', Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
    }

    public function testParsePhpEnumThrowsExceptionOnInvalidType()
    {
        $this->assertNull(Inline::parse('!php/enum SomeEnum::Foo'));

        $this->expectException(ParseException::class);
        $this->expectExceptionMessageMatches('#The string "!php/enum SomeEnum::Foo" could not be parsed as an enum.*#');
        Inline::parse('!php/enum SomeEnum::Foo', Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
    }

    
'annotations' => false,
                'http_method_override' => false,
                'handle_all_throwables' => true,
                'php_errors' => ['log' => true],
                'rate_limiter' => [
                    'without_lock' => ['policy' => 'fixed_window', 'limit' => 10, 'interval' => '1 hour', 'lock_factory' => null],
                ],
            ]);
        });

        $this->expectException(OutOfBoundsException::class);
        $this->expectExceptionMessageMatches('/^The argument "2" doesn\'t exist.*\.$/');

        $container->getDefinition('limiter.without_lock')->getArgument(2);
    }
}
$response = (new SyncPayResponse())->assign([
            'status' => StateMachineTransitionActions::ACTION_FAIL,
            'message' => self::ERROR_MESSAGE,
        ]);
        $this->appendNewResponse($this->signResponse($response->jsonSerialize()));

        if (!Feature::isActive('v6.6.0.0')) {
            $this->expectException(SyncPaymentProcessException::class);
        }
        $this->expectException(PaymentException::class);

        $this->expectExceptionMessageMatches(sprintf('/%s/', self::ERROR_MESSAGE));
        $this->paymentService->handlePaymentByOrder($orderIdnew RequestDataBag()$salesChannelContext);
    }

    public function testPayNoStateButMessage(): void
    {
        $paymentMethodId = $this->getPaymentMethodId('syncTracked');
        $orderId = $this->createOrder($paymentMethodId);
        $this->createTransaction($orderId$paymentMethodId);
        $salesChannelContext = $this->getSalesChannelContext($paymentMethodId);

        $response = (new SyncPayResponse())->assign([
            
$httpClient = $this->createMock(HttpClientInterface::class);

        $this->assertEquals(
            new Connection(['account' => 12345]new SqsClient(['endpoint' => 'https://custom-endpoint.tld', 'region' => 'eu-west-1', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)),
            Connection::fromDsn('sqs://default', ['endpoint' => 'https://custom-endpoint.tld', 'account' => 12345]$httpClient)
        );
    }

    public function testFromDsnWithInvalidQueryString()
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessageMatches('|Unknown option found in DSN: \[foo\]\. Allowed options are \[buffer_size, |');

        Connection::fromDsn('sqs://default?foo=foo');
    }

    public function testFromDsnWithInvalidOption()
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessageMatches('|Unknown option found: \[bar\]\. Allowed options are \[buffer_size, |');

        Connection::fromDsn('sqs://default', ['bar' => 'bar']);
    }

    
public static function setUpBeforeClass(): void
    {
        self::$fixturesPath = realpath(__DIR__.'/../Fixtures/');
        require_once self::$fixturesPath.'/includes/foo.php';
        require_once self::$fixturesPath.'/includes/ProjectExtension.php';
    }

    public function testLoadUnExistFile()
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessageMatches('/The file ".+" does not exist./');
        $loader = new YamlFileLoader(new ContainerBuilder()new FileLocator(self::$fixturesPath.'/ini'));
        $r = new \ReflectionObject($loader);
        $m = $r->getMethod('loadFile');

        $m->invoke($loader, 'foo.yml');
    }

    public function testLoadInvalidYamlFile()
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessageMatches('/The file ".+" does not contain valid YAML./');
        
public function testValidateConflictsSpecificMessage(): void
    {
        $path = __DIR__ . '/_fixture/SwagTestValidateConflictsSpecificMessage';
        $path = str_replace($this->projectDir, '', $path);

        $plugin = $this->createPlugin($path);

        $regexTemplate = '#.*"%s" conflicts with plugin/package "%s == 6\.[0-9]+\.[0-9]+\.[0-9]+.*#im';

        static::assertIsString($plugin->getComposerName());
        $this->expectExceptionMessageMatches(sprintf(
            $regexTemplate,
            preg_quote($plugin->getComposerName(), '#'),
            preg_quote('shopware/core', '#')
        ));
        $this->createValidator()->validateRequirements($plugin, Context::createDefaultContext(), 'test');
    }

    private function createValidator(): RequirementsValidator
    {
        $pluginRepo = $this->createMock(EntityRepository::class);
        $pluginRepo->method('search')->willReturn(new EntitySearchResult(
            
Home | Imprint | This part of the site doesn't use cookies.