added composer.json and needed libs

This commit is contained in:
Tobias Diekershoff 2015-07-11 20:21:09 +02:00
parent 4f1fb007c5
commit 1f74d409a2
42 changed files with 4413 additions and 0 deletions

View file

@ -0,0 +1,53 @@
<?php
/**
* OpenWeatherMap-PHP-API A php api to parse weather data from http://www.OpenWeatherMap.org .
*
* @license MIT
*
* Please see the LICENSE file distributed with this source code for further
* information regarding copyright and licensing.
*
* Please visit the following links to read about the usage policies and the license of
* OpenWeatherMap before using this class:
*
* @see http://www.OpenWeatherMap.org
* @see http://www.OpenWeatherMap.org/terms
* @see http://openweathermap.org/appid
*/
namespace Cmfcmf\OpenWeatherMap\Tests\Fetcher;
use \Cmfcmf\OpenWeatherMap\Fetcher\CurlFetcher;
/**
* @requires function curl_version
*/
class CurlFetcherTest extends \PHPUnit_Framework_TestCase
{
public function testInvalidUrl()
{
$fetcher = new CurlFetcher();
$content = $fetcher->fetch('http://notexisting.example.com');
$this->assertSame(false, $content);
}
public function testEmptyUrl()
{
$fetcher = new CurlFetcher();
$content = $fetcher->fetch('');
$this->assertSame(false, $content);
}
public function testValidUrl()
{
$fetcher = new CurlFetcher();
$content = $fetcher->fetch('http://httpbin.org/html');
$this->assertContains('Herman Melville', $content);
}
}

View file

@ -0,0 +1,59 @@
<?php
/**
* OpenWeatherMap-PHP-API A php api to parse weather data from http://www.OpenWeatherMap.org .
*
* @license MIT
*
* Please see the LICENSE file distributed with this source code for further
* information regarding copyright and licensing.
*
* Please visit the following links to read about the usage policies and the license of
* OpenWeatherMap before using this class:
*
* @see http://www.OpenWeatherMap.org
* @see http://www.OpenWeatherMap.org/terms
* @see http://openweathermap.org/appid
*/
namespace Cmfcmf\OpenWeatherMap\Tests\Fetcher;
use \Cmfcmf\OpenWeatherMap\Fetcher\FileGetContentsFetcher;
class FileGetContentsFetcherTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (!ini_get('allow_url_fopen')) {
$this->markTestSkipped('"allow_url_fopen" is set to off.');
}
}
/**
* @expectedException \PHPUnit_Framework_Error_Warning
*/
public function testInvalidUrl()
{
$fetcher = new FileGetContentsFetcher();
$fetcher->fetch('http://notexisting.example.com');
}
/**
* @expectedException \PHPUnit_Framework_Error_Warning
*/
public function testEmptyUrl()
{
$fetcher = new FileGetContentsFetcher();
$fetcher->fetch('');
}
public function testValidUrl()
{
$fetcher = new FileGetContentsFetcher();
$content = $fetcher->fetch('http://httpbin.org/html');
$this->assertContains('Herman Melville', $content);
}
}

View file

@ -0,0 +1,62 @@
<?php
/**
* Copyright Zikula Foundation 2014 - Zikula Application Framework
*
* This work is contributed to the Zikula Foundation under one or more
* Contributor Agreements and licensed to You under the following license:
*
* @license GNU/LGPv3 (or at your option any later version).
* @package OpenWeatherMap-PHP-Api
*
* Please see the NOTICE file distributed with this source code for further
* information regarding copyright and licensing.
*/
namespace Cmfcmf\OpenWeatherMap\Tests\Util;
use Cmfcmf\OpenWeatherMap\Util\Sun;
class SunTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Sun
*/
private $sun;
public function testSunRise()
{
$rise = new \DateTime('2014-01-01 08:00:00');
$set = new \DateTime('2014-01-01 20:00:00');
$this->givenThereIsASunObject($rise, $set);
$this->assertSame($rise, $this->sun->rise);
}
public function testSunSet()
{
$rise = new \DateTime('2014-01-01 08:00:00');
$set = new \DateTime('2014-01-01 20:00:00');
$this->givenThereIsASunObject($rise, $set);
$this->assertSame($set, $this->sun->set);
}
private function givenThereIsASunObject($rise, $set)
{
$this->sun = new Sun($rise, $set);
}
/**
* @expectedException \LogicException
*/
public function testSunSetBeforeSunRiseException()
{
$rise = new \DateTime('2014-01-01 08:00:00');
$set = new \DateTime('2014-01-01 7:00:00');
$this->givenThereIsASunObject($rise, $set);
}
}

View file

