From 042f058fb6f4c7b5318ad1b7239bbb81da38bd73 Mon Sep 17 00:00:00 2001 From: Hristo Chonov Date: Mon, 27 Feb 2017 11:47:36 +0100 Subject: [PATCH 1/8] Transform RedisLockFunctionalTest from WTB to BTB --- .../src/Functional/Lock}/RedisLockFunctionalTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename {src/Tests => tests/src/Functional/Lock}/RedisLockFunctionalTest.php (91%) diff --git a/src/Tests/RedisLockFunctionalTest.php b/tests/src/Functional/Lock/RedisLockFunctionalTest.php similarity index 91% rename from src/Tests/RedisLockFunctionalTest.php rename to tests/src/Functional/Lock/RedisLockFunctionalTest.php index 3e9b032..22fb2e3 100644 --- a/src/Tests/RedisLockFunctionalTest.php +++ b/tests/src/Functional/Lock/RedisLockFunctionalTest.php @@ -1,10 +1,10 @@ Date: Mon, 27 Feb 2017 14:34:17 +0100 Subject: [PATCH 2/8] Use Drupal 8.3.x core where the tests were converted to BTB --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 214d7f1..83d2037 100644 --- a/.travis.yml +++ b/.travis.yml @@ -63,8 +63,8 @@ env: - DRUPAL_TI_BEHAT_DRIVER="phantomjs" - DRUPAL_TI_BEHAT_BROWSER="firefox" - # Use Drupal 8.2.x to run tests. - - DRUPAL_TI_CORE_BRANCH="8.2.x" + # Use Drupal 8.3.x to run tests. + - DRUPAL_TI_CORE_BRANCH="8.3.x" # PHPUnit specific commandline arguments. - DRUPAL_TI_PHPUNIT_ARGS="--verbose --debug" From d64e4859aae2a13df59311d21ca6ddbabce447c6 Mon Sep 17 00:00:00 2001 From: Sascha Grossenbacher Date: Mon, 27 Feb 2017 22:14:58 +0100 Subject: [PATCH 3/8] PHP 7 must not fail --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 83d2037..e2afd04 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,6 @@ php: matrix: fast_finish: true allow_failures: - - php: 7 - php: hhvm env: From 769dcf6df162786be76530ecf846c9bcc70a0978 Mon Sep 17 00:00:00 2001 From: Sascha Grossenbacher Date: Mon, 27 Feb 2017 22:39:49 +0100 Subject: [PATCH 4/8] Try to use correct modules folder --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e2afd04..ff1dbd0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -101,7 +101,7 @@ services: before_install: - composer self-update - - composer global require "lionsad/drupal_ti:dev-master" + - composer global require "lionsad/drupal_ti:dev-master#a00d1ad64e9ea6cca872ab7869aaf1061bba6a73" - drupal-ti before_install install: From 4735aee4b6308a82fd600ec2063aa339376c639f Mon Sep 17 00:00:00 2001 From: Sascha Grossenbacher Date: Mon, 27 Feb 2017 22:51:33 +0100 Subject: [PATCH 5/8] Update drupal_ti PR reference --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ff1dbd0..8f92d31 100644 --- a/.travis.yml +++ b/.travis.yml @@ -101,7 +101,7 @@ services: before_install: - composer self-update - - composer global require "lionsad/drupal_ti:dev-master#a00d1ad64e9ea6cca872ab7869aaf1061bba6a73" + - composer global require "lionsad/drupal_ti:dev-master#396d11d200005eb68491d24170da0a98ae7f51b3" - drupal-ti before_install install: From 6494b08d36329b01965ac469b332a34d708b36b7 Mon Sep 17 00:00:00 2001 From: Sascha Grossenbacher Date: Mon, 27 Feb 2017 23:25:41 +0100 Subject: [PATCH 6/8] Convert the remaining tests to phpunit, no longer run run-tests.sh and fix Lock test namespace --- .travis.yml | 2 +- .../Lock/RedisLockFunctionalTest.php | 2 +- .../src/Functional}/WebTest.php | 27 ++++++++++--------- .../src/Kernel/PhpRedisCacheTest.php | 10 +++---- 4 files changed, 22 insertions(+), 19 deletions(-) rename {src/Tests => tests/src/Functional}/WebTest.php (86%) rename src/Tests/Cache/PhpRedisUnitTest.php => tests/src/Kernel/PhpRedisCacheTest.php (78%) diff --git a/.travis.yml b/.travis.yml index 8f92d31..dd8a2e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -88,7 +88,7 @@ env: #- DRUPAL_TI_RUNNERS="phpunit" #- DRUPAL_TI_RUNNERS="simpletest" #- DRUPAL_TI_RUNNERS="behat" - - DRUPAL_TI_RUNNERS="phpunit-core simpletest" + - DRUPAL_TI_RUNNERS="phpunit-core" # This will create the database mysql: diff --git a/tests/src/Functional/Lock/RedisLockFunctionalTest.php b/tests/src/Functional/Lock/RedisLockFunctionalTest.php index 22fb2e3..70088d9 100644 --- a/tests/src/Functional/Lock/RedisLockFunctionalTest.php +++ b/tests/src/Functional/Lock/RedisLockFunctionalTest.php @@ -1,6 +1,6 @@ drupalPlaceBlock('system_breadcrumb_block'); $this->drupalPlaceBlock('local_tasks_block'); - $cache_configuration = [ + // Set in-memory settings. + $settings = Settings::getAll(); + $settings['cache'] = [ 'default' => 'cache.backend.redis', 'bins' => [ 'config' => 'cache.backend.chainedfast', @@ -42,8 +43,10 @@ protected function setUp() { 'discovery' => 'cache.backend.chainedfast', ], ]; - $this->settingsSet('cache', $cache_configuration); + new Settings($settings); + // Write settings.php for HTTP requests. + $settings = []; $settings['settings']['cache']['default'] = (object) array( 'value' => 'cache.backend.redis', 'required' => TRUE, @@ -92,14 +95,14 @@ public function testModuleInstallation() { $this->drupalLogin($admin_user); // Enable a few modules. - $edit["modules[Core][node][enable]"] = TRUE; - $edit["modules[Core][views][enable]"] = TRUE; - $edit["modules[Core][field_ui][enable]"] = TRUE; - $edit["modules[Field types][text][enable]"] = TRUE; + $edit["modules[node][enable]"] = TRUE; + $edit["modules[views][enable]"] = TRUE; + $edit["modules[field_ui][enable]"] = TRUE; + $edit["modules[text][enable]"] = TRUE; $this->drupalPostForm('admin/modules', $edit, t('Install')); $this->drupalPostForm(NULL, [], t('Continue')); - $this->assertText('6 modules have been enabled: Field UI, Node, Views, Text, Field, Filter.'); - $this->assertFieldChecked('edit-modules-core-field-ui-enable'); + $this->assertSession()->responseContains('6 modules have been enabled: Field UI, Node, Text, Views, Field, Filter.'); + $this->assertSession()->checkboxChecked('edit-modules-field-ui-enable'); // Create a node type with a field. $edit = [ diff --git a/src/Tests/Cache/PhpRedisUnitTest.php b/tests/src/Kernel/PhpRedisCacheTest.php similarity index 78% rename from src/Tests/Cache/PhpRedisUnitTest.php rename to tests/src/Kernel/PhpRedisCacheTest.php index 22ff9e8..5e00e37 100644 --- a/src/Tests/Cache/PhpRedisUnitTest.php +++ b/tests/src/Kernel/PhpRedisCacheTest.php @@ -1,9 +1,9 @@ has('redis.factory')) { $container->register('cache_tags.invalidator.checksum', 'Drupal\redis\Cache\RedisCacheTagsChecksum') From 704581081df1bd7b16f9264450544475e512ed12 Mon Sep 17 00:00:00 2001 From: Sascha Grossenbacher Date: Mon, 27 Feb 2017 23:36:56 +0100 Subject: [PATCH 7/8] Avoid asserting an exact order of installed modules --- tests/src/Functional/WebTest.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/src/Functional/WebTest.php b/tests/src/Functional/WebTest.php index 7ec49f5..d868e20 100644 --- a/tests/src/Functional/WebTest.php +++ b/tests/src/Functional/WebTest.php @@ -101,8 +101,19 @@ public function testModuleInstallation() { $edit["modules[text][enable]"] = TRUE; $this->drupalPostForm('admin/modules', $edit, t('Install')); $this->drupalPostForm(NULL, [], t('Continue')); - $this->assertSession()->responseContains('6 modules have been enabled: Field UI, Node, Text, Views, Field, Filter.'); - $this->assertSession()->checkboxChecked('edit-modules-field-ui-enable'); + + $assert = $this->assertSession(); + + // The order of the modules is not guaranteed, so just assert that they are + // all listed. + $assert->elementTextContains('css', '.messages--status', '6 modules have been enabled'); + $assert->elementTextContains('css', '.messages--status', 'Field UI'); + $assert->elementTextContains('css', '.messages--status', 'Node'); + $assert->elementTextContains('css', '.messages--status', 'Text'); + $assert->elementTextContains('css', '.messages--status', 'Views'); + $assert->elementTextContains('css', '.messages--status', 'Field'); + $assert->elementTextContains('css', '.messages--status', 'Filter'); + $assert->checkboxChecked('edit-modules-field-ui-enable'); // Create a node type with a field. $edit = [ From 5e7f07bda488e044b46a4763e0924e0183b21b79 Mon Sep 17 00:00:00 2001 From: Sascha Grossenbacher Date: Tue, 28 Feb 2017 00:30:10 +0100 Subject: [PATCH 8/8] Make path to redis module dynamic, include bootstrap container --- .travis.yml | 1 - tests/src/Functional/WebTest.php | 65 +++++++++++++++++++------------- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/.travis.yml b/.travis.yml index dd8a2e6..367e7e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -100,7 +100,6 @@ services: - redis-server before_install: - - composer self-update - composer global require "lionsad/drupal_ti:dev-master#396d11d200005eb68491d24170da0a98ae7f51b3" - drupal-ti before_install diff --git a/tests/src/Functional/WebTest.php b/tests/src/Functional/WebTest.php index d868e20..78e05a7 100644 --- a/tests/src/Functional/WebTest.php +++ b/tests/src/Functional/WebTest.php @@ -37,41 +37,52 @@ protected function setUp() { $settings = Settings::getAll(); $settings['cache'] = [ 'default' => 'cache.backend.redis', - 'bins' => [ - 'config' => 'cache.backend.chainedfast', - 'bootstrap' => 'cache.backend.chainedfast', - 'discovery' => 'cache.backend.chainedfast', + ]; + $settings['container_yamls'][] = drupal_get_path('module', 'redis') . '/example.services.yml'; + + $settings['bootstrap_container_definition'] = [ + 'parameters' => [], + 'services' => [ + 'redis.factory' => [ + 'class' => 'Drupal\redis\ClientFactory', + ], + 'cache.backend.redis' => [ + 'class' => 'Drupal\redis\Cache\CacheBackendFactory', + 'arguments' => ['@redis.factory', '@cache_tags_provider.container', '@serialization.phpserialize'], + ], + 'cache.container' => [ + 'class' => '\Drupal\redis\Cache\PhpRedis', + 'factory' => ['@cache.backend.redis', 'get'], + 'arguments' => ['container'], + ], + 'cache_tags_provider.container' => [ + 'class' => 'Drupal\redis\Cache\RedisCacheTagsChecksum', + 'arguments' => ['@redis.factory'], + ], + 'serialization.phpserialize' => [ + 'class' => 'Drupal\Component\Serialization\PhpSerialize', + ], ], ]; new Settings($settings); - // Write settings.php for HTTP requests. - $settings = []; - $settings['settings']['cache']['default'] = (object) array( - 'value' => 'cache.backend.redis', - 'required' => TRUE, - ); - $settings['settings']['cache']['bins'] = (object) array( - 'value' => [ - 'config' => 'cache.backend.chainedfast', - 'bootstrap' => 'cache.backend.chainedfast', - 'discovery' => 'cache.backend.chainedfast', - ], - 'required' => TRUE, - ); - - $this->writeSettings($settings); - // Write the containers_yaml update by hand, since writeSettings() doesn't - // support this syntax. + // support some of the definitions. $filename = $this->siteDirectory . '/settings.php'; chmod($filename, 0666); $contents = file_get_contents($filename); - $contents .= "\n\n" . '$settings[\'container_yamls\'][] = \'modules/redis/example.services.yml\';'; + + // Add the container_yaml and cache definition. + $contents .= "\n\n" . '$settings["container_yamls"][] = "' . drupal_get_path('module', 'redis') . '/example.services.yml";'; + $contents .= "\n\n" . '$settings["cache"] = ' . var_export($settings['cache'], TRUE) . ';'; + + // Add the classloader. + $contents .= "\n\n" . '$class_loader->addPsr4(\'Drupal\\\\redis\\\\\', \'' . drupal_get_path('module', 'redis') . '/src\');'; + + // Add the bootstrap container definition. + $contents .= "\n\n" . '$settings["bootstrap_container_definition"] = ' . var_export($settings['bootstrap_container_definition'], TRUE) . ';'; + file_put_contents($filename, $contents); - $settings = Settings::getAll(); - $settings['container_yamls'][] = 'modules/redis/example.services.yml'; - new Settings($settings); OpCodeCache::invalidate(DRUPAL_ROOT . '/' . $filename); // Reset the cache factory. @@ -82,6 +93,7 @@ protected function setUp() { db_drop_table('cache_default'); db_drop_table('cache_render'); db_drop_table('cache_config'); + db_drop_table('cache_container'); db_drop_table('cachetags'); db_drop_table('semaphore'); db_drop_table('flood'); @@ -158,6 +170,7 @@ public function testModuleInstallation() { $this->assertFalse(db_table_exists('cache_default')); $this->assertFalse(db_table_exists('cache_render')); $this->assertFalse(db_table_exists('cache_config')); + $this->assertFalse(db_table_exists('cache_container')); $this->assertFalse(db_table_exists('cachetags')); $this->assertFalse(db_table_exists('semaphore')); $this->assertFalse(db_table_exists('flood'));