You are here

protected function CheckoutOrderManagerTest::setUp in Commerce Core 8.2

Overrides OrderKernelTestBase::setUp

File

modules/checkout/tests/src/Kernel/CheckoutOrderManagerTest.php, line 45

Class

CheckoutOrderManagerTest
Tests the checkout order manager.

Namespace

Drupal\Tests\commerce_checkout\Kernel

Code

protected function setUp() : void {
  parent::setUp();
  $this
    ->installConfig('commerce_checkout');
  $user = $this
    ->createUser([
    'mail' => $this
      ->randomString() . '@example.com',
  ]);
  $order = Order::create([
    'type' => 'default',
    'mail' => $user
      ->getEmail(),
    'uid' => $user
      ->id(),
    'store_id' => $this->store
      ->id(),
  ]);
  $order
    ->save();
  $this->order = $order;
  $this->checkoutOrderManager = $this->container
    ->get('commerce_checkout.checkout_order_manager');

  // Fake a request so that the current_route_match works.
  // @todo Remove this when CheckoutFlowBase stops using the route match.
  $url = Url::fromRoute('commerce_checkout.form', [
    'commerce_order' => $order
      ->id(),
  ]);
  $route_provider = $this->container
    ->get('router.route_provider');
  $route = $route_provider
    ->getRouteByName($url
    ->getRouteName());
  $request = Request::create($url
    ->toString());
  $request->attributes
    ->add([
    RouteObjectInterface::ROUTE_OBJECT => $route,
    'commerce_order' => $order,
  ]);
  $this->container
    ->get('request_stack')
    ->push($request);
}