From ea47a46a103c654975722aa12ec74b997fc1b056 Mon Sep 17 00:00:00 2001 From: Kamil Kokot Date: Thu, 19 Nov 2015 14:51:25 +0100 Subject: [PATCH] [Behat] [Travis] Introduced test_cached environment, updated test suites, added metadata cache for Doctrine PHPCR, omit doubled composer dependencies installing --- .travis.yml | 27 ++++++++------ app/config/config_test.yml | 7 ---- app/config/config_test_cached.yml | 21 +++++++++++ app/config/router_test_cached.php | 38 ++++++++++++++++++++ behat.yml.dist | 38 ++++++++++++++++++-- travis/prepare/prepare-cached-composer | 3 +- travis/prepare/prepare-javascript | 2 +- travis/suites/suite-javascript | 22 ++++++------ travis/suites/suite-no-javascript | 50 +++++++++++++------------- web/app.php | 11 +----- web/app_dev.php | 4 --- web/app_test.php | 9 ++--- web/app_test_cached.php | 40 +++++++++++++++++++++ 13 files changed, 191 insertions(+), 81 deletions(-) create mode 100644 app/config/config_test_cached.yml create mode 100644 app/config/router_test_cached.php create mode 100644 web/app_test_cached.php diff --git a/.travis.yml b/.travis.yml index 6d2f51f2ed..e171081577 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,23 +47,28 @@ before_install: - composer self-update - - if [ $TRAVIS_PHP_VERSION != "7.0" ] && [ $TEST_SUITE = "no-javascript" ]; then travis/prepare/prepare-mongodb; fi - - - composer install --prefer-dist --no-interaction - - - if [ $TEST_SUITE = "javascript" ]; then travis/prepare/prepare-javascript; fi + - | + if [ $TRAVIS_PHP_VERSION != "7.0" ] && [ $TEST_SUITE = "no-javascript" ]; then + travis/prepare/prepare-mongodb + else + composer install --prefer-dist --no-interaction + fi - cat travis/prepare/opcache.ini >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini before_script: - - app/console doctrine:database:create --env=test - - app/console doctrine:schema:create --env=test - - app/console doctrine:phpcr:repository:init --env=test + - app/console doctrine:database:create --env=test_cached + - app/console doctrine:schema:create --env=test_cached + - app/console doctrine:phpcr:repository:init --env=test_cached - - app/console cache:warmup --env=test --no-debug + - app/console cache:warmup --env=test_cached --no-debug - - if [ $TEST_SUITE = "javascript" ]; then app/console assets:install --env=test; fi - - if [ $TEST_SUITE = "javascript" ]; then app/console assetic:dump --env=test; fi + - | + if [ $TEST_SUITE = "javascript" ]; then + travis/prepare/prepare-javascript + app/console assets:install --env=test_cached --no-debug + app/console assetic:dump --env=test_cached --no-debug + fi - php -v - php -i diff --git a/app/config/config_test.yml b/app/config/config_test.yml index 91ee12e2d7..657b24e058 100644 --- a/app/config/config_test.yml +++ b/app/config/config_test.yml @@ -21,13 +21,6 @@ doctrine: dbname: %sylius.database.name%_test path: %sylius.database.path% driver_class: Sylius\Bundle\CoreBundle\Tests\MySqlDriver - orm: - entity_managers: - default: - metadata_cache_driver: - type: memcached - host: localhost - port: 11211 sylius_money: currency: EUR diff --git a/app/config/config_test_cached.yml b/app/config/config_test_cached.yml new file mode 100644 index 0000000000..c5215a5fa5 --- /dev/null +++ b/app/config/config_test_cached.yml @@ -0,0 +1,21 @@ +# This file is part of the Sylius package. +# (c) Paweł Jędrzejewski + +imports: + - { resource: config_test.yml } + +doctrine: + orm: + entity_managers: + default: + metadata_cache_driver: + type: memcached + host: localhost + port: 11211 + +doctrine_phpcr: + odm: + metadata_cache_driver: + type: memcached + host: localhost + port: 11211 diff --git a/app/config/router_test_cached.php b/app/config/router_test_cached.php new file mode 100644 index 0000000000..d79636f7fa --- /dev/null +++ b/app/config/router_test_cached.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/* + * This file implements rewrite rules for PHP built-in web server. + * + * See: http://www.php.net/manual/en/features.commandline.webserver.php + * + * If you have custom directory layout, then you have to write your own router + * and pass it as a value to 'router' option of server:run command. + * + * @author: Michał Pipa + * @author: Albert Jessurum + */ + +// Workaround https://bugs.php.net/64566 +if (ini_get('auto_prepend_file') && !in_array(realpath(ini_get('auto_prepend_file')), get_included_files(), true)) { + require ini_get('auto_prepend_file'); +} + +if (is_file($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.$_SERVER['SCRIPT_NAME'])) { + return false; +} + +$_SERVER = array_merge($_SERVER, $_ENV); +$_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'app_test_cached.php'; + +require 'app_test_cached.php'; + +error_log(sprintf('%s:%d [%d]: %s', $_SERVER['REMOTE_ADDR'], $_SERVER['REMOTE_PORT'], http_response_code(), $_SERVER['REQUEST_URI']), 4); diff --git a/behat.yml.dist b/behat.yml.dist index 060627ff36..09bc68de4f 100644 --- a/behat.yml.dist +++ b/behat.yml.dist @@ -405,9 +405,7 @@ default: sessions: default: symfony2: ~ - Behat\Symfony2Extension: - kernel: - debug: false + Behat\Symfony2Extension: ~ gherkin: filters: @@ -434,3 +432,37 @@ javascript: gherkin: filters: tags: "@javascript" + +cached: + extensions: + Behat\Symfony2Extension: + kernel: + env: test_cached + debug: false + +javascript_cached: + extensions: + Lakion\Behat\MinkDebugExtension: + screenshot: true + Behat\MinkExtension: + base_url: http://localhost:8080/ + selenium2: + capabilities: + browserName: chrome + browser: chrome + version: "" + chrome: + switches: + - "start-fullscreen" + - "no-sandbox" + browser_name: chrome + show_auto: false + Behat\Symfony2Extension: + kernel: + env: test_cached + debug: false + + gherkin: + filters: + tags: "@javascript" + diff --git a/travis/prepare/prepare-cached-composer b/travis/prepare/prepare-cached-composer index a2f10aaa31..405f7fc5a2 100755 --- a/travis/prepare/prepare-cached-composer +++ b/travis/prepare/prepare-cached-composer @@ -33,8 +33,7 @@ function restore_composer_lock_from_cache # Argument 1: Cache unique key function is_cache_fresh { - if [ -f $SYLIUS_CACHE_DIR/composer-$1.lock ] && [ -f $SYLIUS_CACHE_DIR/composer-$1.lock.md5sum ] && [ file_md5sum 'composer.lock' -eq `cat $SYLIUS_CACHE_DIR/composer-$1.lock.md5sum` ]; - then + if [ -f "$SYLIUS_CACHE_DIR/composer-$1.lock" ] && [ -f "$SYLIUS_CACHE_DIR/composer-$1.lock.md5sum" ] && [ file_md5sum 'composer.lock' -eq "`cat $SYLIUS_CACHE_DIR/composer-$1.lock.md5sum`" ]; then return 0 else return 1 diff --git a/travis/prepare/prepare-javascript b/travis/prepare/prepare-javascript index 3fddda4f31..e574b0a0aa 100755 --- a/travis/prepare/prepare-javascript +++ b/travis/prepare/prepare-javascript @@ -27,5 +27,5 @@ java -jar $SYLIUS_CACHE_DIR/selenium.jar -Dwebdriver.chrome.driver=$SYLIUS_CACHE vendor/lakion/mink-debug-extension/travis/tools/wait-for-port 4444 # Running webserver -app/console server:run 127.0.0.1:8080 --env=test > $SYLIUS_BUILD_DIR/webserver.log 2>&1 & +app/console server:run 127.0.0.1:8080 --env=test_cached --router=app/config/router_test_cached.php --no-debug > $SYLIUS_BUILD_DIR/webserver.log 2>&1 & vendor/lakion/mink-debug-extension/travis/tools/wait-for-port 8080 diff --git a/travis/suites/suite-javascript b/travis/suites/suite-javascript index a4d0edce60..ba29b167a2 100755 --- a/travis/suites/suite-javascript +++ b/travis/suites/suite-javascript @@ -1,12 +1,12 @@ #!/bin/bash -bin/behat --strict -f progress -p javascript -s channels -bin/behat --strict -f progress -p javascript -s users -bin/behat --strict -f progress -p javascript -s taxonomies -bin/behat --strict -f progress -p javascript -s taxation -bin/behat --strict -f progress -p javascript -s shipping -bin/behat --strict -f progress -p javascript -s promotions -bin/behat --strict -f progress -p javascript -s products -bin/behat --strict -f progress -p javascript -s payments -bin/behat --strict -f progress -p javascript -s orders -bin/behat --strict -f progress -p javascript -s addressing -bin/behat --strict -f progress -p javascript -s account \ No newline at end of file +bin/behat --strict -f progress -p javascript_cached -s channels +bin/behat --strict -f progress -p javascript_cached -s users +bin/behat --strict -f progress -p javascript_cached -s taxonomies +bin/behat --strict -f progress -p javascript_cached -s taxation +bin/behat --strict -f progress -p javascript_cached -s shipping +bin/behat --strict -f progress -p javascript_cached -s promotions +bin/behat --strict -f progress -p javascript_cached -s products +bin/behat --strict -f progress -p javascript_cached -s payments +bin/behat --strict -f progress -p javascript_cached -s orders +bin/behat --strict -f progress -p javascript_cached -s addressing +bin/behat --strict -f progress -p javascript_cached -s account diff --git a/travis/suites/suite-no-javascript b/travis/suites/suite-no-javascript index c6a3c454d7..1e6588125c 100755 --- a/travis/suites/suite-no-javascript +++ b/travis/suites/suite-no-javascript @@ -1,28 +1,28 @@ #!/bin/bash bin/phpspec run -f dot -bin/behat --strict -f progress -s account -bin/behat --strict -f progress -s cart -bin/behat --strict -f progress -s currencies -bin/behat --strict -f progress -s dashboard -bin/behat --strict -f progress -s homepage -bin/behat --strict -f progress -s inventory -bin/behat --strict -f progress -s localization -bin/behat --strict -f progress -s oauth -bin/behat --strict -f progress -s reports -bin/behat --strict -f progress -s taxonomies -bin/behat --strict -f progress -s users -bin/behat --strict -f progress -s search -bin/behat --strict -f progress -s checkout -bin/behat --strict -f progress -s addressing -bin/behat --strict -f progress -s emails -bin/behat --strict -f progress -s orders -bin/behat --strict -f progress -s payments -bin/behat --strict -f progress -s pricing -bin/behat --strict -f progress -s settings -bin/behat --strict -f progress -s shipping -bin/behat --strict -f progress -s taxation -bin/behat --strict -f progress -s i18n -bin/behat --strict -f progress -s channels -bin/behat --strict -f progress -s products -bin/behat --strict -f progress -s promotions +bin/behat --strict -f progress -p cached -s account +bin/behat --strict -f progress -p cached -s cart +bin/behat --strict -f progress -p cached -s currencies +bin/behat --strict -f progress -p cached -s dashboard +bin/behat --strict -f progress -p cached -s homepage +bin/behat --strict -f progress -p cached -s inventory +bin/behat --strict -f progress -p cached -s localization +bin/behat --strict -f progress -p cached -s oauth +bin/behat --strict -f progress -p cached -s reports +bin/behat --strict -f progress -p cached -s taxonomies +bin/behat --strict -f progress -p cached -s users +bin/behat --strict -f progress -p cached -s search +bin/behat --strict -f progress -p cached -s checkout +bin/behat --strict -f progress -p cached -s addressing +bin/behat --strict -f progress -p cached -s emails +bin/behat --strict -f progress -p cached -s orders +bin/behat --strict -f progress -p cached -s payments +bin/behat --strict -f progress -p cached -s pricing +bin/behat --strict -f progress -p cached -s settings +bin/behat --strict -f progress -p cached -s shipping +bin/behat --strict -f progress -p cached -s taxation +bin/behat --strict -f progress -p cached -s i18n +bin/behat --strict -f progress -p cached -s channels +bin/behat --strict -f progress -p cached -s products +bin/behat --strict -f progress -p cached -s promotions diff --git a/web/app.php b/web/app.php index cc9574ac0c..b35309ef69 100644 --- a/web/app.php +++ b/web/app.php @@ -17,23 +17,14 @@ use Symfony\Component\HttpFoundation\Request; * Live (production) environment. */ -$loader = require_once __DIR__.'/../app/bootstrap.php.cache'; - -//$loader = new ApcClassLoader('sylius', $loader); -//$loader->register(true); - +require_once __DIR__.'/../app/bootstrap.php.cache'; require_once __DIR__.'/../app/AppKernel.php'; -//require_once __DIR__.'/../app/AppCache.php'; $kernel = new AppKernel('prod', false); $kernel->loadClassCache(); -//$kernel = new AppCache($kernel); - $request = Request::createFromGlobals(); -Request::enableHttpMethodParameterOverride(); - $response = $kernel->handle($request); $response->send(); diff --git a/web/app_dev.php b/web/app_dev.php index 11206b8820..8bfa121e0e 100644 --- a/web/app_dev.php +++ b/web/app_dev.php @@ -31,14 +31,10 @@ Debug::enable(); require_once __DIR__.'/../app/AppKernel.php'; -// Initialize kernel and run the application. $kernel = new AppKernel('dev', true); -$kernel->loadClassCache(); $request = Request::createFromGlobals(); -Request::enableHttpMethodParameterOverride(); - $response = $kernel->handle($request); $response->send(); diff --git a/web/app_test.php b/web/app_test.php index fdae984a23..d5d1b5d404 100644 --- a/web/app_test.php +++ b/web/app_test.php @@ -13,7 +13,7 @@ use Symfony\Component\HttpFoundation\Request; /* * Sylius front controller. - * Testing environment. + * Testing dev-like environment. */ if (isset($_SERVER['HTTP_CLIENT_IP']) @@ -27,17 +27,12 @@ if (isset($_SERVER['HTTP_CLIENT_IP']) $loader = require_once __DIR__.'/../app/bootstrap.php.cache'; -// Require kernel. require_once __DIR__.'/../app/AppKernel.php'; -// Initialize kernel and run the application. -$kernel = new AppKernel('test', false); -$kernel->loadClassCache(); +$kernel = new AppKernel('test', true); $request = Request::createFromGlobals(); -Request::enableHttpMethodParameterOverride(); - $response = $kernel->handle($request); $response->send(); diff --git a/web/app_test_cached.php b/web/app_test_cached.php new file mode 100644 index 0000000000..9bb479c0a1 --- /dev/null +++ b/web/app_test_cached.php @@ -0,0 +1,40 @@ +loadClassCache(); + +$request = Request::createFromGlobals(); + +$response = $kernel->handle($request); +$response->send(); + +$kernel->terminate($request, $response);