VersionRequirementTest

The Yoast SEO VersionRequirementTest class.

Defined (1)

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

/vendor/yoast/whip/tests/VersionRequirementTest.php  
  1. class VersionRequirementTest extends PHPUnit_Framework_TestCase { 
  2. public function testNameAndVersionAreNotEmpty() { 
  3. $requirement = new Whip_VersionRequirement( 'php', '5.2' ); 
  4.  
  5. $this->assertNotEmpty($requirement->component()); 
  6. $this->assertNotEmpty($requirement->version()); 
  7.  
  8. /** 
  9. * @expectedException Whip_EmptyProperty 
  10. */ 
  11. public function testComponentCannotBeEmpty() { 
  12. new Whip_VersionRequirement( '', '5.2' ); 
  13.  
  14. /** 
  15. * @expectedException Whip_EmptyProperty 
  16. */ 
  17. public function testVersionCannotBeEmpty() { 
  18. new Whip_VersionRequirement( 'php', '' ); 
  19.  
  20. /** 
  21. * @expectedException Whip_InvalidType 
  22. */ 
  23. public function testComponentMustBeString() { 
  24. new Whip_VersionRequirement( 123, '5.2' ); 
  25.  
  26. /** 
  27. * @expectedException Whip_InvalidType 
  28. */ 
  29. public function testVersionMustBeString() { 
  30. new Whip_VersionRequirement( 'php', 123 ); 
  31.  
  32. /** 
  33. * @expectedException Whip_EmptyProperty 
  34. */ 
  35. public function testOperatorCannotBeEmpty() { 
  36. new Whip_VersionRequirement( 'php', '5.6', '' ); 
  37.  
  38. /** 
  39. * @expectedException Whip_InvalidType 
  40. */ 
  41. public function testOperatorMustBeString() { 
  42. new Whip_VersionRequirement( 'php', '5.2', 6 ); 
  43.  
  44. /** 
  45. * @expectedException Whip_InvalidOperatorType 
  46. */ 
  47. public function testOperatorMustBeValid() { 
  48. new Whip_VersionRequirement( 'php', '5.2', '->' ); 
  49.  
  50. public function testGettingComponentProperties() { 
  51. $requirement = new Whip_VersionRequirement( 'php', '5.6' ); 
  52.  
  53. $this->assertEquals( 'php', $requirement->component() ); 
  54. $this->assertEquals( '5.6', $requirement->version() ); 
  55. $this->assertEquals( '=', $requirement->operator() ); 
  56.  
  57. /** 
  58. * @dataProvider dataFromCompareString 
  59. */ 
  60. public function testFromCompareString( $expectation, $component, $compareString ) { 
  61. $requirement = Whip_VersionRequirement::fromCompareString( $component, $compareString ); 
  62.  
  63. $this->assertEquals( $expectation[0], $requirement->component() ); 
  64. $this->assertEquals( $expectation[1], $requirement->version() ); 
  65. $this->assertEquals( $expectation[2], $requirement->operator() ); 
  66.  
  67. public function dataFromCompareString() { 
  68. return array( 
  69. array( array( 'php', '5.5', '>' ), 'php', '>5.5' ),  
  70. array( array( 'php', '5.5', '>=' ), 'php', '>=5.5' ),  
  71. array( array( 'php', '5.5', '<' ), 'php', '<5.5' ),  
  72. array( array( 'php', '5.5', '<=' ), 'php', '<=5.5' ),  
  73. array( array( 'php', '7.3', '>' ), 'php', '>7.3' ),  
  74. array( array( 'php', '7.3', '>=' ), 'php', '>=7.3' ),  
  75. array( array( 'php', '7.3', '<' ), 'php', '<7.3' ),  
  76. array( array( 'php', '7.3', '<=' ), 'php', '<=7.3' ),  
  77. ); 
  78.  
  79. /** 
  80. * @expectedException Whip_InvalidVersionComparisonString 
  81. */ 
  82. public function testFromCompareStringException() { 
  83. Whip_VersionRequirement::fromCompareString( 'php', '> 2.3' );