Hi! I’ve installed <spryker-b2b-demo in docker &a...
# docker
n
Hi! I’ve installed spryker-b2b-demo in docker &amp; dev mode. I tried to get Tests running by using the bootcamp StringReverser example. Running the tests in docker with
docker/sdk testing codecept run -c tests/PyzTest/Zed/StringReverser
results in:
Copy code
PyzTest\Zed\StringReverser.Business Tests (1)  

E StringReverserFacadeTest: String is reversed correctly 
E StringReverserFacadeTest: String is reversed correctly (0.00s)

In ConnectionFactory.php line 43:
                             
  Unable to open connection  
                             

In PdoAdapter.php line 72:
                                 
  Unable to open PDO connection  
                                 

In PdoConnection.php line 59:
                                                                       
  SQLSTATE[08006] [7] could not connect to server: Connection refused  
        Is the server running on host "127.0.0.1" and accepting             
        TCP/IP connections on port 5432?
This is not the desired Exception, in the bootcamp the exception was
FacadeNotFoundException
. And I don’t think there should be a
PDOException
since there is no DB involved (or is it, the test runs in the Business Layer 🤔)? Running docker desktop 2.3.0.3 (stable) on macOS Catalina v 10.15.5 with recommended docker settings. Can you help me or point me in a direction to get the tests working in docker? 🤗
q
anyway, first guess: the codeception.yml from our example loads too many unnecessary modules
h
Please, try different way to run tests:
docker/sdk testing codecept run -g StringReverser
To speed up the run you can change codeception.yml or create your own and set include: to include only necessary test.
n
@quick-account-45953 codeception.yml
Copy code
namespace: PyzTest\Zed\StringReverser

paths:
    tests: .
    data: _data
    support: _support
    log: _output

coverage:
    enabled: true
    remote: false
    whitelist: { include: ['../../../../src/*'] }

suites:
    Business:
        path: Business
        class_name: StringReverserBusinessTester
        modules:
            enabled:
                - Asserts
                - \PyzTest\Shared\Testify\Helper\Environment
                - \SprykerTest\Shared\Testify\Helper\ConfigHelper
                - \SprykerTest\Shared\Testify\Helper\DependencyHelper
                - \SprykerTest\Shared\Propel\Helper\TransactionHelper
                - \SprykerTest\Shared\Testify\Helper\LocatorHelper:
                      projectNamespaces: ['Pyz']
1:1 from the bootcamp
@high-pencil-62400 the command does not run any test with my current configuration. But I’ll investigate - thx for the hint. I’ll come back at you with new results 😄
q
another first guess (looks like my first guesses are not very good today 😊)
@high-pencil-62400’s command calls a specific group
n
mondays.. 😄 ¯\_(ツ)_/¯
q
the group does not exists on the test
n
i thought so, currently checking codeceptions documentation on how to fix it
q
oh, it does
n
is it the
namespace
attribute, that defines the group?
q
no there is a @group annotation on top of the test class
(there are actually a lot of those)
n
ahh thx for pointing that out
Copy code
[PyzTest\Zed\StringReverser]: tests from /data/tests/PyzTest/Zed/StringReverser


PyzTest\Zed\StringReverser.Business Tests (0)
i am such an idiot…
i ran the `codeception`with the complete namespace not the group `StringReverser`🤦‍♂️
thx @high-pencil-62400 and @quick-account-45953
q
i will add the docker specific stuff to the bootcamp in the next iteration. thanks for pointing it out! 👍
main thing is that it works now 😉
n
yea it works - thanks again
i
What was the solution for this? I have the exact same problem (also using docker). All the"@group" tags within my test class are out-commented.
q
maybe @magnificent-market-21783?
w
For me removing the
\SprykerTest\Shared\Propel\Helper\TransactionHelper
from codeception.yml was enough (run
codecept build -c tests/PyzTest/Zed/StringReverser
afterwards) – neither test nor module use persistence so it shouldn't be required. Main issue seems to be that the
docker.dev
environment which the testing container uses sets up the database connection by including
common/config_services-devvm.php
where the DB host is set to localhost (which seems wrong to me at first glance).
h
It APPLICATION_ENV=devtest instead of docker specific one.
This file https://github.com/spryker-shop/b2b-demo-shop/blob/master/tests/PyzTest/Shared/Testify/_support/Helper/Environment.php should be like this:
Copy code
<?php

/**
 * This file is part of the Spryker Suite.
 * For full license information, please view the LICENSE file that was distributed with this source code.
 */

namespace PyzTest\Shared\Testify\Helper;

use Codeception\Module;
use Spryker\Shared\Kernel\CodeBucket\Config\CodeBucketConfig;
use Spryker\Shared\Kernel\CodeBucket\Config\CodeBucketConfigInterface;

class Environment extends Module
{
    protected const TESTING_APPLICATION_ENV_NAME = 'devtest';

    /**
     * @return void
     */
    public function _initialize()
    {
        $rootDir = realpath(__DIR__ . '/../../../../../../');
        $applicationEnv = $this->getApplicationEnv();

        defined('APPLICATION_ENV') || define('APPLICATION_ENV', $applicationEnv);
        defined('APPLICATION_STORE') || define('APPLICATION_STORE', (isset($_SERVER['APPLICATION_STORE'])) ? $_SERVER['APPLICATION_STORE'] : 'DE');
        putenv('APPLICATION_STORE=' . APPLICATION_STORE);

        defined('APPLICATION') || define('APPLICATION', '');

        defined('APPLICATION_ROOT_DIR') || define('APPLICATION_ROOT_DIR', $rootDir);
        defined('APPLICATION_SOURCE_DIR') || define('APPLICATION_SOURCE_DIR', APPLICATION_ROOT_DIR . '/src');
        defined('APPLICATION_VENDOR_DIR') || define('APPLICATION_VENDOR_DIR', APPLICATION_ROOT_DIR . '/vendor');

        defined('APPLICATION_CODE_BUCKET') || define('APPLICATION_CODE_BUCKET', $this->createCodeBucketConfig()->getCurrentCodeBucket());
        putenv('APPLICATION_CODE_BUCKET=' . APPLICATION_CODE_BUCKET);
    }

    /**
     * @return string
     */
    protected function getApplicationEnv(): string
    {
        if (getenv('SPRYKER_TESTING_ENABLED')) {
            return getenv('APPLICATION_ENV');
        }

        return static::TESTING_APPLICATION_ENV_NAME;
    }

    /**
     * @return \Spryker\Shared\Kernel\CodeBucket\Config\CodeBucketConfigInterface
     */
    protected function createCodeBucketConfig(): CodeBucketConfigInterface
    {
        return new CodeBucketConfig();
    }
}