MageTest / BehatMage

Behat for Magento
MIT License
85 stars 31 forks source link

[Feature-Request] Use Mage:: in a Behat-Hook #91

Open zuernBernhard opened 7 years ago

zuernBernhard commented 7 years ago

I have a behat test for the Customer-Registration in a Magento-Shop (1.8).

In order to rerun the test as often as I want As a developer I want the Test to clear the generated user account in a scenario hook

Possible Solution:

/**
   * @param $event
   *
   * @BeforeScenario
   */
  public function before($event) {
    if ('Customer Register' == $event->getScenario()->getTitle()) {
      // Delete the TestCustomer if exists.
      $customer = Mage::getModel('customer/customer')->loadByEmail('email@dre.ss');
      $customer->delete();
    }
  }

BUT this does not work.

Then I move the code into a Stepdefinition it works. :(

zuernBernhard commented 7 years ago

Here is the working step definition:

  /**
   * @Given I make sure the customer :mail does not exist in the :shop Shop
   */
  public function iMakeSureTheCustomerDoesNotExistInTheShop($mail, $site)
  {
    $websites = Mage::app()->getWebsites();
    foreach ($websites as $website) {
      $name = $website->getName();
      if ($site == $name) {
        Mage::register('isSecureArea', true); /* set secure admin area*/
        $customerModel = Mage::getModel('customer/customer');
        $customerModel->setWebsiteId($website->getId());
        $customer = $customerModel->loadByEmail($mail);
        $customer->delete();
        Mage::unregister('isSecureArea'); /* un set secure admin area*/
      }
    }
  }