ConfigTest.php

Same filename in this branch
  1. 11.x core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/d8/ConfigTest.php
  2. 11.x core/modules/config/tests/config_test/src/Entity/ConfigTest.php
  3. 11.x core/modules/migrate/tests/src/Unit/destination/ConfigTest.php
  4. 11.x core/modules/system/tests/src/Functional/File/ConfigTest.php
  5. 11.x core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/ConfigTest.php
  6. 11.x core/tests/Drupal/Tests/Core/Config/ConfigTest.php
Same filename and directory in other branches
  1. 9 core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/d8/ConfigTest.php
  2. 9 core/modules/config/tests/config_test/src/Entity/ConfigTest.php
  3. 9 core/modules/migrate/tests/src/Unit/destination/ConfigTest.php
  4. 9 core/modules/system/tests/src/Functional/File/ConfigTest.php
  5. 9 core/tests/Drupal/Tests/Composer/Plugin/ProjectMessage/ConfigTest.php
  6. 9 core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/ConfigTest.php
  7. 9 core/tests/Drupal/Tests/Core/Config/ConfigTest.php
  8. 8.9.x core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/d8/ConfigTest.php
  9. 8.9.x core/modules/config/tests/config_test/src/Entity/ConfigTest.php
  10. 8.9.x core/modules/migrate/tests/src/Unit/destination/ConfigTest.php
  11. 8.9.x core/modules/system/tests/src/Functional/File/ConfigTest.php
  12. 8.9.x core/tests/Drupal/Tests/Composer/Plugin/ProjectMessage/ConfigTest.php
  13. 8.9.x core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/ConfigTest.php
  14. 8.9.x core/tests/Drupal/Tests/Core/Config/ConfigTest.php
  15. 10 core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/d8/ConfigTest.php
  16. 10 core/modules/config/tests/config_test/src/Entity/ConfigTest.php
  17. 10 core/modules/migrate/tests/src/Unit/destination/ConfigTest.php
  18. 10 core/modules/system/tests/src/Functional/File/ConfigTest.php
  19. 10 core/tests/Drupal/Tests/Composer/Plugin/ProjectMessage/ConfigTest.php
  20. 10 core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/ConfigTest.php
  21. 10 core/tests/Drupal/Tests/Core/Config/ConfigTest.php

Namespace

Drupal\Tests\Composer\Plugin\ProjectMessage

File

core/tests/Drupal/Tests/Composer/Plugin/ProjectMessage/ConfigTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\Composer\Plugin\ProjectMessage;

use Composer\Package\RootPackageInterface;
use Drupal\Composer\Plugin\ProjectMessage\Message;
use PHPUnit\Framework\TestCase;
use org\bovigo\vfs\vfsStream;

/**
 * @coversDefaultClass Drupal\Composer\Plugin\ProjectMessage\Message
 * @group ProjectMessage
 */
class ConfigTest extends TestCase {
    public static function setUpBeforeClass() : void {
        parent::setUpBeforeClass();
        vfsStream::setup('config_test', NULL, [
            'bespoke' => [
                'special_file.txt' => "Special\nFile",
            ],
        ]);
    }
    public static function provideGetMessageText() {
        return [
            [
                [],
                [],
            ],
            [
                [
                    'Special',
                    'File',
                ],
                [
                    'drupal-core-project-message' => [
                        'event-name-file' => vfsStream::url('config_test/bespoke/special_file.txt'),
                    ],
                ],
            ],
            [
                [
                    'I am the message.',
                ],
                [
                    'drupal-core-project-message' => [
                        'event-name-message' => [
                            'I am the message.',
                        ],
                    ],
                ],
            ],
            [
                [
                    'This message overrides file.',
                ],
                [
                    'drupal-core-project-message' => [
                        'event-name-message' => [
                            'This message overrides file.',
                        ],
                        'event-name-file' => vfsStream::url('config_test/bespoke/special_file.txt'),
                    ],
                ],
            ],
        ];
    }
    
    /**
     * @dataProvider provideGetMessageText
     * @covers ::getText
     */
    public function testGetMessageText($expected, $config) : void {
        // Root package has our config.
        $root = $this->createMock(RootPackageInterface::class);
        $root->expects($this->once())
            ->method('getExtra')
            ->willReturn($config);
        $message = new Message($root, 'event-name');
        $this->assertSame($expected, $message->getText());
    }
    
    /**
     * @covers ::getText
     */
    public function testDefaultFile() : void {
        // Root package has no extra field.
        $root = $this->createMock(RootPackageInterface::class);
        $root->expects($this->once())
            ->method('getExtra')
            ->willReturn([]);
        // The default is to try to read from event-name-message.txt, so we expect
        // config to try that.
        $message = $this->getMockBuilder(Message::class)
            ->setConstructorArgs([
            $root,
            'event-name',
        ])
            ->onlyMethods([
            'getMessageFromFile',
        ])
            ->getMock();
        $message->expects($this->once())
            ->method('getMessageFromFile')
            ->with('event-name-message.txt')
            ->willReturn([]);
        $this->assertSame([], $message->getText());
    }

}

Classes

Title Deprecated Summary
ConfigTest @coversDefaultClass Drupal\Composer\Plugin\ProjectMessage\Message @group ProjectMessage

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