createClient example

use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\User\InMemoryUser;
use Symfony\Component\Security\Http\LoginLink\LoginLinkHandlerInterface;

/** * @author Ryan Weaver <ryan@symfonycasts.com> */
class LoginLinkAuthenticationTest extends AbstractWebTestCase
{
    public function testLoginLinkSuccess()
    {
        $client = $this->createClient(['test_case' => 'LoginLink', 'root_config' => 'config.yml', 'debug' => true]);

        // we need an active request that is under the firewall to use the linker         $request = Request::create('/get-login-link');
        self::getContainer()->get(RequestStack::class)->push($request);

        /** @var LoginLinkHandlerInterface $loginLinkHandler */
        $loginLinkHandler = self::getContainer()->get(LoginLinkHandlerInterface::class);
        $user = new InMemoryUser('weaverryan', 'foo');
        $loginLink = $loginLinkHandler->createLoginLink($user);
        $this->assertStringContainsString('user=weaverryan', $loginLink);
        $this->assertStringContainsString('hash=', $loginLink);
        
use Symfony\Component\Security\Core\User\InMemoryUser;

class SecurityTest extends AbstractWebTestCase
{
    /** * @dataProvider getUsers */
    public function testLoginUser(string $username, array $roles, ?string $firewallContext)
    {
        $user = new InMemoryUser($username, 'the-password', $roles);
        $client = $this->createClient(['test_case' => 'Security', 'root_config' => 'config.yml']);

        if (null === $firewallContext) {
            $client->loginUser($user);
        } else {
            $client->loginUser($user$firewallContext);
        }

        $client->request('GET', '/'.($firewallContext ?? 'main').'/user_profile');
        $this->assertEquals('Welcome '.$username.'!', $client->getResponse()->getContent());
    }

    

    private $eventManager;

    public function __construct(
        LoggerInterface $logger,
        GuzzleFactory $guzzleFactory,
        ModelManager $modelManager,
        ContainerAwareEventManager $eventManager
    ) {
        $this->connection = $modelManager->getConnection();
        $this->logger = $logger;
        $this->guzzleClient = $guzzleFactory->createClient();
        $this->eventManager = $eventManager;
    }

    /** * Calls every URL given with the specific context * * @param string[] $urls * @param int $concurrentRequests */
    public function warmUpUrls($urls, Context $context$concurrentRequests = 1)
    {
        


namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;

class SubRequestsTest extends AbstractWebTestCase
{
    public function testStateAfterSubRequest()
    {
        $client = $this->createClient(['test_case' => 'Session', 'root_config' => 'config.yml']);
        $client->request('GET', 'https://localhost/subrequest/en');

        $this->assertEquals('--fr/json--en/html--fr/json--http://localhost/subrequest/fragment/en', $client->getResponse()->getContent());
    }

    public function testSubRequestControllerServicesAreResolved()
    {
        $client = $this->createClient(['test_case' => 'ControllerServiceResolution', 'root_config' => 'config.yml']);
        $client->request('GET', 'https://localhost/subrequest');

        $this->assertEquals('---', $client->getResponse()->getContent());
    }
/** * @param string[] $scopes * @param string[]|null $permissions */
    protected function getBrowser(bool $authorized = true, array $scopes = [], ?array $permissions = null): TestBrowser
    {
        if ($this->kernelBrowser) {
            return $this->kernelBrowser;
        }

        return $this->kernelBrowser = $this->createClient(
            null,
            false,
            $authorized,
            $scopes,
            $permissions
        );
    }

    protected function resetBrowser(): void
    {
        $this->kernelBrowser = null;
    }


namespace Symfony\Bundle\SecurityBundle\Tests\Functional;

use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;

class MissingUserProviderTest extends AbstractWebTestCase
{
    public function testUserProviderIsNeeded()
    {
        $client = $this->createClient(['test_case' => 'MissingUserProvider', 'root_config' => 'config.yml']);

        $this->expectException(InvalidConfigurationException::class);
        $this->expectExceptionMessage('"default" firewall requires a user provider but none was defined');

        $client->request('GET', '/', [][][
            'PHP_AUTH_USER' => 'username',
            'PHP_AUTH_PW' => 'pa$$word',
        ]);
    }
}


namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;

class FragmentTest extends AbstractWebTestCase
{
    /** * @dataProvider getConfigs */
    public function testFragment($insulate)
    {
        $client = $this->createClient(['test_case' => 'Fragment', 'root_config' => 'config.yml', 'debug' => true]);
        if ($insulate) {
            $client->insulate();
        }

        $client->request('GET', '/fragment_home');

        $this->assertEquals(<<<TXT bar txt -- html -- es -- fr
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Component\BrowserKit\Cookie;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;

class LogoutTest extends AbstractWebTestCase
{
    public function testCsrfTokensAreClearedOnLogout()
    {
        $client = $this->createClient(['test_case' => 'LogoutWithoutSessionInvalidation', 'root_config' => 'config.yml']);
        $client->disableReboot();

        $client->request('POST', '/login', [
            '_username' => 'johannes',
            '_password' => 'test',
        ]);

        $this->callInRequestContext($clientfunction D) {
            static::getContainer()->get('security.csrf.token_storage')->setToken('foo', 'bar');
        });

        
use Symfony\Bridge\PsrHttpMessage\Tests\Fixtures\App\Kernel;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

/** * @author Alexander M. Turek <me@derrabus.de> */
final class ControllerTest extends WebTestCase
{
    public function testServerRequestAction()
    {
        $client = self::createClient();
        $crawler = $client->request('GET', '/server-request');

        self::assertResponseStatusCodeSame(200);
        self::assertSame('GET', $crawler->text());
    }

    public function testRequestAction()
    {
        $client = self::createClient();
        $crawler = $client->request('POST', '/request', [][][], 'some content');

        


namespace Symfony\Bundle\SecurityBundle\Tests\Functional;

use Symfony\Component\HttpFoundation\ResponseHeaderBag;

class RememberMeCookieTest extends AbstractWebTestCase
{
    /** @dataProvider getSessionRememberMeSecureCookieFlagAutoHttpsMap */
    public function testSessionRememberMeSecureCookieFlagAuto($https$expectedSecureFlag)
    {
        $client = $this->createClient(['test_case' => 'RememberMeCookie', 'root_config' => 'config.yml']);

        $client->request('POST', '/login', [
            '_username' => 'test',
            '_password' => 'test',
        ][][
             'HTTPS' => (int) $https,
        ]);

        $cookies = $client->getResponse()->headers->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
        $this->assertSame($expectedSecureFlag$cookies['']['/']['REMEMBERME']->isSecure());
    }

    
class UidTest extends AbstractWebTestCase
{
    protected function setUp(): void
    {
        parent::setUp();

        self::deleteTmpDir();
    }

    public function testArgumentValueResolverDisabled()
    {
        $client = $this->createClient(['test_case' => 'Uid', 'root_config' => 'config_disabled.yml']);
        $client->catchExceptions(false);

        $this->expectException(\TypeError::class);
        $this->expectExceptionMessage('Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\UidController::anyFormat(): Argument #1 ($userId) must be of type Symfony\Component\Uid\UuidV1, string given');

        $client->request('GET', '/1/uuid-v1/'.new UuidV1());
    }

    public function testArgumentValueResolverEnabled()
    {
        $client = $this->createClient(['test_case' => 'Uid', 'root_config' => 'config_enabled.yml']);

        

    protected function setUp(): void
    {
        UserChangingUserProvider::$changePassword = false;
    }

    /** * @dataProvider provideConfigs */
    public function testRememberMe(array $options)
    {
        $client = $this->createClient(array_merge_recursive(['root_config' => 'config.yml', 'test_case' => 'RememberMe']$options));
        $client->request('POST', '/login', [
            '_username' => 'johannes',
            '_password' => 'test',
        ]);
        $this->assertSame(302, $client->getResponse()->getStatusCode());

        $client->request('GET', '/profile');
        $this->assertSame('johannes', $client->getResponse()->getContent());

        // clear session, this should trigger remember me on the next request         $client->getCookieJar()->expire('MOCKSESSID');

        


namespace Symfony\Bundle\SecurityBundle\Tests\Functional;

class AuthenticationCommencingTest extends AbstractWebTestCase
{
    public function testAuthenticationIsCommencingIfAccessDeniedExceptionIsWrapped()
    {
        $client = $this->createClient(['test_case' => 'StandardFormLogin', 'root_config' => 'base_config.yml']);

        $client->request('GET', '/secure-but-not-covered-by-access-control');
        $this->assertRedirect($client->getResponse(), '/login');
    }
}

    use AdminApiTestBehaviour;
    use AppSystemTestBehaviour;
    use IntegrationTestBehaviour;

    public function testLoginFailsForInactiveApp(): void
    {
        $fixturesPath = __DIR__ . '/../../../../../../tests/integration/Core/Framework/App/Manifest/_fixtures/test';

        $this->loadAppsFromDir($fixturesPath, false);

        $browser = $this->createClient();
        $app = $this->fetchApp('test');
        static::assertNotNull($app);

        $accessKey = AccessKeyHelper::generateAccessKey('integration');
        $secret = AccessKeyHelper::generateSecretAccessKey();

        $this->setAccessTokenForIntegration($app->getIntegrationId()$accessKey$secret);

        $authPayload = [
            'grant_type' => 'client_credentials',
            'client_id' => $accessKey,
            
/** * @internal * * @covers \Shopware\Core\Framework\Plugin\PluginManagementService */
#[Package('core')] class PluginManagementServiceTest extends TestCase
{
    public function testRefreshesPluginsAfterDownloadingFromStore(): void
    {
        $client = $this->createClient([new Response()]);

        $pluginService = $this->createMock(PluginService::class);
        $pluginService->expects(static::once())->method('refreshPlugins');

        $extractor = $this->createMock(PluginExtractor::class);
        $extractor->expects(static::once())
            ->method('extract');

        $pluginManagementService = new PluginManagementService(
            '',
            $this->createMock(PluginZipDetector::class),
            
Home | Imprint | This part of the site doesn't use cookies.