Why can magento behat test not find my database?

2019-08-12 05:15发布

问题:

When I call bin/behat to execute my tests, I get this error:

test.dev bin/behat

  [Zend_Db_Adapter_Exception]                       
  SQLSTATE[HY000] [2002] No such file or directory  

  [PDOException]                                    
  SQLSTATE[HY000] [2002] No such file or directory

This is my composer.json:

{
  "require": {
    "php": ">=5.4.0"
  },
  "require-dev": {
    "magetest/magento-behat-extension": "dev-develop",
    "magetest/magento-phpspec-extension": "~2.0",
    "peridot-php/webdriver-manager": "dev-master",
    "bossa/phpspec2-expect": "dev-master",
    "behat/mink-extension": "*",
    "behat/mink-goutte-driver": "*",
    "behat/mink-selenium2-driver": "*",
    "behat/mink-selenium-driver": "*"
  },
  "autoload": {
    "psr-0": {
      "": [
        "html/app",
        "html/app/code/community",
        "html/app/code/core",
        "html/lib"
      ],
      "Mage" : "html/app/code/core"
    }
  },
  "config": {
    "bin-dir": "bin"
  }
}

And this is my behat.yml:

default:
  paths:
    features:  features
    bootstrap: features/bootstrap
  extensions:
    MageTest\MagentoExtension\Extension: ~
    Behat\MinkExtension\Extension:
      base_url: http://test.dev
      goutte: ~
      selenium2: ~
      default_session: selenium2

It's a patchwork of several tutorials while every of them threw the same error. My Magento installation is in html under project. Only thing that differs to all tutorials is, that I have no html/app/code/local folder. Composer install and behat --init run without errors.

Edit: I'm working with MAMP Pro, so I found this issue. But linking the socket file to /tmp did not fix my problem.

回答1:

Since I use MAMP, I have to configure it for CLI as well:

export PATH=/Applications/MAMP/bin/php/php5.6.10/bin:$PATH

Now CLI uses my MAMP PHP version and everything runs well.