Docblox /tests/unit/DocBlox/ParserTest.php

Language PHP Lines 133
MD5 Hash 031a9c8a82a484abe0766c0029a87b0d Estimated Cost $1,408 (why?)
Repository git://github.com/mvriel/Docblox.git View Raw File View Project SPDX
  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
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php

/**
* Test class for DocBlox_Parser.
*/
class DocBlox_ParserTest extends PHPUnit_Framework_TestCase
{
  /** @var DocBlox_Parser */
  protected $fixture = null;

  protected function setUp()
  {
    $this->fixture = new DocBlox_Parser();
  }

  public function testForced()
  {
    // defaults to false
    $this->assertEquals(false, $this->fixture->isForced());

    $xml = new SimpleXMLElement('<project></project>');
    $xml->addAttribute('version', DocBlox_Core_Abstract::VERSION);

    $this->fixture->setExistingXml($xml->asXML());
    $this->assertEquals(false, $this->fixture->isForced());

    // if version differs, we force a rebuild
    $xml['version'] = DocBlox_Core_Abstract::VERSION.'a';
    $this->fixture->setExistingXml($xml->asXML());
    $this->assertEquals(true, $this->fixture->isForced());

    // switching back should undo the force
    $xml['version'] = DocBlox_Core_Abstract::VERSION;
    $this->fixture->setExistingXml($xml->asXML());
    $this->assertEquals(false, $this->fixture->isForced());

    // manually setting forced should result in a force
    $this->fixture->setForced(true);
    $this->assertEquals(true, $this->fixture->isForced());

    $this->fixture->setForced(false);
    $this->assertEquals(false, $this->fixture->isForced());
  }

  public function testValidate()
  {
    // defaults to false
    $this->assertEquals(false, $this->fixture->doValidation());

    $this->fixture->setValidate(true);
    $this->assertEquals(true, $this->fixture->doValidation());

    $this->fixture->setValidate(false);
    $this->assertEquals(false, $this->fixture->doValidation());
  }

  public function testMarkers()
  {
    $fixture_data = array('FIXME', 'TODO', 'DOIT');

    // default is TODO and FIXME
    $this->assertEquals(array('TODO', 'FIXME'), $this->fixture->getMarkers());

    $this->fixture->setMarkers($fixture_data);
    $this->assertEquals($fixture_data, $this->fixture->getMarkers());
  }

  public function testExistingXml()
  {
    // default is null
    $this->assertEquals(null, $this->fixture->getExistingXml());

    $this->fixture->setExistingXml('<?xml version="1.0" ?><project version="1.0"></project>');
    $this->assertInstanceOf('DOMDocument', $this->fixture->getExistingXml());
    $this->assertEquals('1.0', $this->fixture->getExistingXml()->documentElement->getAttribute('version'));
  }

// TODO: move this to a unit test for DocBlox_Parser_Files
//  public function testIgnorePatterns()
//  {
//    $fixture_data = '*/test/*';
//    $fixture_data2 = '*/test?/*';
//    $result_data = '.*\/test\/.*';
//    $result_data2 = '.*\/test.\/.*';
//
//    // default is empty
//    $this->assertEquals(array(), $this->fixture->getIgnorePatterns());
//
//    // test adding a normal glob with asterisks on both sides
//    $this->fixture->addIgnorePattern($fixture_data);
//    $this->assertEquals(array($result_data), $this->fixture->getIgnorePatterns());
//
//    // what happens if we add another one with a question mark?
//    $this->fixture->addIgnorePattern($fixture_data2);
//    $this->assertEquals(array($result_data, $result_data2), $this->fixture->getIgnorePatterns());
//
//    // what happens if we set all to an empty array
//    $this->fixture->setIgnorePatterns(array());
//    $this->assertEquals(array(), $this->fixture->getIgnorePatterns());
//
//    // what happens if we set both patterns using the setIgnorePatterns method
//    $this->fixture->setIgnorePatterns(array($fixture_data, $fixture_data2));
//    $this->assertEquals(array($result_data, $result_data2), $this->fixture->getIgnorePatterns());
//  }

  public function testPathHandling()
  {
    // default is only stripping the opening slash
    $this->assertEquals(ltrim(__FILE__, '/'), $this->fixture->getRelativeFilename(__FILE__));

    // after setting the current directory as root folder; should strip all but filename
    $this->fixture->setPath(dirname(__FILE__));
    $this->assertEquals(basename(__FILE__), $this->fixture->getRelativeFilename(__FILE__));

    // when providing a file in a lower directory it cannot parse and thus it is invalid
    $this->setExpectedException('InvalidArgumentException');
    $this->fixture->getRelativeFilename(realpath(dirname(__FILE__).'/../phpunit.xml'));
  }

  /**
   * Make sure the setter can transform string to array and set correct attribute
   *
   * @covers DocBlox_Parser::setVisibility
   *
   * @return void
   */
  public function testSetVisibilityCorrectlySetsAttribute()
  {
      $this->fixture->setVisibility('public,protected,private');
      $this->assertAttributeEquals(array('public', 'protected', 'private'), 'visibility', $this->fixture);
  }

}
Back to Top