PageRenderTime 49ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/UnitTest/src/test/settings.php

https://github.com/Yannix/zetacomponents
PHP | 116 lines | 53 code | 8 blank | 55 comment | 4 complexity | 6d6ce907c366bb53c7d8fc4b4c8d8fb9 MD5 | raw file
  1. <?php
  2. /**
  3. * File containing the ezcTestSettings class
  4. *
  5. * Licensed to the Apache Software Foundation (ASF) under one
  6. * or more contributor license agreements. See the NOTICE file
  7. * distributed with this work for additional information
  8. * regarding copyright ownership. The ASF licenses this file
  9. * to you under the Apache License, Version 2.0 (the
  10. * "License"); you may not use this file except in compliance
  11. * with the License. You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing,
  16. * software distributed under the License is distributed on an
  17. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18. * KIND, either express or implied. See the License for the
  19. * specific language governing permissions and limitations
  20. * under the License.
  21. *
  22. * @package UnitTest
  23. * @version //autogentag//
  24. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  25. */
  26. PHP_CodeCoverage::getInstance()->filter()->addFileToBlacklist( __FILE__, 'PHPUNIT' );
  27. /**
  28. * This object stores the settings from the TestRunner.
  29. *
  30. * Every TestCase can get the instance of this object, and access the settings.
  31. *
  32. * @package UnitTest
  33. * @version //autogentag//
  34. */
  35. class ezcTestSettings
  36. {
  37. /**
  38. * Holds the properties
  39. */
  40. private $properties = array();
  41. /**
  42. * Holds the one and only instance of this object.
  43. */
  44. private static $instance = null;
  45. /**
  46. * Use the getInstance() method instead to get an instance of this class.
  47. */
  48. private function __construct()
  49. {
  50. $this->properties['db'] = new ezcTestDatabaseSettings;
  51. }
  52. /**
  53. * Returns an instance of this class.
  54. */
  55. public static function getInstance()
  56. {
  57. if ( is_null( ezcTestSettings::$instance ))
  58. {
  59. ezcTestSettings::$instance = new ezcTestSettings();
  60. }
  61. return ezcTestSettings::$instance;
  62. }
  63. /**
  64. * No properties can be set.
  65. * @ignore
  66. */
  67. public function __set( $name, $value )
  68. {
  69. switch ( $name )
  70. {
  71. case 'db':
  72. trigger_error( "Property: db is read-only", E_USER_ERROR );
  73. break;
  74. }
  75. }
  76. /**
  77. * The db property can be read.
  78. * @ignore
  79. */
  80. public function __get( $name )
  81. {
  82. switch ( $name )
  83. {
  84. case 'db':
  85. return $this->properties['db'];
  86. default:
  87. return parent::__get( $name );
  88. }
  89. }
  90. /**
  91. * Set all the database settings via a given settings array.
  92. */
  93. public function setDatabaseSettings( $settings )
  94. {
  95. $settingNames = array(
  96. 'dsn', 'phptype', 'dbsyntax', 'username', 'password', 'protocol',
  97. 'hostspec', 'port', 'socket', 'database'
  98. );
  99. foreach ( $settingNames as $settingName )
  100. {
  101. if ( isset( $settings[$settingName] ) )
  102. {
  103. $this->properties['db']->$settingName = $settings[$settingName];
  104. }
  105. }
  106. }
  107. }
  108. ?>