/** * @expectedException \Exception * @expectedExceptionMessage Missing key 'platform=>php' in 'composer.lock' file */ public function testGetRequiredPhpVersionExceptionMissingKey() { $this->directoryReadMock->expects($this->once())->method('isExist')->will($this->returnValue(true)); $this->directoryReadMock->expects($this->once())->method('readFile')->with('composer.lock')->will($this->returnValue('{}')); $phpInfo = new PhpInformation($this->filesystemMock); $phpInfo->getRequiredPhpVersion(); }
/** * Verifies php version * * @return JsonModel */ public function phpVersionAction() { try { $requiredVersion = $this->phpInformation->getRequiredPhpVersion(); } catch (\Exception $e) { return new JsonModel(['responseType' => ResponseTypeInterface::RESPONSE_TYPE_ERROR, 'data' => ['error' => 'phpVersionError', 'message' => 'Cannot determine required PHP version: ' . $e->getMessage()]]); } $multipleConstraints = $this->versionParser->parseConstraints($requiredVersion); $currentPhpVersion = new VersionConstraint('=', PHP_VERSION); $responseType = ResponseTypeInterface::RESPONSE_TYPE_SUCCESS; if (!$multipleConstraints->matches($currentPhpVersion)) { $responseType = ResponseTypeInterface::RESPONSE_TYPE_ERROR; } $data = ['responseType' => $responseType, 'data' => ['required' => $requiredVersion, 'current' => PHP_VERSION]]; return new JsonModel($data); }
/** * Verifies php version * * @return JsonModel */ public function phpVersionAction() { try { $requiredVersion = $this->phpInformation->getRequiredPhpVersion(); } catch (\Exception $e) { return new JsonModel(['responseType' => ResponseTypeInterface::RESPONSE_TYPE_ERROR, 'data' => ['error' => 'phpVersionError', 'message' => 'Cannot determine required PHP version: ' . $e->getMessage()]]); } $multipleConstraints = $this->versionParser->parseConstraints($requiredVersion); try { $normalizedPhpVersion = $this->versionParser->normalize(PHP_VERSION); } catch (\UnexpectedValueException $e) { $prettyVersion = preg_replace('#^([^~+-]+).*$#', '$1', PHP_VERSION); $normalizedPhpVersion = $this->versionParser->normalize($prettyVersion); } $currentPhpVersion = $this->versionParser->parseConstraints($normalizedPhpVersion); $responseType = ResponseTypeInterface::RESPONSE_TYPE_SUCCESS; if (!$multipleConstraints->matches($currentPhpVersion)) { $responseType = ResponseTypeInterface::RESPONSE_TYPE_ERROR; } $data = ['responseType' => $responseType, 'data' => ['required' => $requiredVersion, 'current' => PHP_VERSION]]; return new JsonModel($data); }