public function VendorHardeningPluginTest::testCleanAllPackages in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/VendorHardeningPluginTest.php \Drupal\Tests\Composer\Plugin\VendorHardening\VendorHardeningPluginTest::testCleanAllPackages()
@covers ::cleanAllPackages
File
- core/tests/ Drupal/ Tests/ Composer/ Plugin/ VendorHardening/ VendorHardeningPluginTest.php, line 107 
Class
- VendorHardeningPluginTest
- @coversDefaultClass \Drupal\Composer\Plugin\VendorHardening\VendorHardeningPlugin @group VendorHardening
Namespace
Drupal\Tests\Composer\Plugin\VendorHardeningCode
public function testCleanAllPackages() {
  $config = $this
    ->getMockBuilder(Config::class)
    ->disableOriginalConstructor()
    ->getMock();
  $config
    ->expects($this
    ->once())
    ->method('getAllCleanupPaths')
    ->willReturn([
    'drupal/package' => [
      'tests',
    ],
  ]);
  $package = $this
    ->getMockBuilder(PackageInterface::class)
    ->getMockForAbstractClass();
  $package
    ->expects($this
    ->any())
    ->method('getName')
    ->willReturn('drupal/package');
  $plugin = $this
    ->getMockBuilder(VendorHardeningPlugin::class)
    ->setMethods([
    'getInstalledPackages',
    'getInstallPathForPackage',
  ])
    ->getMock();
  $plugin
    ->expects($this
    ->once())
    ->method('getInstalledPackages')
    ->willReturn([
    $package,
  ]);
  $plugin
    ->expects($this
    ->once())
    ->method('getInstallPathForPackage')
    ->willReturn(vfsStream::url('vendor/drupal/package'));
  $io = $this
    ->prophesize(IOInterface::class);
  $ref_io = new \ReflectionProperty($plugin, 'io');
  $ref_io
    ->setAccessible(TRUE);
  $ref_io
    ->setValue($plugin, $io
    ->reveal());
  $ref_config = new \ReflectionProperty($plugin, 'config');
  $ref_config
    ->setAccessible(TRUE);
  $ref_config
    ->setValue($plugin, $config);
  $this
    ->assertFileExists(vfsStream::url('vendor/drupal/package/tests/SomeTest.php'));
  $plugin
    ->cleanAllPackages();
  $this
    ->assertFileDoesNotExist(vfsStream::url('vendor/drupal/package/tests'));
}