@ -0,0 +1,159 @@
<?php
/**
* Copyright Zikula Foundation 2014 - Zikula Application Framework
*
* This work is contributed to the Zikula Foundation under one or more
* Contributor Agreements and licensed to You under the following license:
*
* @license GNU/LGPv3 (or at your option any later version).
* @package OpenWeatherMap-PHP-Api
*
* Please see the NOTICE file distributed with this source code for further
* information regarding copyright and licensing.
*/
namespace Cmfcmf\OpenWeatherMap\Tests\Util;
use \Cmfcmf\OpenWeatherMap\Util\Unit;
class UnitTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Unit
*/
private $unit;
const POSITIVE_INT_VALUE = 23;
const POSITIVE_FLOAT_VALUE = 48.23534;
const NEGATIVE_INT_VALUE = -30;
const NEGATIVE_FLOAT_VALUE = -93.45839;
const ZERO_INT_VALUE = 0;
const ZERO_FLOAT_VALUE = 0.0;
public function testGetValueWithPositiveIntValue()
{
$this->givenThereIsAUnitWithValue(self::POSITIVE_INT_VALUE);
$this->assertSame((float)self::POSITIVE_INT_VALUE, $this->unit->getValue());
}
public function testGetValueWithPositiveFloatValue()
{
$this->givenThereIsAUnitWithValue(self::POSITIVE_FLOAT_VALUE);
$this->assertSame(self::POSITIVE_FLOAT_VALUE, $this->unit->getValue());
}
public function testGetValueWithNegativeIntValue()
{
$this->givenThereIsAUnitWithValue(self::NEGATIVE_INT_VALUE);
$this->assertSame((float)self::NEGATIVE_INT_VALUE, $this->unit->getValue());
}
public function testGetValueWithNegativeFloatValue()
{
$this->givenThereIsAUnitWithValue(self::NEGATIVE_FLOAT_VALUE);
$this->assertSame(self::NEGATIVE_FLOAT_VALUE, $this->unit->getValue());
}
public function testGetValueWithZeroIntValue()
{
$this->givenThereIsAUnitWithValue(self::ZERO_INT_VALUE);
$this->assertSame((float)self::ZERO_INT_VALUE, $this->unit->getValue());
}
public function testGetValueWithZeroFloatValue()
{
$this->givenThereIsAUnitWithValue(self::ZERO_FLOAT_VALUE);
$this->assertSame(self::ZERO_FLOAT_VALUE, $this->unit->getValue());
}
private function givenThereIsAUnitWithValue($value, $unit = null)
{
$this->unit = $unit === null ? new Unit($value) : new Unit($value, $unit);
}
public function testGetUnitWithEmptyUnit()
{
$this->givenThereIsAUnitWithUnit("");
$this->assertSame("", $this->unit->getUnit());
}
public function testGetUnitWithStringAsUnit()
{
$this->givenThereIsAUnitWithUnit("Hey! I'm cmfcmf");
$this->assertSame("Hey! I'm cmfcmf", $this->unit->getUnit());
}
public function testCelsiusFixture()
{
$this->givenThereIsAUnitWithUnit("celsius");
$this->assertSame("&deg;C", $this->unit->getUnit());
}
public function testFahrenheitFixture()
{
$this->givenThereIsAUnitWithUnit("fahrenheit");
$this->assertSame("F", $this->unit->getUnit());
}
private function givenThereIsAUnitWithUnit($unit)
{
$this->unit = new Unit(0, $unit);
}
public function testGetDescriptionWithEmptyDescription()
{
$this->givenThereIsAUnitWithDescription("");
$this->assertSame("", $this->unit->getDescription());
}
public function testGetDescriptionWithStringAsDescription()
{
$this->givenThereIsAUnitWithDescription("Hey! I'm cmfcmf");
$this->assertSame("Hey! I'm cmfcmf", $this->unit->getDescription());
}
private function givenThereIsAUnitWithDescription($description)
{
$this->unit = new Unit(0, "", $description);
}
public function testGetFormattedWithoutUnit()
{
$this->givenThereIsAUnitWithValue(self::POSITIVE_INT_VALUE);
$this->assertEquals(self::POSITIVE_INT_VALUE, $this->unit->getFormatted());
$this->assertEquals($this->unit->getValue(), $this->unit->getFormatted());
}
public function testGetFormattedWithUnit()
{
$this->givenThereIsAUnitWithValue(self::POSITIVE_INT_VALUE, 'K');
$this->assertEquals(self::POSITIVE_INT_VALUE . ' K', $this->unit->getFormatted());
$this->assertEquals($this->unit->getValue() . ' ' . $this->unit->getUnit(), $this->unit->getFormatted());
}
public function testToString()
{
$this->givenThereIsAUnitWithValue(self::POSITIVE_INT_VALUE, 'K');
$this->assertEquals($this->unit->getFormatted(), $this->unit);
}
}

View file

@ -0,0 +1,12 @@
<?php
call_user_func(function () {
if (!is_file($autoloadFile = __DIR__ . '/../vendor/autoload.php')) {
throw new \RuntimeException('Did not find vendor/autoload.php. Did you run "composer install --dev"?');
}
/** @noinspection PhpIncludeInspection */
require_once $autoloadFile;
ini_set('date.timezone', 'Europe/Berlin');
});