View source
<?php
namespace Drupal\BuildTests\Framework\Tests;
use Drupal\BuildTests\Framework\BuildTestBase;
use org\bovigo\vfs\vfsStream;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
class BuildTestTest extends BuildTestBase {
public function testWorkspace() {
$test_directory = 'test_directory';
$process = $this
->executeCommand('', $test_directory);
$this
->assertCommandSuccessful();
$workspace = $this
->getWorkspaceDirectory();
$working_path = $workspace . '/' . $test_directory;
$this
->assertDirectoryExists($working_path);
$this
->assertEquals($working_path, $process
->getWorkingDirectory());
}
public function testCopyCodebase() {
$test_directory = 'copied_codebase';
$this
->copyCodebase(NULL, $test_directory);
$full_path = $this
->getWorkspaceDirectory() . '/' . $test_directory;
$files = [
'autoload.php',
'composer.json',
'index.php',
'README.md',
'.git',
'.ht.router.php',
];
foreach ($files as $file) {
$this
->assertFileExists($full_path . '/' . $file);
}
}
public function testCopyCodebaseExclude() {
vfsStream::setup('drupal', NULL, [
'sites' => [
'default' => [
'files' => [
'a_file.txt' => 'some file.',
],
'settings.php' => '<?php $settings = stuff;',
'settings.local.php' => '<?php $settings = override;',
],
'simpletest' => [
'simpletest_hash' => [
'some_results.xml' => '<xml/>',
],
],
],
'vendor' => [
'composer' => [
'composer' => [
'installed.json' => '"items": {"things"}',
],
],
],
'modules' => [
'my_module' => [
'vendor' => [
'my_vendor' => [
'composer.json' => "{\n}",
],
],
],
],
]);
$base = $this
->getMockBuilder(BuildTestBase::class)
->onlyMethods([
'getDrupalRoot',
])
->getMockForAbstractClass();
$base
->expects($this
->exactly(2))
->method('getDrupalRoot')
->willReturn(vfsStream::url('drupal'));
$base
->setUp();
$test_directory = 'copied_codebase';
$base
->copyCodebase(NULL, $test_directory);
$full_path = $base
->getWorkspaceDirectory() . '/' . $test_directory;
$this
->assertDirectoryExists($full_path);
$this
->assertFileExists($full_path . DIRECTORY_SEPARATOR . 'modules/my_module/vendor/my_vendor/composer.json');
$file_system = new Filesystem();
$file_system
->remove($full_path . DIRECTORY_SEPARATOR . 'modules');
$this
->assertTrue(($files = @scandir($full_path)) && count($files) <= 2, 'Directory is not empty: ' . implode(', ', $files));
$base
->tearDown();
}
public function testPortMany() {
$iterator = (new Finder())
->in($this
->getDrupalRoot())
->ignoreDotFiles(FALSE)
->exclude([
'sites/simpletest',
])
->path('/^.ht.router.php$/')
->getIterator();
$this
->copyCodebase($iterator);
$processes = [];
$count = 15;
for ($i = 0; $i <= $count; $i++) {
$port = $this
->findAvailablePort();
$this
->assertArrayNotHasKey($port, $processes, 'Port ' . $port . ' was already in use by a process.');
$processes[$port] = $this
->instantiateServer($port);
$this
->assertNotEmpty($processes[$port]);
$this
->assertTrue($processes[$port]
->isRunning(), 'Process on port ' . $port . ' is not still running.');
$this
->assertFalse($this
->checkPortIsAvailable($port));
}
foreach ($processes as $process) {
$process
->stop();
}
}
public function testStandUpServer() {
$this
->standUpServer('first');
$ref_process = new \ReflectionProperty(parent::class, 'serverProcess');
$ref_process
->setAccessible(TRUE);
$first_process = $ref_process
->getValue($this);
$this
->standUpServer('first');
$this
->assertSame($first_process, $ref_process
->getValue($this));
$this
->standUpServer('second');
$this
->assertNotSame($first_process, $second_process = $ref_process
->getValue($this));
$this
->standUpServer('first');
$this
->assertNotSame($first_process, $ref_process
->getValue($this));
$this
->assertNotSame($second_process, $ref_process
->getValue($this));
}
}