Skip to content

Commit 1aead13

Browse files
author
Mario Blazek
committed
Weather by city ids test
1 parent 1091b8c commit 1aead13

1 file changed

Lines changed: 86 additions & 0 deletions

File tree

Tests/Controller/WeatherControllerTest.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Netgen\Bundle\OpenWeatherMapBundle\Core\Weather;
77
use Netgen\Bundle\OpenWeatherMapBundle\Exception\NotAuthorizedException;
88
use Netgen\Bundle\OpenWeatherMapBundle\Exception\NotFoundException;
9+
use Symfony\Component\HttpFoundation\Request;
910
use Symfony\Component\HttpFoundation\Response;
1011

1112
class WeatherControllerTest extends \PHPUnit_Framework_TestCase
@@ -339,4 +340,89 @@ public function testByCircleWithNotFoundException()
339340
$this->assertEquals('Not found', $response->getContent());
340341
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
341342
}
343+
344+
public function testByCityIds()
345+
{
346+
$weather = $this->getMockBuilder(Weather::class)
347+
->disableOriginalConstructor()
348+
->setMethods(array('fetchWeatherDataForSeveralCityIds'))
349+
->getMock();
350+
351+
$weather->expects($this->once())
352+
->willReturn('some_data')
353+
->method('fetchWeatherDataForSeveralCityIds');
354+
355+
$request = new Request(array('cities' => 12));
356+
357+
$weatherController = new WeatherController($weather);
358+
$response = $weatherController->byCityIds($request);
359+
360+
$this->assertInstanceOf(Response::class, $response);
361+
}
362+
363+
public function testByCityIdsWithNotAuthorizedException()
364+
{
365+
$weather = $this->getMockBuilder(Weather::class)
366+
->disableOriginalConstructor()
367+
->setMethods(array('fetchWeatherDataForSeveralCityIds'))
368+
->getMock();
369+
370+
$weather->expects($this->once())
371+
->willThrowException(new NotAuthorizedException('Not authorized'))
372+
->method('fetchWeatherDataForSeveralCityIds');
373+
374+
$weatherController = new WeatherController($weather);
375+
376+
$request = new Request(array('cities' => 12));
377+
378+
$response = $weatherController->byCityIds($request);
379+
380+
$this->assertInstanceOf(Response::class, $response);
381+
$this->assertEquals('Not authorized', $response->getContent());
382+
$this->assertEquals(Response::HTTP_UNAUTHORIZED, $response->getStatusCode());
383+
}
384+
385+
public function testByCityIdsWithNotFoundException()
386+
{
387+
$weather = $this->getMockBuilder(Weather::class)
388+
->disableOriginalConstructor()
389+
->setMethods(array('fetchWeatherDataForSeveralCityIds'))
390+
->getMock();
391+
392+
$weather->expects($this->once())
393+
->willThrowException(new NotFoundException('Not found'))
394+
->method('fetchWeatherDataForSeveralCityIds');
395+
396+
$weatherController = new WeatherController($weather);
397+
398+
$request = new Request(array('cities' => 12));
399+
400+
$response = $weatherController->byCityIds($request);
401+
402+
$this->assertInstanceOf(Response::class, $response);
403+
$this->assertEquals('Not found', $response->getContent());
404+
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
405+
}
406+
407+
public function testByCityIdsWithBadRequest()
408+
{
409+
$weather = $this->getMockBuilder(Weather::class)
410+
->disableOriginalConstructor()
411+
->setMethods(array('fetchWeatherDataForSeveralCityIds'))
412+
->getMock();
413+
414+
$weather->expects($this->never())
415+
->willThrowException(new NotFoundException('Not found'))
416+
->method('fetchWeatherDataForSeveralCityIds');
417+
418+
$weatherController = new WeatherController($weather);
419+
420+
$request = new Request(array());
421+
422+
$response = $weatherController->byCityIds($request);
423+
424+
$this->assertInstanceOf(Response::class, $response);
425+
$this->assertEquals('', $response->getContent());
426+
$this->assertEquals(Response::HTTP_BAD_REQUEST, $response->getStatusCode());
427+
}
342428
}

0 commit comments

Comments
 (0)