SunTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\Sun;
  16. class SunTest extends \PHPUnit_Framework_TestCase
  17. {
  18. /**
  19. * @var Sun
  20. */
  21. private $sun;
  22. public function testSunRise()
  23. {
  24. $rise = new \DateTime('2014-01-01 08:00:00');
  25. $set = new \DateTime('2014-01-01 20:00:00');
  26. $this->givenThereIsASunObject($rise, $set);
  27. $this->assertSame($rise, $this->sun->rise);
  28. }
  29. public function testSunSet()
  30. {
  31. $rise = new \DateTime('2014-01-01 08:00:00');
  32. $set = new \DateTime('2014-01-01 20:00:00');
  33. $this->givenThereIsASunObject($rise, $set);
  34. $this->assertSame($set, $this->sun->set);
  35. }
  36. /**
  37. * @expectedException \LogicException
  38. */
  39. public function testSunSetBeforeSunRiseException()
  40. {
  41. $rise = new \DateTime('2014-01-01 08:00:00');
  42. $set = new \DateTime('2014-01-01 7:00:00');
  43. $this->givenThereIsASunObject($rise, $set);
  44. }
  45. private function givenThereIsASunObject($rise, $set)
  46. {
  47. $this->sun = new Sun($rise, $set);
  48. }
  49. }