Every test creates a store and needs a store. We need a trait for making stores and setting the default store. Something like

  /**
   * Creates and sets the default store.
   *
   * @return \Drupal\commerce_store\Entity\StoreInterface
   *    The store.
   */
  protected function createDefaultStore() {
    $currency_importer = \Drupal::service('commerce_price.currency_importer');
    /** @var \Drupal\commerce_store\StoreStorage $store_storage */
    $store_storage = \Drupal::service('entity_type.manager')->getStorage('commerce_store');
    $currency_importer->import('USD');
    $store_values = [
      'type' => 'default',
      'uid' => 1,
      'name' => 'Demo store',
      'mail' => 'admin@example.com',
      'address' => [
        'country_code' => 'US',
      ],
      'default_currency' => 'USD',
      'billing_countries' => [
        'US',
      ],
    ];
    $store = $store_storage->create($store_values);
    $store->save();
    $store_storage->markAsDefault($store);
    return $store;
  }
CommentFileSizeAuthor
#2 storecreationtesttrait-2733489-2.patch8.15 KBmglaman

Comments

mglaman created an issue. See original summary.

mglaman’s picture

Status: Active » Needs review
StatusFileSize
new8.15 KB

  • mglaman committed 2ae37f1 on 8.x-2.x
    Issue #2733489: StoreCreationTestTrait
    
  • bojanz committed 66314c8 on 8.x-2.x
    Merge pull request #390 from mglaman/commerce-store-test-trait
    
    Issue #...
bojanz’s picture

Status: Needs review » Fixed

Boom.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.