Skip to content

Commit

Permalink
Add methods to return PHP version info
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorbrandao committed Nov 8, 2014
1 parent ed0045b commit 6b70803
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 14 deletions.
85 changes: 79 additions & 6 deletions src/Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ public function getSystemAlias($system, $release, $version)
// Modify release (marketing release = SunOS release - 3)
$l = explode('.', $release);
if ($l) {
$major = (int)$l[0] - 3;
$l[0] = (string)$major;
$major = (int) $l[0] - 3;
$l[0] = (string) $major;
$release = implode('.', $l);
if ($release < '6') {
$system = 'Solaris';
Expand All @@ -306,16 +306,89 @@ public function getSystemAlias($system, $release, $version)
} else {
$version = '64bit';
}
}

elseif (in_array($system, array('win32', 'win16'))) {
} elseif (in_array($system, array('win32', 'win16'))) {
// In case one of the other tricks
$system = 'Windows';
}

return array('system' => $system, 'release' => $release, 'version' => $version);
}

/**
* Returns he current PHP version as a string in "major.minor.release[extra]" notation.
*
* @return string
*/
public function getPhpVersion()
{
return PHP_VERSION;
}

/**
* Returns the PHP version as associative array ("major", "minor", "release") of strings.
*
* For compatibility with Python's implementation a "patchlevel" field is also returned, containing the same level
* of "release".
*
* @return array
*/
public function getPhpVersionArray()
{
return array(
'major' => PHP_MAJOR_VERSION,
'minor' => PHP_MINOR_VERSION,
'release' => PHP_RELEASE_VERSION,
'patchlevel' => PHP_RELEASE_VERSION
);
}

/**
* Returns a string identifying the PHP implementation branch.
*
* If not available, an empty string is returned.
*
* @return string
*/
public function getPhpBranch()
{
return '';
}

/**
* Returns a string identifying the PHP implementation revision.
*
* If not available, an empty string is returned.
*
* @return string
*/
public function getPhpRevision()
{
return '';
}

/**
* Returns an associative array ("buildno", "builddate") stating the PHP build number and date as strings.
*
* @return array
*/
public function getPhpBuild()
{
return array(
'buildno' => '',
'builddate' => ''
);
}

/**
* Returns a string identifying the compiler used for compiling PHP.
*
* @return string
*/
public function getPhpCompiler()
{
return '';
}

/**
* Allows Python-style method naming. Platform::version() gets converted into Platform::getVersion().
*
Expand All @@ -324,7 +397,7 @@ public function getSystemAlias($system, $release, $version)
*/
public function __call($name, $arguments)
{
$method = 'get' . ucfirst($name);
$method = 'get' . ucfirst(preg_replace('/_(.?)/e', "strtoupper('$1')", $name));
if (method_exists($this, $method)) {
return call_user_func_array(array($this, $method), $arguments);
}
Expand Down
2 changes: 1 addition & 1 deletion src/PlatformCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln(' <comment>Machine:</comment> '.$platform->getMachine());
$output->writeln('<comment>Processor:</comment> '.$platform->getProcessor());

$platform->getLinuxDistribution();
$platform->getPhpBuild();
}
}
52 changes: 45 additions & 7 deletions tests/PlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@

class PlatformTest extends \PHPUnit_Framework_TestCase
{
public function createPlatform()
{
return new Platform();
}

public function testGetArchitecture()
{
$platform = new Platform();
$architecture = $platform->getArchitecture();
$architecture = $this->createPlatform()->getArchitecture();

foreach (array('bits', 'linkage') as $key) {
$this->assertArrayHasKey($key, $architecture);
Expand All @@ -41,8 +45,7 @@ public function testGetArchitecture()

public function testGetUname()
{
$platform = new Platform();
$uname = $platform->getUname();
$uname = $this->createPlatform()->getUname();

foreach (array('system', 'node', 'release', 'version', 'machine', 'processor') as $key) {
$this->assertArrayHasKey($key, $uname);
Expand All @@ -51,11 +54,46 @@ public function testGetUname()

public function testGetSystemAlias()
{
$platform = new Platform();

$alias = $platform->getSystemAlias('Rhapsody', 'Mac OS X Server 1.0', '');
$alias = $this->createPlatform()->getSystemAlias('Rhapsody', 'Mac OS X Server 1.0', '');
foreach (array('system', 'release', 'version') as $key) {
$this->assertArrayHasKey($key, $alias);
}
}
}

public function testGetPhpVersion()
{
$this->assertInternalType('string', $this->createPlatform()->getPhpVersion());
}

public function testGetPhpVersionArray()
{
$phpVersion = $this->createPlatform()->getPhpVersionArray();
foreach (array('major', 'minor', 'patchlevel') as $key) {
$this->assertArrayHasKey($key, $phpVersion);
}
}

public function testGetPhpBranch()
{
$this->assertInternalType('string', $this->createPlatform()->getPhpBranch());
}

public function testGetPhpRevision()
{
$this->assertInternalType('string', $this->createPlatform()->getPhpRevision());
}

public function testGetPhpBuild()
{
$phpBuild = $this->createPlatform()->getPhpBuild();
foreach (array('buildno', 'builddate') as $key) {
$this->assertArrayHasKey($key, $phpBuild);
}
}

public function testGetPhpCompiler()
{
$this->assertInternalType('string', $this->createPlatform()->getPhpCompiler());
}
}

0 comments on commit 6b70803

Please sign in to comment.