class ExternalCommandRequirementTest

Same name in other branches
  1. 9 core/tests/Drupal/BuildTests/Framework/Tests/ExternalCommandRequirementTest.php \Drupal\BuildTests\Framework\Tests\ExternalCommandRequirementTest
  2. 8.9.x core/tests/Drupal/BuildTests/Framework/Tests/ExternalCommandRequirementTest.php \Drupal\BuildTests\Framework\Tests\ExternalCommandRequirementTest

@coversDefaultClass \Drupal\BuildTests\Framework\ExternalCommandRequirementsTrait @group Build @group legacy

Hierarchy

  • class \Drupal\BuildTests\Framework\Tests\ExternalCommandRequirementTest extends \PHPUnit\Framework\TestCase uses \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait

Expanded class hierarchy of ExternalCommandRequirementTest

File

core/tests/Drupal/BuildTests/Framework/Tests/ExternalCommandRequirementTest.php, line 17

Namespace

Drupal\BuildTests\Framework\Tests
View source
class ExternalCommandRequirementTest extends TestCase {
    use ExpectDeprecationTrait;
    
    /**
     * @covers ::checkExternalCommandRequirements
     */
    public function testCheckExternalCommandRequirementsNotAvailable() : void {
        $this->expectDeprecation('Drupal\\BuildTests\\Framework\\ExternalCommandRequirementsTrait::checkExternalCommandRequirements() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use Drupal\\TestTools\\Extension\\RequiresComposerTrait instead. See https://www.drupal.org/node/3362239');
        $this->expectDeprecation('The \'@require externalCommand\' annotation for tests is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use Drupal\\TestTools\\Extension\\RequiresComposerTrait instead. See https://www.drupal.org/node/3362239');
        $requires = new UsesCommandRequirements();
        $ref_check_requirements = new \ReflectionMethod($requires, 'checkExternalCommandRequirements');
        // Use a try/catch block because otherwise PHPUnit might think this test is
        // legitimately skipped.
        try {
            $ref_check_requirements->invokeArgs($requires, [
                [
                    'externalCommand not_available',
                    'externalCommand available_command',
                ],
            ]);
            $this->fail('Unavailable external command requirement should throw a skipped test error exception.');
        } catch (SkippedTestError $exception) {
            $this->assertEquals('Required external commands: not_available', $exception->getMessage());
        }
    }
    
    /**
     * @covers ::checkExternalCommandRequirements
     */
    public function testCheckExternalCommandRequirementsAvailable() : void {
        $this->expectDeprecation('Drupal\\BuildTests\\Framework\\ExternalCommandRequirementsTrait::checkExternalCommandRequirements() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use Drupal\\TestTools\\Extension\\RequiresComposerTrait instead. See https://www.drupal.org/node/3362239');
        $this->expectDeprecation('The \'@require externalCommand\' annotation for tests is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use Drupal\\TestTools\\Extension\\RequiresComposerTrait instead. See https://www.drupal.org/node/3362239');
        $requires = new UsesCommandRequirements();
        $ref_check_requirements = new \ReflectionMethod($requires, 'checkExternalCommandRequirements');
        // Use a try/catch block because otherwise PHPUnit might think this test is
        // legitimately skipped.
        try {
            $this->assertNull($ref_check_requirements->invokeArgs($requires, [
                [
                    'externalCommand available_command',
                ],
            ]));
        } catch (SkippedTestError $exception) {
            $this->fail(sprintf('The external command should be available: %s', $exception->getMessage()));
        }
    }
    
