PHP code example of edmondscommerce / behat-db-context

1. Go to this page and download the library: Download edmondscommerce/behat-db-context library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

edmondscommerce / behat-db-context example snippets


    // ...

    const MAGENTO_ONE_PATH_TO_LOCAL_XML = '/public/app/etc/local.xml';

    private static function detectMagentoOnePlatform($projectRoot)
    {
        return is_file($projectRoot . self::MAGENTO_ONE_PATH_TO_LOCAL_XML);
    }
    
    // ...

    // ...
    
    public static function detect()
    {
        // ...

        while (true) {
            if (self::detectMagentoOnePlatform($searchPath)) {
                return [self::MAGENTO_ONE, $searchPath];
            }

            // ...

            $searchPath = realpath($searchPath . '/../');

            if ($searchPath === false) {
                break;
            }
        }

        throw new \RuntimeException('Failed finding project root.');
    }
    
    // ...

// ...

    const MAGENTO_ONE = 'magento';
    
// ...

    // ...
    
    private static function assertMagentoOneUsingTestingDatabase($projectRoot, $databaseName)
    {
        $localXml = simplexml_load_string(
            file_get_contents($projectRoot . Platform::MAGENTO_ONE_PATH_TO_LOCAL_XML)
        );

        if (! isset($localXml->global->resources->default_setup->connection->dbname)) {
            throw new \RuntimeException(
                'You need to configure a dbname in your local.xml'
            );
        }

        if ((string) $localXml->global->resources->default_setup->connection->dbname === $databaseName) {
            return;
        }

        throw new \InvalidArgumentException(
            "You need to configure Magento to use the testing database '$databaseName' in local.xml"
        );
    }
    
    // ...

    // ...
    
    public static function assertTestingDatabaseIsBeingUsed($databaseName)
    {
        list($platform, $projectRoot) = self::detect();

        switch ($platform) {
            case self::MAGENTO_ONE:
                self::assertMagentoOneUsingTestingDatabase($projectRoot, $databaseName);
                break;
            // Add your platform specific assertion here...
        }
    }
    
    // ...