データベースをクリーンアップしようとしないと、すべて正常に動作します。テストのBDD symfony 3のクリーニングデータベース - ドライバで例外が発生しました:SQLSTATE [HY000] [2002]接続が拒否されました
パートはこれです:
namespace tests\ApiBundle\features\group_management\bootstrap;
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use tests\ApiBundle\features\WebApi;
use PHPUnit_Framework_Assert as Assertions;
//use Behat\Testwork\Hook\Scope\BeforeSuiteScope;
//use Behat\Testwork\Hook\Scope\AfterSuiteScope;
//use Behat\Behat\Hook\Scope\AfterScenarioScope;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Doctrine\ORM\EntityManager;
use NG\Model\Group\Group;
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use Doctrine\Common\DataFixtures\Loader;
use tests\MyDataFixtures\LoadUserData;
/**
* Defines application features from the specific context.
*/
class CreatingNewGroupContext implements Context, SnippetAcceptingContext
{
/**
* @var WebApi
*/
private $webApi;
/**
* Initializes context.
*
* Every scenario gets its own context instance.
* You can also pass arbitrary arguments to the
* context constructor through behat.yml.
*
* @param WebApi $webApi web api
*/
public function __construct(WebApi $webApi, EntityManager $entityManager)
{
$this->webApi = $webApi;
$this->entityManager = $entityManager;
}
/** @BeforeScenario */
public function before(BeforeScenarioScope $scope)
{
echo 'before ';
$loader = new Loader();
$loader->addFixture(new LoadUserData());
$purger = new ORMPurger();
$executor = new ORMExecutor($this->entityManager, $purger);
$executor->execute($loader->getFixtures());
}
あなたが前に機能がある見ることができるように。その中で最後のステートメントは失敗します。教義で
は、私はconnnecting時に使用しようとしているものをパラメータログオンしている()関数を接続connection.php:file_put_contents('debug.txt', 'drive options: ' . json_encode($driverOptions) , FILE_APPEND);
と私は正しいオプションを参照してください。少なくとも私たちは間違っていることに気付かない。また、それらが間違っている場合、before()関数をコメントアウトすると、データベースにも接続するため、すべてのテストが失敗します。
ドッキング用の容器を使用しています。ユーザ名として任意の文字列をmysqlにログインさせようとしました。
mysql -u randomstr
-uパラメータとして書いたものに接続します。だから私は接続データが正しいかどうかを確認する方法を知らない。
ところで、私は関数の前でやっているものを理解していないです、同僚はちょうどので、私は実行しているいくつかのコードを取得しようとしていたレコードを削除するための
https://github.com/doctrine/data-fixtures
を使用すると述べました。
あなたがより良い方法を知っているなら、あなたも知ることができます。
エラーは、私がテストを実行すると以下の通りです:
--- Failed hooks:
BeforeScenario # tests\ApiBundle\features\group_management\bootstrap\CreatingNewGroupContext::before()
│ before
An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused (Doctrine\DBAL\Exception\ConnectionException)