    /**
     * @covers ::checkClassCommandRequirements
     */
    public function testClassRequiresAvailable() : void {
        $this->expectDeprecation('Drupal\\BuildTests\\Framework\\ExternalCommandRequirementsTrait::checkClassCommandRequirements() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use Drupal\\TestTools\\Extension\\RequiresComposerTrait instead. See https://www.drupal.org/node/3362239');
        $requires = new ClassRequiresAvailable();
        $ref_check = new \ReflectionMethod($requires, 'checkClassCommandRequirements');
        // Use a try/catch block because otherwise PHPUnit might think this test is
        // legitimately skipped.
        try {
            $this->assertNull($ref_check->invoke($requires));
        } catch (SkippedTestError $exception) {
            $this->fail(sprintf('The external command should be available: %s', $exception->getMessage()));
        }
    }
    
    /**
     * @covers ::checkClassCommandRequirements
     */
    public function testClassRequiresUnavailable() : void {
        $this->expectDeprecation('Drupal\\BuildTests\\Framework\\ExternalCommandRequirementsTrait::checkClassCommandRequirements() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use Drupal\\TestTools\\Extension\\RequiresComposerTrait instead. See https://www.drupal.org/node/3362239');
        $requires = new ClassRequiresUnavailable();
        $ref_check = new \ReflectionMethod($requires, 'checkClassCommandRequirements');
        // Use a try/catch block because otherwise PHPUnit might think this test is
        // legitimately skipped.
        try {
            $this->assertNull($ref_check->invoke($requires));
            $this->fail('Unavailable external command requirement should throw a skipped test error exception.');
        } catch (SkippedTestError $exception) {
            $this->assertEquals('Required external commands: unavailable_command', $exception->getMessage());
        }
    }
    
    /**
     * @covers ::checkMethodCommandRequirements
     */
    public function testMethodRequiresAvailable() : void {
        $this->expectDeprecation('Drupal\\BuildTests\\Framework\\ExternalCommandRequirementsTrait::checkMethodCommandRequirements() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use Drupal\\TestTools\\Extension\\RequiresComposerTrait instead. See https://www.drupal.org/node/3362239');
        $requires = new MethodRequires();
        $ref_check = new \ReflectionMethod($requires, 'checkMethodCommandRequirements');
        // Use a try/catch block because otherwise PHPUnit might think this test is
        // legitimately skipped.
        try {
            $this->assertNull($ref_check->invoke($requires, 'testRequiresAvailable'));
        } catch (SkippedTestError $exception) {
            $this->fail(sprintf('The external command should be available: %s', $exception->getMessage()));
        }
    }
    
    /**
     * @covers ::checkMethodCommandRequirements
     */
    public function testMethodRequiresUnavailable() : void {
        $this->expectDeprecation('Drupal\\BuildTests\\Framework\\ExternalCommandRequirementsTrait::checkMethodCommandRequirements() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use Drupal\\TestTools\\Extension\\RequiresComposerTrait instead. See https://www.drupal.org/node/3362239');
        $requires = new MethodRequires();
        $ref_check = new \ReflectionMethod($requires, 'checkMethodCommandRequirements');
        // Use a try/catch block because otherwise PHPUnit might think this test is
        // legitimately skipped.
        try {
            $this->assertNull($ref_check->invoke($requires, 'testRequiresUnavailable'));
            $this->fail('Unavailable external command requirement should throw a skipped test error exception.');
        } catch (SkippedTestError $exception) {
            $this->assertEquals('Required external commands: unavailable_command', $exception->getMessage());
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary
ExternalCommandRequirementTest::testCheckExternalCommandRequirementsAvailable public function @covers ::checkExternalCommandRequirements
ExternalCommandRequirementTest::testCheckExternalCommandRequirementsNotAvailable public function @covers ::checkExternalCommandRequirements
ExternalCommandRequirementTest::testClassRequiresAvailable public function @covers ::checkClassCommandRequirements
ExternalCommandRequirementTest::testClassRequiresUnavailable public function @covers ::checkClassCommandRequirements
ExternalCommandRequirementTest::testMethodRequiresAvailable public function @covers ::checkMethodCommandRequirements
ExternalCommandRequirementTest::testMethodRequiresUnavailable public function @covers ::checkMethodCommandRequirements

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