RequirementsCheckerTest

The Yoast SEO RequirementsCheckerTest class.

Defined (1)

The class is defined in the following location(s).

/vendor/yoast/whip/tests/RequirementsCheckerTest.php  
  1. class RequirementsCheckerTest extends PHPUnit_Framework_TestCase { 
  2.  
  3. public function testItReceivesAUsableRequirementObject() { 
  4. $checker = new Whip_RequirementsChecker(); 
  5. $checker->addRequirement( new Whip_VersionRequirement( 'php', '5.2' ) ); 
  6.  
  7. $this->assertTrue( $checker->hasRequirements() ); 
  8. $this->assertEquals( 1, $checker->totalRequirements() ); 
  9.  
  10. /** 
  11. * @requires PHP 7 
  12. */ 
  13. public function testItThrowsAnTypeErrorWhenInvalidRequirementIsPassed() { 
  14. if ( version_compare( phpversion(), 7.0, '<' ) ) { 
  15. $this->markTestSkipped( 'Skipped due to incompatible PHP version.' ); 
  16.  
  17. $exceptionCaught = false; 
  18.  
  19. $checker = new Whip_RequirementsChecker(); 
  20.  
  21. try { 
  22. $checker->addRequirement( new stdClass() ); 
  23. } catch( Error $e ) { 
  24. $exceptionCaught = true; 
  25.  
  26. $this->assertTrue( $exceptionCaught ); 
  27.  
  28. public function testItThrowsAnTypeErrorWhenInvalidRequirementIsPassedInPHP5() { 
  29. if ( version_compare( phpversion(), 7.0, '>=' ) ) { 
  30. $this->markTestSkipped(); 
  31.  
  32. $exceptionCaught = false; 
  33.  
  34. $checker = new Whip_RequirementsChecker(); 
  35.  
  36. try { 
  37. $checker->addRequirement( new stdClass() ); 
  38. } catch( Exception $e ) { 
  39. $exceptionCaught = true; 
  40.  
  41. $this->assertTrue( $exceptionCaught ); 
  42.  
  43. public function testItOnlyContainsUniqueComponents() { 
  44. $checker = new Whip_RequirementsChecker(); 
  45.  
  46. $checker->addRequirement( new Whip_VersionRequirement( 'php', '5.2' ) ); 
  47. $checker->addRequirement( new Whip_VersionRequirement( 'mysql', '5.6' ) ); 
  48.  
  49. $this->assertTrue( $checker->hasRequirements() ); 
  50. $this->assertEquals( 2, $checker->totalRequirements() ); 
  51.  
  52. $checker->addRequirement( new Whip_VersionRequirement( 'php', '6' ) ); 
  53.  
  54. $this->assertEquals( 2, $checker->totalRequirements() ); 
  55.  
  56. public function testIfRequirementExists() { 
  57. $checker = new Whip_RequirementsChecker(); 
  58.  
  59. $checker->addRequirement( new Whip_VersionRequirement( 'php', '5.2' ) ); 
  60. $checker->addRequirement( new Whip_VersionRequirement( 'mysql', '5.6' ) ); 
  61.  
  62. $this->assertTrue( $checker->requirementExistsForComponent( 'php' ) ); 
  63. $this->assertFalse( $checker->requirementExistsForComponent( 'mongodb' ) ); 
  64.  
  65. public function testCheckIfRequirementIsFulfilled() { 
  66. $checker = new Whip_RequirementsChecker( array( 'php' => phpversion() ) ); 
  67.  
  68. $checker->addRequirement( new Whip_VersionRequirement( 'php', '5.2' ) ); 
  69. $checker->check(); 
  70.  
  71. $this->assertEmpty( $checker->getMostRecentMessage()->body() ); 
  72.  
  73. public function testCheckIfPHPRequirementIsNotFulfilled() { 
  74. $checker = new Whip_RequirementsChecker( array( 'php' => 4 ) ); 
  75.  
  76. $checker->addRequirement( new Whip_VersionRequirement( 'php', '5.6' ) ); 
  77. $checker->check(); 
  78.  
  79. $this->assertTrue( $checker->hasMessages() ); 
  80.  
  81. // Get the message. This will unset the global. 
  82. $recentMessage = $checker->getMostRecentMessage(); 
  83.  
  84. $this->assertNotEmpty( $recentMessage ); 
  85. $this->assertInternalType( 'string', $recentMessage->body() ); 
  86. $this->assertFalse( $checker->hasMessages() ); 
  87. $this->assertInstanceOf( 'Whip_UpgradePhpMessage', $recentMessage ); 
  88.  
  89. public function testCheckIfRequirementIsNotFulfilled() { 
  90. $checker = new Whip_RequirementsChecker( array( 'mysql' => 4 ) ); 
  91.  
  92. $checker->addRequirement( new Whip_VersionRequirement( 'mysql', '5.6' ) ); 
  93. $checker->check(); 
  94.  
  95. $this->assertTrue( $checker->hasMessages() ); 
  96.  
  97. // Get the message. This will unset the global. 
  98. $recentMessage = $checker->getMostRecentMessage(); 
  99.  
  100. $this->assertNotEmpty( $recentMessage ); 
  101. $this->assertFalse( $checker->hasMessages() ); 
  102. $this->assertInstanceOf( 'Whip_InvalidVersionRequirementMessage', $recentMessage ); 
  103. $this->assertStringStartsWith( 'Invalid version detected', $recentMessage->body() ); 
  104.  
  105. public function testCheckIfRequirementIsFulfilledWithSpecificComparison() { 
  106. $checker = new Whip_RequirementsChecker( array( 'php' => 4 ) ); 
  107.  
  108. $checker->addRequirement( new Whip_VersionRequirement( 'php', '5.2', '<' ) ); 
  109. $checker->check(); 
  110.  
  111. $this->assertFalse( $checker->hasMessages() ); 
  112.  
  113. public function testCheckIfRequirementIsNotFulfilledWithSpecificComparison() { 
  114. $checker = new Whip_RequirementsChecker( array( 'php' => 4 ) ); 
  115.  
  116. $checker->addRequirement( new Whip_VersionRequirement( 'php', '5.2', '>=' ) ); 
  117. $checker->check(); 
  118.  
  119. $this->assertTrue( $checker->hasMessages() );