expectExceptionMessage example

if ('\\' === \DIRECTORY_SEPARATOR) {
            $paths[] = ['c:\var\lib/symfony/src/Symfony/', 'c:/var/lib/symfony/', 'src/Symfony/'];
        }

        return $paths;
    }

    public function testMakePathRelativeWithRelativeStartPath()
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('The start path "var/lib/symfony/src/Symfony/Component" is not absolute.');
        $this->assertSame('../../../', $this->filesystem->makePathRelative('/var/lib/symfony/', 'var/lib/symfony/src/Symfony/Component'));
    }

    public function testMakePathRelativeWithRelativeEndPath()
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('The end path "var/lib/symfony/" is not absolute.');
        $this->assertSame('../../../', $this->filesystem->makePathRelative('var/lib/symfony/', '/var/lib/symfony/src/Symfony/Component'));
    }

    public function testMirrorCopiesFilesAndDirectoriesRecursively()
    {
$this->assertFileUnchanged($source, File::load($source->id()));
    $this->assertFileUnchanged($target, File::load($target->id()));
  }

  /** * Tests for an invalid stream wrapper. * * @covers ::copy */
  public function testInvalidStreamWrapper() {
    $this->expectException(InvalidStreamWrapperException::class);
    $this->expectExceptionMessage('Invalid stream wrapper: foo://');
    $source = $this->createFile();
    $this->fileRepository->copy($source, 'foo://');
  }

  /** * Tests for entity storage exception. * * @covers ::copy */
  public function testEntityStorageException() {
    /** @var \Drupal\Core\Entity\EntityTypeManager $entityTypeManager */
    
'!php/const PHP_INT_MAX', \PHP_INT_MAX],
            ['[!php/const PHP_INT_MAX]', [\PHP_INT_MAX]],
            ['{ foo: !php/const PHP_INT_MAX }', ['foo' => \PHP_INT_MAX]],
            ['{ !php/const PHP_INT_MAX: foo }', [\PHP_INT_MAX => 'foo']],
            ['!php/const NULL', null],
        ];
    }

    public function testParsePhpConstantThrowsExceptionWhenUndefined()
    {
        $this->expectException(ParseException::class);
        $this->expectExceptionMessage('The constant "WRONG_CONSTANT" is not defined');
        Inline::parse('!php/const WRONG_CONSTANT', Yaml::PARSE_CONSTANT);
    }

    public function testParsePhpEnumThrowsExceptionWhenUndefined()
    {
        $this->expectException(ParseException::class);
        $this->expectExceptionMessage('The enum "SomeEnum::Foo" is not defined');
        Inline::parse('!php/enum SomeEnum::Foo', Yaml::PARSE_CONSTANT);
    }

    public function testParsePhpEnumThrowsExceptionWhenNotAnEnum()
    {
10.123, '10.123', 0.01, '0.01', 'float'],
            ['22', '"22"', '10', '"10"', 'string'],
        ];
    }

    /** * @dataProvider throwsOnNonNumericValuesProvider */
    public function testThrowsOnNonNumericValues(string $expectedGivenType$value$comparedValue)
    {
        $this->expectException(UnexpectedValueException::class);
        $this->expectExceptionMessage(sprintf('Expected argument of type "numeric", "%s" given', $expectedGivenType));

        $this->validator->validate($value$this->createConstraint([
            'value' => $comparedValue,
        ]));
    }

    public static function throwsOnNonNumericValuesProvider()
    {
        return [
            [\stdClass::class, 2, new \stdClass()],
            [\ArrayIterator::classnew \ArrayIterator(), 12],
        ];
$request = new Request([][][][][]['HTTP_AUTHORIZATION' => 'Bearer VALID_ACCESS_TOKEN']);
        $passport = $this->authenticator->authenticate($request);
        $this->assertInstanceOf(SelfValidatingPassport::class$passport);
    }

    /** * @dataProvider provideInvalidAuthenticateData */
    public function testAuthenticateInvalid($request$errorMessage$exceptionType = BadRequestHttpException::class)
    {
        $this->expectException($exceptionType);
        $this->expectExceptionMessage($errorMessage);

        $this->setUpAuthenticator();

        $this->authenticator->authenticate($request);
    }

    public static function provideInvalidAuthenticateData(): iterable
    {
        $request = new Request();
        yield [$request, 'Invalid credentials.', BadCredentialsException::class];

        
public function testConstructorWithParameters()
    {
        $constraint = new PasswordStrength(minScore: PasswordStrength::STRENGTH_STRONG, message: 'This password should be strong.');

        $this->assertSame(PasswordStrength::STRENGTH_STRONG, $constraint->minScore);
        $this->assertSame('This password should be strong.', $constraint->message);
    }

    public function testInvalidScoreOfZero()
    {
        $this->expectException(ConstraintDefinitionException::class);
        $this->expectExceptionMessage('The parameter "minScore" of the "Symfony\Component\Validator\Constraints\PasswordStrength" constraint must be an integer between 1 and 4.');
        new PasswordStrength(minScore: PasswordStrength::STRENGTH_VERY_WEAK);
    }

    public function testInvalidScoreOfFive()
    {
        $this->expectException(ConstraintDefinitionException::class);
        $this->expectExceptionMessage('The parameter "minScore" of the "Symfony\Component\Validator\Constraints\PasswordStrength" constraint must be an integer between 1 and 4.');
        new PasswordStrength(minScore: 5);
    }
}
$config_factory = $this->createMock('Drupal\Core\Config\ConfigFactoryInterface');
    $key_value_factory = $this->createMock('Drupal\Core\KeyValueStore\KeyValueFactoryInterface');
    $config_manager = $this->createMock('Drupal\Core\Config\ConfigManagerInterface');
    $config_entity_type = $this->createMock('Drupal\Core\Config\Entity\ConfigEntityTypeInterface');
    $config_entity_type->expects($this->atLeastOnce())
      ->method('id')
      ->willReturn('test_config_entity_type');
    $query_factory = new QueryFactory($config_factory$key_value_factory$config_manager);

    $method = new \ReflectionMethod($query_factory, 'getKeys');
    $this->expectException(\LogicException::class);
    $this->expectExceptionMessage('test_config_entity_type lookup key test.* ends with a wildcard this can not be used as a lookup');
    $method->invoke($query_factory$this->getConfigObject('test'), 'test.*', 'get', $config_entity_type);
  }

  /** * Gets a test configuration object. * * @param string $name * The config name. * * @return \Drupal\Core\Config\Config|\PHPUnit\Framework\MockObject\MockObject * The test configuration object. */
