setComplete(); $rootPath = realpath(__DIR__ . '/../../../fixtures/'); $filesFinder = new FileSystemFilesFinder; $cache = new FileSystemCache; $initialOptions = new Options; $input = new MockProtocolStream; $output = new MockProtocolStream; $definitionResolver = new DefinitionResolver($projectIndex); $client = new LanguageClient($input, $output); $documentLoader = new PhpDocumentLoader(new FileSystemContentRetriever, $projectIndex, $definitionResolver); $textDocument = new Server\TextDocument($documentLoader, $definitionResolver, $client, $projectIndex); $indexer = new Indexer( $filesFinder, $rootPath, $client, $cache, $dependenciesIndex, $sourceIndex, $documentLoader, $initialOptions ); $workspace = new Server\Workspace( $client, $projectIndex, $dependenciesIndex, $sourceIndex, $initialOptions, null, $documentLoader ); $output->on('message', function (Message $msg) use ($promise) { if ($msg->body->method === 'window/showMessage' && $promise->state === Promise::PENDING) { $hasMessage = strpos( $msg->body->params->message, 'Settings could not be applied. For more information see logs.' ) !== false; if ($msg->body->params->type === MessageType::ERROR && $hasMessage) { $promise->fulfill(true); } if ($msg->body->params->type !== MessageType::ERROR) { $promise->reject(new Exception($msg->body->params->message)); } } }); $settings = new \stdClass(); $settings->php = new \stdClass(); $settings->php->fileTypes = 'not an array'; $workspace->didChangeConfiguration($settings); $this->assertTrue($promise->wait()); } public function testNoChangedOptions() { $promise = new Promise; $sourceIndex = new Index; $dependenciesIndex = new DependenciesIndex; $projectIndex = new ProjectIndex($sourceIndex, $dependenciesIndex); $projectIndex->setComplete(); $rootPath = realpath(__DIR__ . '/../../../fixtures/'); $filesFinder = new FileSystemFilesFinder; $cache = new FileSystemCache; $initialOptions = new Options; $input = new MockProtocolStream; $output = new MockProtocolStream; $definitionResolver = new DefinitionResolver($projectIndex); $client = new LanguageClient($input, $output); $documentLoader = new PhpDocumentLoader(new FileSystemContentRetriever, $projectIndex, $definitionResolver); $textDocument = new Server\TextDocument($documentLoader, $definitionResolver, $client, $projectIndex); $indexer = new Indexer( $filesFinder, $rootPath, $client, $cache, $dependenciesIndex, $sourceIndex, $documentLoader, $initialOptions ); $workspace = new Server\Workspace( $client, $projectIndex, $dependenciesIndex, $sourceIndex, $initialOptions, null, $documentLoader ); $output->on('message', function (Message $msg) use ($promise) { $promise->reject(new Exception($msg->body->message)); }); $settings = new \stdClass(); $settings->php = new \stdClass(); $settings->php->fileTypes = ['.php']; $this->expectException(\LogicException::class); $workspace->didChangeConfiguration($settings); $promise->wait(); } public function testDetectsChangedOptions() { $promise = new Promise; $sourceIndex = new Index; $dependenciesIndex = new DependenciesIndex; $projectIndex = new ProjectIndex($sourceIndex, $dependenciesIndex); $projectIndex->setComplete(); $rootPath = realpath(__DIR__ . '/../../../fixtures/'); $filesFinder = new FileSystemFilesFinder; $cache = new FileSystemCache; $initialOptions = new Options; $input = new MockProtocolStream; $output = new MockProtocolStream; $definitionResolver = new DefinitionResolver($projectIndex); $client = new LanguageClient($input, $output); $documentLoader = new PhpDocumentLoader(new FileSystemContentRetriever, $projectIndex, $definitionResolver); $textDocument = new Server\TextDocument($documentLoader, $definitionResolver, $client, $projectIndex); $indexer = new Indexer( $filesFinder, $rootPath, $client, $cache, $dependenciesIndex, $sourceIndex, $documentLoader, $initialOptions ); $workspace = new Server\Workspace( $client, $projectIndex, $dependenciesIndex, $sourceIndex, $initialOptions, null, $documentLoader ); $output->on('message', function (Message $msg) use ($promise) { if ($msg->body->method === 'window/showMessage' && $promise->state === Promise::PENDING) { $hasMessage = strpos( $msg->body->params->message, 'You must restart your editor for the changes to take effect.' ) !== false; if ($msg->body->params->type === MessageType::INFO && $hasMessage) { $promise->fulfill(true); } if ($msg->body->params->type === MessageType::ERROR) { $promise->reject(new Exception($msg->body->params->message)); } } }); $settings = new \stdClass(); $settings->php = new \stdClass(); $settings->php->fileTypes = ['.php', '.php5']; // default is only .php $workspace->didChangeConfiguration($settings); $this->assertTrue($promise->wait()); } }