PageRenderTime 242ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/unit/DocBlox/ParserTest.php

http://github.com/mvriel/Docblox
PHP | 133 lines | 62 code | 23 blank | 48 comment | 0 complexity | 031a9c8a82a484abe0766c0029a87b0d MD5 | raw file
Possible License(s): LGPL-3.0, BSD-3-Clause, CC-BY-SA-3.0
  1. <?php
  2. /**
  3. * Test class for DocBlox_Parser.
  4. */
  5. class DocBlox_ParserTest extends PHPUnit_Framework_TestCase
  6. {
  7. /** @var DocBlox_Parser */
  8. protected $fixture = null;
  9. protected function setUp()
  10. {
  11. $this->fixture = new DocBlox_Parser();
  12. }
  13. public function testForced()
  14. {
  15. // defaults to false
  16. $this->assertEquals(false, $this->fixture->isForced());
  17. $xml = new SimpleXMLElement('<project></project>');
  18. $xml->addAttribute('version', DocBlox_Core_Abstract::VERSION);
  19. $this->fixture->setExistingXml($xml->asXML());
  20. $this->assertEquals(false, $this->fixture->isForced());
  21. // if version differs, we force a rebuild
  22. $xml['version'] = DocBlox_Core_Abstract::VERSION.'a';
  23. $this->fixture->setExistingXml($xml->asXML());
  24. $this->assertEquals(true, $this->fixture->isForced());
  25. // switching back should undo the force
  26. $xml['version'] = DocBlox_Core_Abstract::VERSION;
  27. $this->fixture->setExistingXml($xml->asXML());
  28. $this->assertEquals(false, $this->fixture->isForced());
  29. // manually setting forced should result in a force
  30. $this->fixture->setForced(true);
  31. $this->assertEquals(true, $this->fixture->isForced());
  32. $this->fixture->setForced(false);
  33. $this->assertEquals(false, $this->fixture->isForced());
  34. }
  35. public function testValidate()
  36. {
  37. // defaults to false
  38. $this->assertEquals(false, $this->fixture->doValidation());
  39. $this->fixture->setValidate(true);
  40. $this->assertEquals(true, $this->fixture->doValidation());
  41. $this->fixture->setValidate(false);
  42. $this->assertEquals(false, $this->fixture->doValidation());
  43. }
  44. public function testMarkers()
  45. {
  46. $fixture_data = array('FIXME', 'TODO', 'DOIT');
  47. // default is TODO and FIXME
  48. $this->assertEquals(array('TODO', 'FIXME'), $this->fixture->getMarkers());
  49. $this->fixture->setMarkers($fixture_data);
  50. $this->assertEquals($fixture_data, $this->fixture->getMarkers());
  51. }
  52. public function testExistingXml()
  53. {
  54. // default is null
  55. $this->assertEquals(null, $this->fixture->getExistingXml());
  56. $this->fixture->setExistingXml('<?xml version="1.0" ?><project version="1.0"></project>');
  57. $this->assertInstanceOf('DOMDocument', $this->fixture->getExistingXml());
  58. $this->assertEquals('1.0', $this->fixture->getExistingXml()->documentElement->getAttribute('version'));
  59. }
  60. // TODO: move this to a unit test for DocBlox_Parser_Files
  61. // public function testIgnorePatterns()
  62. // {
  63. // $fixture_data = '*/test/*';
  64. // $fixture_data2 = '*/test?/*';
  65. // $result_data = '.*\/test\/.*';
  66. // $result_data2 = '.*\/test.\/.*';
  67. //
  68. // // default is empty
  69. // $this->assertEquals(array(), $this->fixture->getIgnorePatterns());
  70. //
  71. // // test adding a normal glob with asterisks on both sides
  72. // $this->fixture->addIgnorePattern($fixture_data);
  73. // $this->assertEquals(array($result_data), $this->fixture->getIgnorePatterns());
  74. //
  75. // // what happens if we add another one with a question mark?
  76. // $this->fixture->addIgnorePattern($fixture_data2);
  77. // $this->assertEquals(array($result_data, $result_data2), $this->fixture->getIgnorePatterns());
  78. //
  79. // // what happens if we set all to an empty array
  80. // $this->fixture->setIgnorePatterns(array());
  81. // $this->assertEquals(array(), $this->fixture->getIgnorePatterns());
  82. //
  83. // // what happens if we set both patterns using the setIgnorePatterns method
  84. // $this->fixture->setIgnorePatterns(array($fixture_data, $fixture_data2));
  85. // $this->assertEquals(array($result_data, $result_data2), $this->fixture->getIgnorePatterns());
  86. // }
  87. public function testPathHandling()
  88. {
  89. // default is only stripping the opening slash
  90. $this->assertEquals(ltrim(__FILE__, '/'), $this->fixture->getRelativeFilename(__FILE__));
  91. // after setting the current directory as root folder; should strip all but filename
  92. $this->fixture->setPath(dirname(__FILE__));
  93. $this->assertEquals(basename(__FILE__), $this->fixture->getRelativeFilename(__FILE__));
  94. // when providing a file in a lower directory it cannot parse and thus it is invalid
  95. $this->setExpectedException('InvalidArgumentException');
  96. $this->fixture->getRelativeFilename(realpath(dirname(__FILE__).'/../phpunit.xml'));
  97. }
  98. /**
  99. * Make sure the setter can transform string to array and set correct attribute
  100. *
  101. * @covers DocBlox_Parser::setVisibility
  102. *
  103. * @return void
  104. */
  105. public function testSetVisibilityCorrectlySetsAttribute()
  106. {
  107. $this->fixture->setVisibility('public,protected,private');
  108. $this->assertAttributeEquals(array('public', 'protected', 'private'), 'visibility', $this->fixture);
  109. }
  110. }