$systemConfigService = $this->getContainer()->get(SystemConfigService::class);
        static::assertEquals([
            'withConfig.config.email' => 'no-reply@shopware.de',
        ]$systemConfigService->getDomain('withConfig.config'));
    }

    public function testInstallThrowsIfConfigContainsComponentElement(): void
    {
        $manifest = Manifest::createFromXmlFile(__DIR__ . '/_fixtures/withInvalidConfig/manifest.xml');

        static::expectException(AppException::class);
        static::expectExceptionMessage('Configuration of app "withInvalidConfig" is invalid');
        $this->appLifecycle->install($manifest, true, $this->context);
    }

    public function testInstallAndUpdateSavesRuleConditions(): void
    {
        $manifest = Manifest::createFromXmlFile(__DIR__ . '/_fixtures/withRuleConditions/manifest.xml');
        $this->appLifecycle->install($manifest, true, $this->context);

        $criteria = new Criteria();
        $criteria->addAssociation('scriptConditions');
        /** @var AppCollection $apps */
        
PrivateConstructorController::class, 'staticAction'], 'bar'],
        ];
    }

    /** * @dataProvider getUndefinedControllers */
    public function testGetControllerWithUndefinedController($controller$exceptionName = null, $exceptionMessage = null)
    {
        $resolver = $this->createControllerResolver();
        $this->expectException($exceptionName);
        $this->expectExceptionMessage($exceptionMessage);

        $request = Request::create('/');
        $request->attributes->set('_controller', $controller);
        $resolver->getController($request);
    }

    public static function getUndefinedControllers()
    {
        $controller = new ControllerTest();

        return [
            [
$this->assertInstanceOf(Workflow::class$workflow);
        $this->assertSame('workflow1', $workflow->getName());

        $workflow = $this->registry->get(new Subject2(), 'workflow2');
        $this->assertInstanceOf(Workflow::class$workflow);
        $this->assertSame('workflow2', $workflow->getName());
    }

    public function testGetWithMultipleMatch()
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('Too many workflows (workflow2, workflow3) match this subject (Symfony\Component\Workflow\Tests\Subject2); set a different name on each and use the second (name) argument of this method.');
        $w1 = $this->registry->get(new Subject2());
        $this->assertInstanceOf(Workflow::class$w1);
        $this->assertSame('workflow1', $w1->getName());
    }

    public function testGetWithNoMatch()
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('Unable to find a workflow for class "stdClass".');
        $w1 = $this->registry->get(new \stdClass());
        $this->assertInstanceOf(Workflow::class$w1);
        
'D8 custom fake' => [FALSE, 'Drupal\Driver\Database\corefake', TRUE],
      'module mysql' => ['core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestMysql/', 'Drupal\driver_test\Driver\Database\DrivertestMysql', TRUE],
    ];
  }

  /** * @covers ::findDriverAutoloadDirectory * @dataProvider providerFindDriverAutoloadDirectoryException */
  public function testFindDriverAutoloadDirectoryException($expected_message$namespace$include_tests) {
    $this->expectException(\RuntimeException::class);
    $this->expectExceptionMessage($expected_message);
    Database::findDriverAutoloadDirectory($namespace$this->root, $include_tests);
  }

  /** * Data provider for ::testFindDriverAutoloadDirectoryException(). * * @return array */
  public function providerFindDriverAutoloadDirectoryException() {
    return [
      'test module but tests not included' => ["Cannot find the module 'driver_test' for the database driver namespace 'Drupal\driver_test\Driver\Database\DrivertestMysql'", 'Drupal\driver_test\Driver\Database\DrivertestMysql', FALSE],
      
$systemConfigService = $this->createMock(SystemConfigService::class);
        $systemConfigService->expects(static::never())
            ->method('set');

        $frwService = $this->createFirstRunWizardService(
            systemConfigService: $systemConfigService,
            filesystemOperator: $filesystem,
            frwClient: $frwClient,
        );

        $this->expectException(LicenseDomainVerificationException::class);
        $this->expectExceptionMessage(sprintf('License host verification failed for domain "%s."', $domain));

        $frwService->verifyLicenseDomain($domain$this->context);
    }

    public function testIdentifiesAndConvertsCurrentLicenseDomains(): void
    {
        $licenseDomains = [
            [
                'id' => 1,
                'domain' => 'xn--tst-qla.de',
                'verified' => true,
                
use Symfony\Component\Webhook\Test\AbstractRequestParserTestCase;

class VonageRequestParserTest extends AbstractRequestParserTestCase
{
    public function testMissingAuthorizationTokenThrows()
    {
        $request = $this->createRequest('{}');
        $request->headers->remove('Authorization');
        $parser = $this->createRequestParser();

        $this->expectException(RejectWebhookException::class);
        $this->expectExceptionMessage('Missing "Authorization" header');

        $parser->parse($request$this->getSecret());
    }

    public function testInvalidAuthorizationTokenThrows()
    {
        $request = $this->createRequest('{}');
        $request->headers->set('Authorization', 'Invalid Header');
        $parser = $this->createRequestParser();

        $this->expectException(RejectWebhookException::class);
        
$this->assertEquals(['a', 'c']$role->getPermissions());

    $role->grantPermission('b')->save();
    $this->assertEquals(['a', 'b', 'c']$role->getPermissions());
  }

  public function testGrantingNonExistentPermission() {
    $role = Role::create(['id' => 'test_role', 'label' => 'Test role']);

    // A single permission that does not exist.     $this->expectException(\RuntimeException::class);
    $this->expectExceptionMessage('Adding non-existent permissions to a role is not allowed. The incorrect permissions are "does not exist".');
    $role->grantPermission('does not exist')
      ->save();

    // A multiple permissions that do not exist.     $this->expectException(\RuntimeException::class);
    $this->expectExceptionMessage('Adding non-existent permissions to a role is not allowed. The incorrect permissions are "does not exist, also does not exist".');
    $role->grantPermission('does not exist')
      ->grantPermission('also does not exist')
      ->save();
  }

  
public function testAddConstraintRequiresClassConstraints()
    {
        $this->expectException(ConstraintDefinitionException::class);

        $this->metadata->addConstraint(new PropertyConstraint());
    }

    public function testAddCompositeConstraintRejectsNestedPropertyConstraints()
    {
        $this->expectException(ConstraintDefinitionException::class);
        $this->expectExceptionMessage('The constraint "Symfony\Component\Validator\Tests\Fixtures\PropertyConstraint" cannot be put on classes.');

        $this->metadata->addConstraint(new ClassCompositeConstraint([new PropertyConstraint()]));
    }

    public function testAddCompositeConstraintAcceptsNestedClassConstraints()
    {
        $this->metadata->addConstraint($constraint = new ClassCompositeConstraint([new ClassConstraint()]));
        $this->assertSame($this->metadata->getConstraints()[$constraint]);
    }

    public function testAddPropertyConstraints()
    {
Home | Imprint | This part of the site doesn't use cookies.