You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dependencyanalyzer.php 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * @author Thomas Müller
  4. * @copyright 2014 Thomas Müller deepdiver@owncloud.com
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace Test\App;
  9. use OC;
  10. use OC\App\Platform;
  11. use OCP\IL10N;
  12. class DependencyAnalyzer extends \PHPUnit_Framework_TestCase {
  13. /**
  14. * @var Platform
  15. */
  16. private $platformMock;
  17. /**
  18. * @var IL10N
  19. */
  20. private $l10nMock;
  21. public function setUp() {
  22. $this->platformMock = $this->getMockBuilder('\OC\App\Platform')
  23. ->disableOriginalConstructor()
  24. ->getMock();
  25. $this->platformMock->expects($this->any())
  26. ->method('getPhpVersion')
  27. ->will( $this->returnValue('5.4.3'));
  28. $this->platformMock->expects($this->any())
  29. ->method('getDatabase')
  30. ->will( $this->returnValue('mysql'));
  31. $this->l10nMock = $this->getMockBuilder('\OCP\IL10N')
  32. ->disableOriginalConstructor()
  33. ->getMock();
  34. $this->l10nMock->expects($this->any())
  35. ->method('t')
  36. ->will($this->returnCallback(function($text, $parameters = array()) {
  37. return vsprintf($text, $parameters);
  38. }));
  39. }
  40. /**
  41. * @dataProvider providesPhpVersion
  42. */
  43. public function testPhpVersion($expectedMissing, $minVersion, $maxVersion) {
  44. $app = array(
  45. 'dependencies' => array(
  46. 'php' => array()
  47. )
  48. );
  49. if (!is_null($minVersion)) {
  50. $app['dependencies']['php']['@attributes']['min-version'] = $minVersion;
  51. }
  52. if (!is_null($maxVersion)) {
  53. $app['dependencies']['php']['@attributes']['max-version'] = $maxVersion;
  54. }
  55. $analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock);
  56. $missing = $analyser->analyze();
  57. $this->assertTrue(is_array($missing));
  58. $this->assertEquals(count($expectedMissing), count($missing));
  59. $this->assertEquals($expectedMissing, $missing);
  60. }
  61. /**
  62. * @dataProvider providesDatabases
  63. */
  64. public function testDatabases($expectedMissing, $databases) {
  65. $app = array(
  66. 'dependencies' => array(
  67. )
  68. );
  69. if (!is_null($databases)) {
  70. $app['dependencies']['database'] = $databases;
  71. }
  72. $analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock);
  73. $missing = $analyser->analyze();
  74. $this->assertTrue(is_array($missing));
  75. $this->assertEquals(count($expectedMissing), count($missing));
  76. $this->assertEquals($expectedMissing, $missing);
  77. }
  78. function providesDatabases() {
  79. return array(
  80. // non BC - in case on databases are defined -> all are supported
  81. array(array(), null),
  82. array(array(), array()),
  83. array(array('Following databases are supported: sqlite, postgres'), array('sqlite', array('@value' => 'postgres'))),
  84. );
  85. }
  86. function providesPhpVersion() {
  87. return array(
  88. array(array(), null, null),
  89. array(array(), '5.4', null),
  90. array(array(), null, '5.5'),
  91. array(array(), '5.4', '5.5'),
  92. array(array('PHP 5.4.4 or higher is required.'), '5.4.4', null),
  93. array(array('PHP with a version less then 5.4.2 is required.'), null, '5.4.2'),
  94. );
  95. }
  96. }