class PackageUpdateTest

Tests updating packages in a stage directory.

@group package_manager @internal

Hierarchy

Expanded class hierarchy of PackageUpdateTest

File

core/modules/package_manager/tests/src/Build/PackageUpdateTest.php, line 15

Namespace

Drupal\Tests\package_manager\Build
View source
class PackageUpdateTest extends TemplateProjectTestBase {
    
    /**
     * Tests updating packages in a stage directory.
     */
    public function testPackageUpdate() : void {
        $this->createTestProject('RecommendedProject');
        $fixtures = __DIR__ . '/../../fixtures/build_test_projects';
        $alpha_repo_path = $this->copyFixtureToTempDirectory("{$fixtures}/alpha/1.0.0");
        $this->addRepository('alpha', $alpha_repo_path);
        $updated_module_repo_path = $this->copyFixtureToTempDirectory("{$fixtures}/updated_module/1.0.0");
        $this->addRepository('updated_module', $updated_module_repo_path);
        $this->setReleaseMetadata([
            'updated_module' => __DIR__ . '/../../fixtures/release-history/updated_module.1.1.0.xml',
        ]);
        $this->runComposer('composer require drupal/alpha drupal/updated_module --update-with-all-dependencies', 'project');
        // The updated_module provides actual Drupal-facing functionality that we're
        // testing as well, so we need to install it.
        $this->installModules([
            'updated_module',
        ]);
        // Change both modules' upstream version.
        static::copyFixtureFilesTo("{$fixtures}/alpha/1.1.0", $alpha_repo_path);
        static::copyFixtureFilesTo("{$fixtures}/updated_module/1.1.0", $updated_module_repo_path);
        // Make .git folder
        // Use the API endpoint to create a stage and update updated_module to
        // 1.1.0. Even though both modules have version 1.1.0 available, only
        // updated_module should be updated.
        $this->makePackageManagerTestApiRequest('/package-manager-test-api', [
            'runtime' => [
                'drupal/updated_module:1.1.0',
            ],
        ]);
        $expected_versions = [
            'alpha' => '1.0.0',
            'updated_module' => '1.1.0',
        ];
        foreach ($expected_versions as $module_name => $expected_version) {
            $path = "/modules/contrib/{$module_name}/composer.json";
            $module_composer_json = json_decode(file_get_contents($this->getWebRoot() . "/{$path}"));
            $this->assertSame($expected_version, $module_composer_json?->version);
        }
        // The post-apply event subscriber in updated_module 1.1.0 should have
        // created this file.
        // @see \Drupal\updated_module\PostApplySubscriber::postApply()
        $this->assertSame('Bravo!', file_get_contents($this->getWorkspaceDirectory() . '/project/bravo.txt'));
        $this->assertExpectedStageEventsFired(ControllerStage::class);
        $this->assertRequestedChangesWereLogged([
            'Update drupal/updated_module from 1.0.0 to 1.1.0',
        ]);
        $this->assertAppliedChangesWereLogged([
            'Updated drupal/updated_module from 1.0.0 to 1.1.0',
        ]);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
AssertPreconditionsTrait::assertNoFailureMarker private static function Asserts that there is no failure marker present.
AssertPreconditionsTrait::failIfUnmetPreConditions protected static function Asserts universal test preconditions before any setup is done.
AssertPreconditionsTrait::getProjectRoot private static function Returns the absolute path of the project root.
AssertPreconditionsTrait::setUpBeforeClass public static function Invokes the test preconditions assertion before the first test is run.
BuildTestBase::$commandProcess private property The most recent command process.
BuildTestBase::$destroyBuild protected property Default to destroying build artifacts after a test finishes.
BuildTestBase::$hostName private static property Our native host name, used by PHP when it starts up the server.
BuildTestBase::$hostPort private property Port that will be tested.
BuildTestBase::$mink private property The Mink session manager.
BuildTestBase::$phpFinder private property The PHP executable finder.
BuildTestBase::$portLocks private property A list of ports used by the test.
BuildTestBase::$serverDocroot private property The docroot for the server process.
BuildTestBase::$serverProcess private property The process that's running the HTTP server.
BuildTestBase::$workspaceDir private property The working directory where this test will manipulate files.
BuildTestBase::assertCommandExitCode public function Asserts that the last command returned the specified exit code.
BuildTestBase::assertCommandOutputContains public function Assert that text is present in the output of the most recent command.
BuildTestBase::assertCommandSuccessful public function Asserts that the last command ran without error.
BuildTestBase::assertDrupalVisit public function Helper function to assert that the last visit was a Drupal site.
BuildTestBase::assertErrorOutputContains public function Assert that text is present in the error output of the most recent command.
BuildTestBase::assertErrorOutputNotContains public function Assert text is not present in the error output of the most recent command.
BuildTestBase::checkPortIsAvailable protected function Checks whether a port is available.
BuildTestBase::executeCommand public function Run a command.
BuildTestBase::findAvailablePort protected function Discover an available port number.
BuildTestBase::getCodebaseFinder public function Get a default Finder object for a Drupal codebase.
BuildTestBase::getComposerRoot public function Gets the path to the Composer root directory.
BuildTestBase::getDrupalRoot public function Get the root path of this Drupal codebase.
BuildTestBase::getDrupalRootStatic public static function Get the root path of this Drupal codebase.
BuildTestBase::getMink public function Get the Mink instance.
BuildTestBase::getPortNumber protected function Get the port number for requests.
BuildTestBase::getWorkingPath protected function Get the working directory within the workspace, creating if necessary.
BuildTestBase::getWorkingPathDrupalRoot public function Gets the working path for Drupal core.
BuildTestBase::getWorkspaceDirectory public function Full path to the workspace where this test can build.
BuildTestBase::getWorkspaceDrupalRoot public function Gets the path to Drupal root in the workspace directory.
BuildTestBase::initMink protected function Set up the Mink session manager.
BuildTestBase::standUpServer protected function Makes a local test server using PHP's internal HTTP server.
BuildTestBase::stopServer protected function Stop the HTTP server, zero out all necessary variables.
FixtureUtilityTrait::copyFixtureFilesTo protected static function Mirrors a fixture directory to the given path.
FixtureUtilityTrait::renameGitDirectories private static function Renames _git directories to .git.
FixtureUtilityTrait::renameInfoYmlFiles protected static function Renames all files that end with .info.yml.hide.
PackageUpdateTest::testPackageUpdate public function Tests updating packages in a stage directory.
QuickStartTestBase::$adminPassword protected property Password of the admin account generated during install.
QuickStartTestBase::$adminUsername protected property User name of the admin account generated during install.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RequiresComposerTrait::requiresComposer public static function
TemplateProjectTestBase::$metadataServer private property A secondary server instance, to serve XML metadata about available updates.
TemplateProjectTestBase::$serverErrorLog private property All output that the PHP web server logs to the error buffer.
TemplateProjectTestBase::$webRoot private property The web root of the test site, relative to the workspace directory.
TemplateProjectTestBase::addRepository protected function Adds a path repository to the test site.
TemplateProjectTestBase::assertAppliedChangesWereLogged protected function Asserts that changes applied during the stage life cycle were logged.
TemplateProjectTestBase::assertExpectedStageEventsFired protected function Asserts stage events were fired in a specific order.
TemplateProjectTestBase::assertRequestedChangesWereLogged protected function Asserts changes requested during the stage life cycle were logged.
TemplateProjectTestBase::copyCodebase public function Copy the current working codebase into a workspace. Overrides BuildTestBase::copyCodebase
TemplateProjectTestBase::copyFixtureToTempDirectory protected function Copies a fixture directory to a temporary directory and returns its path.
TemplateProjectTestBase::createTestProject protected function Creates a test project from a given template and installs Drupal.
TemplateProjectTestBase::createVendorRepository protected function Creates a Composer repository for all dependencies of the test project.
TemplateProjectTestBase::formLogin public function Helper that uses Drupal's user/login form to log in. Overrides QuickStartTestBase::formLogin
TemplateProjectTestBase::getWebRoot protected function Returns the full path to the test site's document root.
TemplateProjectTestBase::installModules protected function Installs modules in the UI.
TemplateProjectTestBase::installQuickStart public function Install a Drupal site using the quick start feature. Overrides QuickStartTestBase::installQuickStart
TemplateProjectTestBase::instantiateServer protected function Do the work of making a server process. Overrides BuildTestBase::instantiateServer
TemplateProjectTestBase::makePackageManagerTestApiRequest protected function Gets a /package-manager-test-api response.
TemplateProjectTestBase::MAX_EXECUTION_TIME protected constant The PHP web server's max_execution_time value.
TemplateProjectTestBase::providerTemplate public static function Data provider for tests which use all the core project templates.
TemplateProjectTestBase::runComposer protected function Runs a Composer command and returns its output.
TemplateProjectTestBase::setReleaseMetadata protected function Prepares the test site to serve an XML feed of available release metadata.
TemplateProjectTestBase::setUp protected function Overrides BuildTestBase::setUp
TemplateProjectTestBase::setUpstreamCoreVersion protected function Sets the version of Drupal core to which the test site will be updated.
TemplateProjectTestBase::tearDown protected function Invokes the test preconditions assertion after each test run. Overrides AssertPreconditionsTrait::tearDown
TemplateProjectTestBase::unboundCoreConstraints private static function Changes constraints for core packages to `*`.
TemplateProjectTestBase::visit public function Visit a URI on the HTTP server. Overrides BuildTestBase::visit
TemplateProjectTestBase::visitPackageManagerChangeLog private function Visits the 'admin/reports/dblog' and selects Package Manager's change log.
TemplateProjectTestBase::writeSettings protected function Appends PHP code to the test site's settings.php.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.