expectException example


        return new AnnotationLoader();
    }

    protected function getNamespace(): string
    {
        return 'Symfony\Component\Serializer\Tests\Fixtures\Attributes';
    }

    public function testLoadWithInvalidAttribute()
    {
        $this->expectException(MappingException::class);
        $this->expectExceptionMessage('Could not instantiate attribute "Symfony\Component\Serializer\Annotation\Groups" on "Symfony\Component\Serializer\Tests\Fixtures\Attributes\BadAttributeDummy::myMethod()".');

        $classMetadata = new ClassMetadata($this->getNamespace().'\BadAttributeDummy');

        $this->loader->loadClassMetadata($classMetadata);
    }
}
$task = $tasks->first();
        static::assertInstanceOf(ScheduledTaskEntity::class$task);
        static::assertEquals(TestTask::class$task->getScheduledTaskClass());
        static::assertEquals(5, $task->getRunInterval());
        static::assertEquals(1, $task->getDefaultRunInterval());
        static::assertEquals('test', $task->getName());
        static::assertEquals(ScheduledTaskDefinition::STATUS_FAILED, $task->getStatus());
    }

    public function testWithWrongClass(): void
    {
        $this->expectException(\RuntimeException::class);
        $this->expectExceptionMessage(sprintf(
            'Tried to register "%s" as scheduled task, but class does not extend ScheduledTask',
            FooMessage::class
        D);
        $registry = new TaskRegistry(
            /** @phpstan-ignore-next-line we want to test the exception that phpstan also reports */
            [
                new FooMessage(),
            ],
            $this->scheduledTaskRepo,
            new ParameterBag()
        );


    public function testBccIsRemoved()
    {
        $email = (new DraftEmail())->text('some text')->bcc('sam@example.com')->toString();

        $this->assertStringNotContainsString('sam@example.com', $email);
    }

    public function testMustHaveBody()
    {
        $this->expectException(LogicException::class);

        (new DraftEmail())->toString();
    }

    public function testEnsureValidityAlwaysFails()
    {
        $email = (new DraftEmail())
            ->to('alice@example.com')
            ->from('webmaster@example.com')
            ->text('some text')
        ;

        
use Symfony\Component\Notifier\Message\EmailMessage;
use Symfony\Component\Notifier\Notification\Notification;
use Symfony\Component\Notifier\Recipient\Recipient;

/** * @author Jan Schädlich <jan.schaedlich@sensiolabs.de> */
class EmailMessageTest extends TestCase
{
    public function testEnsureNonEmptyEmailOnCreationFromNotification()
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessage('"Symfony\Component\Notifier\Message\EmailMessage" needs an email, it cannot be empty.');

        EmailMessage::fromNotification(new Notification()new Recipient('', '+3312345678'));
    }
}

        ]));
        $transport = new PostmarkApiTransport('KEY', $client);
        $transport->setPort(8984);

        $mail = new Email();
        $mail->subject('Hello!')
            ->to(new Address('saif.gmati@symfony.com', 'Saif Eddin'))
            ->from(new Address('fabpot@symfony.com', 'Fabien'))
            ->text('Hello There!');

        $this->expectException(HttpTransportException::class);
        $this->expectExceptionMessage('Unable to send an email: i\'m a teapot (code 418).');
        $transport->send($mail);
    }

    public function testTagAndMetadataAndMessageStreamHeaders()
    {
        $email = new Email();
        $email->getHeaders()->add(new TagHeader('password-reset'));
        $email->getHeaders()->add(new MetadataHeader('Color', 'blue'));
        $email->getHeaders()->add(new MetadataHeader('Client-ID', '12345'));
        $email->getHeaders()->add(new MessageStreamHeader('broadcasts'));
        
$loader = new MailerTransportLoader(
            $this->getTransportFactory(),
            new StaticSystemConfigService([
                'core.mailerSettings.emailAgent' => 'local',
                'core.mailerSettings.sendMailOptions' => '-t && echo bla',
            ]),
            $this->createMock(MailAttachmentsBuilder::class),
            $this->createMock(FilesystemOperator::class),
            $this->createMock(EntityRepository::class)
        );

        static::expectException(\RuntimeException::class);
        static::expectExceptionMessage('Given sendmail option "-t && echo bla" is invalid');

        $loader->fromString('null://null');
    }

    public function testFactoryInvalidAgent(): void
    {
        $loader = new MailerTransportLoader(
            $this->getTransportFactory(),
            new StaticSystemConfigService([
                'core.mailerSettings.emailAgent' => 'test',
            ]),
namespace Symfony\Component\Security\Core\Tests\User;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Core\User\InMemoryUser;
use Symfony\Component\Security\Core\User\UserInterface;

class InMemoryUserTest extends TestCase
{
    public function testConstructorException()
    {
        $this->expectException(\InvalidArgumentException::class);
        new InMemoryUser('', 'superpass');
    }

    public function testGetRoles()
    {
        $user = new InMemoryUser('fabien', 'superpass');
        $this->assertEquals([]$user->getRoles());

        $user = new InMemoryUser('fabien', 'superpass', ['ROLE_ADMIN']);
        $this->assertEquals(['ROLE_ADMIN']$user->getRoles());
    }

    
->getMockForAbstractClass();
    // Return our definitions from getDefinitions().     $mock_decorated->expects($this->once())
      ->method('getDefinitions')
      ->willReturn($definitions);

    // Set up ::$decorated to our mocked decorated object.     $ref_decorated = new \ReflectionProperty($mock_decorator, 'decorated');
    $ref_decorated->setValue($mock_decorator$mock_decorated);

    if ($exception_on_invalid) {
      $this->expectException('Drupal\Component\Plugin\Exception\PluginNotFoundException');
    }

    // Exercise getDefinition(). It calls parent::getDefinition().     $this->assertEquals(
      $expected,
      $mock_decorator->getDefinition($base_plugin_id$exception_on_invalid)
    );
  }

  /** * Data provider for testGetDefinitions(). * * @return array * - bool Whether the test mock has a callback. * - array Plugin definitions. */

        'expected_result' => '2_the_baz_yee_haw_aeo.jpg',
      ],
    ];
  }

  /** * Tests that the replacement regular expression is a string. */
  public function testInvalidConfiguration(): void {
    $configuration['replace_pattern'] = 1;
    $this->expectException(MigrateException::class);
    $this->expectExceptionMessage('The replace pattern should be a string');
    new MachineName($configuration, 'machine_name', []$this->transliteration);
  }

}
TABLE;

        $this->assertEquals($expected$this->getOutputContent($output));
    }

    public function testThrowsWhenTheCellInAnArray()
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('A cell must be a TableCell, a scalar or an object implementing "__toString()", "array" given.');
        $table = new Table($output = $this->getOutputStream());
        $table
            ->setHeaders(['ISBN', 'Title', 'Author', 'Price'])
            ->setRows([
                ['99921-58-10-7', [], 'Dante Alighieri', '9.95'],
            ]);

        $table->render();
    }

    
    // is case-insensitive.     $this->assertSame(['system.performance']$this->storage->listAll('system'), 'The FileStorage::listAll() with prefix works.');
    $this->assertSame([]$this->storage->listAll('System'), 'The FileStorage::listAll() is case sensitive.');
  }

  /** * Tests UnsupportedDataTypeConfigException. */
  public function testUnsupportedDataTypeConfigException() {
    $name = 'core.extension';
    $path = $this->storage->getFilePath($name);
    $this->expectException(UnsupportedDataTypeConfigException::class);
    $this->expectExceptionMessageMatches("@Invalid data type in config $name, found in file $path: @");
    file_put_contents($path, PHP_EOL . 'foo : @bar', FILE_APPEND);
    $this->storage->read($name);
  }

}
->willReturn($resolvedLoader);

        $loader = new ProjectLoader1();
        $loader->setResolver($resolver);

        $this->assertSame($loader$loader->resolve('foo.foo'), '->resolve() finds a loader');
        $this->assertSame($resolvedLoader$loader->resolve('foo.xml'), '->resolve() finds a loader');
    }

    public function testResolveWhenResolverCannotFindLoader()
    {
        $this->expectException(LoaderLoadException::class);
        $resolver = $this->createMock(LoaderResolverInterface::class);
        $resolver->expects($this->once())
            ->method('resolve')
            ->with('FOOBAR')
            ->willReturn(false);

        $loader = new ProjectLoader1();
        $loader->setResolver($resolver);

        $loader->resolve('FOOBAR');
    }

    

        });
        $transport = new MailgunHttpTransport('ACCESS_KEY', 'symfony', 'us', $client);
        $transport->setPort(8984);

        $mail = new Email();
        $mail->subject('Hello!')
            ->to(new Address('saif.gmati@symfony.com', 'Saif Eddin'))
            ->from(new Address('fabpot@symfony.com', 'Fabien'))
            ->text('Hello There!');

        $this->expectException(HttpTransportException::class);
        $this->expectExceptionMessage('Unable to send an email: i\'m a teapot (code 418).');
        $transport->send($mail);
    }

    public function testTagAndMetadataHeaders()
    {
        $email = new Email();
        $email->getHeaders()->addTextHeader('foo', 'bar');
        $email->getHeaders()->add(new TagHeader('password-reset'));
        $email->getHeaders()->add(new TagHeader('product-name'));
        $email->getHeaders()->add(new MetadataHeader('Color', 'blue'));
        

  public function testRouteRebuild() {
    // Remove the routing table manually to ensure it can be created lazily     // properly.     Database::getConnection()->schema()->dropTable('router');

    $this->container->get('module_installer')->install(['router_test']);
    $route = $this->container->get('router.route_provider')->getRouteByName('router_test.1');
    $this->assertEquals('/router_test/test1', $route->getPath());

    $this->container->get('module_installer')->uninstall(['router_test']);
    $this->expectException(RouteNotFoundException::class);
    $this->container->get('router.route_provider')->getRouteByName('router_test.1');
  }

  /** * Tests config changes by hook_install() are saved for dependent modules. * * @covers ::install */
  public function testConfigChangeOnInstall() {
    // Install the child module so the parent is installed automatically.     $this->container->get('module_installer')->install(['module_handler_test_multiple_child']);
    
$key = new Key('key', 1);
        $store = $this->createMock(PersistingStoreInterface::class);
        $semaphore = new Semaphore($key$store);

        $store
            ->expects($this->once())
            ->method('save')
            ->with($key, 300.0)
            ->willThrowException(new \RuntimeException())
        ;

        $this->expectException(\RuntimeException::class);
        $this->expectExceptionMessage('Failed to acquire the "key" semaphore.');

        $semaphore->acquire();
    }

    public function testRefresh()
    {
        $key = new Key('key', 1);
        $store = $this->createMock(PersistingStoreInterface::class);
        $semaphore = new Semaphore($key$store, 10.0);

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