diff --git a/.travis.yml b/.travis.yml index 214d7f1..367e7e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,6 @@ php: matrix: fast_finish: true allow_failures: - - php: 7 - php: hhvm env: @@ -63,8 +62,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" @@ -89,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: @@ -101,8 +100,7 @@ services: - redis-server before_install: - - composer self-update - - composer global require "lionsad/drupal_ti:dev-master" + - composer global require "lionsad/drupal_ti:dev-master#396d11d200005eb68491d24170da0a98ae7f51b3" - drupal-ti before_install install: 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..70088d9 100644 --- a/src/Tests/RedisLockFunctionalTest.php +++ b/tests/src/Functional/Lock/RedisLockFunctionalTest.php @@ -1,10 +1,10 @@ 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', - 'bootstrap' => 'cache.backend.chainedfast', - 'discovery' => 'cache.backend.chainedfast', - ], ]; - $this->settingsSet('cache', $cache_configuration); - - $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', + $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', + ], ], - 'required' => TRUE, - ); - - $this->writeSettings($settings); + ]; + new Settings($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. @@ -79,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'); @@ -92,14 +107,25 @@ 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'); + + $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 = [ @@ -144,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')); 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')