You are here

class ProjectUnitTest in Coder 8.2

Tests that project and version detection works.

Hierarchy

  • class \DrupalPractice\ProjectDetection\ProjectUnitTest extends \DrupalPractice\ProjectDetection\PHPUnit_Framework_TestCase

Expanded class hierarchy of ProjectUnitTest

File

coder_sniffer/DrupalPractice/Test/ProjectDetection/ProjectUnitTest.php, line 10

Namespace

DrupalPractice\ProjectDetection
View source
class ProjectUnitTest extends \PHPUnit_Framework_TestCase {

  /**
   * The mocked file object for testing.
   *
   * @var PHP_CodeSniffer_File|PHPUnit_Framework_MockObject_MockObject
   */
  protected $phpcsFile;

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp();
    $this->phpcsFile = $this
      ->getMockBuilder('PHP_CodeSniffer_File')
      ->disableOriginalConstructor()
      ->getMock();
  }

  /**
   * Tests the extending classes Sniff class.
   */
  public function testInfoFileDetection() {

    // @see https://www.drupal.org/project/coder/issues/2962880
    $this
      ->markTestIncomplete('This test relies on code that has been removed in PHP_CodeSniffer 3.x.');
    $this->phpcsFile
      ->expects($this
      ->any())
      ->method('getFilename')
      ->will($this
      ->returnValue(dirname(__FILE__) . '/modules/drupal6/test.php'));
    $this
      ->assertEquals(Project::getInfoFile($this->phpcsFile), dirname(__FILE__) . '/modules/drupal6/testmodule.info');
  }

  /**
   * Tests the extending classes Sniff class.
   */
  public function testInfoFileNestedDetection() {

    // @see https://www.drupal.org/project/coder/issues/2962880
    $this
      ->markTestIncomplete('This test relies on code that has been removed in PHP_CodeSniffer 3.x.');
    $this->phpcsFile
      ->expects($this
      ->any())
      ->method('getFilename')
      ->will($this
      ->returnValue(dirname(__FILE__) . '/modules/drupal6/nested/test.php'));
    $this
      ->assertEquals(Project::getInfoFile($this->phpcsFile), dirname(__FILE__) . '/modules/drupal6/testmodule.info');
  }

  /**
   * Tests the extending classes Sniff class.
   *
   * @dataProvider coreVersionProvider
   */
  public function testCoreVersion($filename, $core_version) {

    // @see https://www.drupal.org/project/coder/issues/2962880
    $this
      ->markTestIncomplete('This test relies on code that has been removed in PHP_CodeSniffer 3.x.');
    $this->phpcsFile
      ->expects($this
      ->any())
      ->method('getFilename')
      ->will($this
      ->returnValue($filename));
    $this
      ->assertEquals(Project::getCoreVersion($this->phpcsFile), $core_version);
  }

  /**
   * Data provider for testCoreVersion().
   */
  public function coreVersionProvider() {
    return array(
      array(
        dirname(__FILE__) . '/modules/drupal6/nested/test.php',
        '6.x',
      ),
      array(
        dirname(__FILE__) . '/modules/drupal7/test.php',
        '7.x',
      ),
      array(
        dirname(__FILE__) . '/modules/drupal8/test.php',
        '8.x',
      ),
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ProjectUnitTest::$phpcsFile protected property The mocked file object for testing.
ProjectUnitTest::coreVersionProvider public function Data provider for testCoreVersion().
ProjectUnitTest::setUp public function
ProjectUnitTest::testCoreVersion public function Tests the extending classes Sniff class.
ProjectUnitTest::testInfoFileDetection public function Tests the extending classes Sniff class.
ProjectUnitTest::testInfoFileNestedDetection public function Tests the extending classes Sniff class.