1: <?php
2:
3: /**
4: * Jyxo PHP Library
5: *
6: * LICENSE
7: *
8: * This source file is subject to the new BSD license that is bundled
9: * with this package in the file license.txt.
10: * It is also available through the world-wide-web at this URL:
11: * https://github.com/jyxo/php/blob/master/license.txt
12: */
13:
14: namespace Jyxo\Beholder\TestCase;
15:
16: /**
17: * Tests the current PHP version.
18: *
19: * @category Jyxo
20: * @package Jyxo\Beholder
21: * @copyright Copyright (c) 2005-2011 Jyxo, s.r.o.
22: * @license https://github.com/jyxo/php/blob/master/license.txt
23: * @author Jaroslav HanslĂk
24: */
25: class PhpVersion extends \Jyxo\Beholder\TestCase
26: {
27: /**
28: * Required version.
29: *
30: * @var string
31: */
32: private $version;
33:
34: /**
35: * Optional extension test.
36: *
37: * @var string
38: */
39: private $extension;
40:
41: /**
42: * Comparison type.
43: *
44: * @var string
45: */
46: private $comparison;
47:
48: /**
49: * Constructor.
50: *
51: * @param string $description Test description
52: * @param string $version Required version
53: * @param string $extension Optional extension name
54: * @param string $comparison Comparison operator for version_compare. >= means "the actual version must be greater or equal to the expected"
55: */
56: public function __construct($description, $version, $extension = '', $comparison = '=')
57: {
58: parent::__construct($description);
59:
60: $this->version = (string) $version;
61: $this->extension = (string) $extension;
62: $this->comparison = (string) $comparison;
63: }
64:
65: /**
66: * Performs the test.
67: *
68: * @return \Jyxo\Beholder\Result
69: */
70: public function run()
71: {
72: // If we test extensions they have to be installed
73: if ((!empty($this->extension)) && (!extension_loaded($this->extension))) {
74: return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::NOT_APPLICABLE, sprintf('Extension %s missing', $this->extension));
75: }
76:
77: // Current version
78: $actual = !empty($this->extension) ? phpversion($this->extension) : phpversion();
79:
80: // Version comparison
81: if (true !== version_compare($actual, $this->version, $this->comparison)) {
82: return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, sprintf('Version %s, expected %s %s', $actual, $this->comparison, $this->version));
83: }
84:
85: // OK
86: return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::SUCCESS, sprintf('Version %s', $actual));
87: }
88: }
89: