RequirementsExceptionTest.php 1.55 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
<?php

/**
 * @file
 * Contains \Drupal\Tests\migrate\Unit\Exception\RequirementsExceptionTest.
 */

namespace Drupal\Tests\migrate\Unit\Exception;

use Drupal\migrate\Exception\RequirementsException;
use Drupal\Tests\UnitTestCase;

/**
 * @coversDefaultClass \Drupal\migrate\Exception\RequirementsException
 * @group migration
 */
class RequirementsExceptionTest extends UnitTestCase {

  protected $missingRequirements = ['random_jackson_pivot', '51_Eridani_b'];

  /**
   * @covers ::getRequirements
   */
  public function testGetRequirements() {
    $exception = new RequirementsException('Missing requirements ', ['requirements' => $this->missingRequirements]);
    $this->assertArrayEquals(['requirements' => $this->missingRequirements], $exception->getRequirements());
  }

  /**
   * @covers ::getRequirementsString
   * @dataProvider getRequirementsProvider
   */
  public function testGetExceptionString($expected, $message, $requirements) {
    $exception = new RequirementsException($message, $requirements);
    $this->assertEquals($expected, $exception->getRequirementsString());
  }

  /**
   * Provides a list of requirements to test.
   */
  public function getRequirementsProvider() {
    return array(
      array(
        'requirements: random_jackson_pivot.',
        'Single Requirement',
        array('requirements' => $this->missingRequirements[0]),
      ),
      array(
        'requirements: random_jackson_pivot. requirements: 51_Eridani_b.',
        'Multiple Requirements',
        array('requirements' => $this->missingRequirements),
      ),
    );
  }
}