UserProvisioner example

new FakeQueryBuilder($connection[]),
            new FakeQueryBuilder($connection[[$localeId]])
        );

        $user = [
            'firstName' => 'first',
            'lastName' => 'last',
            'email' => 'test@test.com',
            'admin' => false,
        ];

        $provisioner = new UserProvisioner($connection);
        $provisioner->provision('admin', 'shopware', $user);
    }

    public function testProvisionThrowsIfUserAlreadyExists(): void
    {
        $connection = $this->createMock(Connection::class);
        $connection->expects(static::never())
            ->method('insert');

        $connection->expects(static::once())->method('createQueryBuilder')->willReturnOnConsecutiveCalls(
            new FakeQueryBuilder($connection[[Uuid::randomBytes()]]),
        );

#[Package('core')] class AdminConfigurationService
{
    /** * @param AdminUser $user */
    public function createAdmin(array $user, Connection $connection): void
    {
        $userProvisioner = new UserProvisioner($connection);
        $userProvisioner->provision(
            $user['username'],
            $user['password'],
            [
                'firstName' => $user['firstName'],
                'lastName' => $user['lastName'],
                'email' => $user['email'],
            ]
        );
    }
}
Home | Imprint | This part of the site doesn't use cookies.