You are here

class PluginHandlerTest in Database Sanitize 7

Tests for EdisonLabs\MergeYaml\PluginHandler

Hierarchy

  • class \EdisonLabs\MergeYaml\Unit\PluginHandlerTest extends \PHPUnit\Framework\TestCase

Expanded class hierarchy of PluginHandlerTest

File

vendor/edisonlabs/merge-yaml/tests/src/Unit/PluginHandlerTest.php, line 12

Namespace

EdisonLabs\MergeYaml\Unit
View source
class PluginHandlerTest extends TestCase {

  /**
   * A valid composer configuration for the plugin.
   *
   * @var array
   */
  protected $defaultConfig;

  /**
   * @var \PHPUnit_Framework_MockObject_MockObject
   */
  protected $io;

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    $this->defaultConfig = [
      'files' => [
        'test',
      ],
      'locations' => [
        dirname(__FILE__) . '/../../assets',
      ],
      'output-dir' => '/tmp/merge-yaml',
    ];
    $this->io = $this
      ->getMockBuilder('Composer\\IO\\IOInterface')
      ->getMock();
  }

  /**
   * {@inheritdoc}
   */
  protected function tearDown() {
    $file = '/tmp/merge-yaml/test.merge.yml';
    if (file_exists($file)) {
      unlink($file);
    }
  }

  /**
   * Tests setting up the plugin correctly.
   */
  public function testPlugin() {
    $mergeYaml = new PluginHandler(new Composer(), $this->io, $this->defaultConfig);
    $this
      ->assertEquals($this->defaultConfig['files'], $mergeYaml->fileNamePatterns);
    $this
      ->assertEquals($this->defaultConfig['locations'], $mergeYaml->sourcePaths);
    $this
      ->assertEquals($this->defaultConfig['output-dir'], $mergeYaml->outputDir);
    $this
      ->assertTrue($mergeYaml->isConfigured);
    $mergeYaml
      ->createMergeFiles();
    $this
      ->assertFileExists('/tmp/merge-yaml/test.merge.yml');
  }

  /**
   * Tests the plugin with missing files configuration.
   */
  public function testMissingFilesConfiguration() {
    $configParameters = $this->defaultConfig;
    unset($configParameters['files']);
    $this
      ->expectException(\RuntimeException::class);
    $mergeYaml = new PluginHandler(new Composer(), $this->io, $configParameters);
  }

  /**
   * Tests the plugin with missing locations configuration.
   */
  public function testMissingLocationsConfiguration() {
    $configParameters = $this->defaultConfig;
    unset($configParameters['locations']);
    $this
      ->expectException(\RuntimeException::class);
    $mergeYaml = new PluginHandler(new Composer(), $this->io, $configParameters);
  }

  /**
   * Tests the plugin with missing output-dir configuration.
   */
  public function testMissingOuptutDirConfiguration() {
    $configParameters = $this->defaultConfig;
    unset($configParameters['output-dir']);
    $this
      ->expectException(\RuntimeException::class);
    $mergeYaml = new PluginHandler(new Composer(), $this->io, $configParameters);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PluginHandlerTest::$defaultConfig protected property A valid composer configuration for the plugin.
PluginHandlerTest::$io protected property
PluginHandlerTest::setUp protected function
PluginHandlerTest::tearDown protected function
PluginHandlerTest::testMissingFilesConfiguration public function Tests the plugin with missing files configuration.
PluginHandlerTest::testMissingLocationsConfiguration public function Tests the plugin with missing locations configuration.
PluginHandlerTest::testMissingOuptutDirConfiguration public function Tests the plugin with missing output-dir configuration.
PluginHandlerTest::testPlugin public function Tests setting up the plugin correctly.