TemperatureTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * Copyright Zikula Foundation 2014 - Zikula Application Framework
  4. *
  5. * This work is contributed to the Zikula Foundation under one or more
  6. * Contributor Agreements and licensed to You under the following license:
  7. *
  8. * @license GNU/LGPv3 (or at your option any later version).
  9. * @package OpenWeatherMap-PHP-Api
  10. *
  11. * Please see the NOTICE file distributed with this source code for further
  12. * information regarding copyright and licensing.
  13. */
  14. namespace Cmfcmf\OpenWeatherMap\Tests\Util;
  15. use \Cmfcmf\OpenWeatherMap\Util\Unit;
  16. use \Cmfcmf\OpenWeatherMap\Util\Temperature;
  17. class TemperatureTest extends \PHPUnit_Framework_TestCase
  18. {
  19. /**
  20. * @var string
  21. */
  22. protected $unit = 'Berlin';
  23. /**
  24. * @var Temperature
  25. */
  26. protected $temperature;
  27. /**
  28. * @var string
  29. */
  30. protected $nowTemp = '298.77';
  31. /**
  32. * @var string
  33. */
  34. protected $description = 'This is a description';
  35. protected function setUp()
  36. {
  37. $units = 'Berlin';
  38. $fakeTempNow = 298.77;
  39. $fakeTempMin = 298.77;
  40. $fakeTempMax = 298.774;
  41. $tempNowUnit = new Unit($fakeTempNow, $units, $this->description);
  42. $tempMinUnit = new Unit($fakeTempMin, $units, $this->description);
  43. $tempMaxUnit = new Unit($fakeTempMax, $units, $this->description);
  44. $this->temperature = new Temperature($tempNowUnit, $tempMinUnit, $tempMaxUnit);
  45. }
  46. public function test__toString()
  47. {
  48. $expectStr = $this->nowTemp;
  49. $expectStr .= ' ' . $this->unit;
  50. $str = $this->temperature->__toString();
  51. $this->assertSame($expectStr, $str);
  52. $this->assertInternalType('string', $str);
  53. }
  54. public function testGetUnit()
  55. {
  56. $expectUnit = $this->unit;
  57. $unit = $this->temperature->getUnit();
  58. $this->assertSame($expectUnit, $unit);
  59. $this->assertInternalType('string', $unit);
  60. }
  61. public function testGetValue()
  62. {
  63. $expectValue = round($this->nowTemp, 2);
  64. $value = $this->temperature->getValue();
  65. $this->assertSame($expectValue, $value);
  66. $this->assertInternalType('double', $value);
  67. }
  68. public function testGetDescription()
  69. {
  70. $expectDescription = $this->description;
  71. $description = $this->temperature->getDescription();
  72. $this->assertSame($expectDescription, $description);
  73. $this->assertInternalType('string', $description);
  74. }
  75. public function testGetFormatted()
  76. {
  77. $expectFormattedString = $this->nowTemp;
  78. $expectFormattedString .= ' ' . $this->unit;
  79. $formattedString = $this->temperature->getFormatted();
  80. $this->assertSame($expectFormattedString, $formattedString);
  81. $this->assertInternalType('string', $formattedString);
  82. }
  83. }