Skip to content

Commit

Permalink
nearest-stations api
Browse files Browse the repository at this point in the history
  • Loading branch information
p8pepe committed Sep 3, 2015
1 parent 2010221 commit 8a4ac34
Show file tree
Hide file tree
Showing 10 changed files with 370 additions and 4 deletions.
10 changes: 10 additions & 0 deletions behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@ default:
extensions:
RMiller\BehatSpec\BehatExtension:
path: bin/phpspec
Behat\Symfony2Extension: ~
Behat\MinkExtension:
default_session: 'symfony2'
sessions:
symfony2: { symfony2: ~ }
suites:
administrator:
contexts: [ AdministratorContext ]
filters: { role: system administrator }
public_transport_user:
contexts: [ PublicTransportUserContext ]
filters: { role: public transport user }
api_public_transport_user:
contexts:
- ApiPublicTransportUserContext:
dockingStations: @cocoders.repository.docking_station
filters: { role: public transport user, tags: api }
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
"behat/behat": "~3.0",
"phpspec/phpspec": "~2.2",
"rmiller/behat-spec": "~0.2",
"sensio/generator-bundle": "~2.3"
"sensio/generator-bundle": "~2.3",
"behat/mink": "~1.5.0",
"behat/mink-extension": "~2.0.0",
"behat/symfony2-extension": "~2.0.0",
"behat/mink-browserkit-driver": "~1.1.0"
},
"scripts": {
"post-root-package-install": [
Expand Down
231 changes: 230 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 83 additions & 0 deletions features/bootstrap/ApiPublicTransportUserContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\TableNode;
use Behat\MinkExtension\Context\MinkAwareContext;

class ApiPublicTransportUserContext extends PublicTransportUserContext implements MinkAwareContext, Context, SnippetAcceptingContext
{
/** @var \Behat\Mink\Mink */
private $mink;
private $minkParameters;

/**
* Initializes context.
*
* Every scenario gets its own context instance.
* You can also pass arbitrary arguments to the
* context constructor through behat.yml.
*/
public function __construct($dockingStations)
{
parent::__construct();

$this->dockingStations = $dockingStations;
}

public function iAmSearchingNearestBikeDockingStationsFromMyPosisitonWhichIs($positionString)
{
$position = \Cocoders\CityBike\Position::fromString($positionString);

$this->mink->getSession()->visit('/nearest-stations/'.urlencode($position->getLat()).'/'.urlencode($position->getLong()));
}

public function iShouldSeeSuchNearestDockingStations(TableNode $table)
{
$this->mink->assertSession()->statusCodeEquals(200);
$content = $this->mink->getSession()->getPage()->getContent();
$stations = json_decode($content, true);

if (!$stations) {
throw new \Exception('There is no stations');
}

foreach ($stations as $key => $foundDockingStation) {
if ($foundDockingStation['distance'] != $table->getHash()[$key]['distance (km)']) {
throw new \Exception('Distance does not match');
}
if ($foundDockingStation['availableBikes'] != $table->getHash()[$key]['available bikes']) {
throw new \Exception('Available does not match');
}
if ($foundDockingStation['lat'] != $table->getHash()[$key]['lat']) {
throw new \Exception('lat does not match');
}
if ($foundDockingStation['long'] != $table->getHash()[$key]['long']) {
throw new \Exception('long does not match');
}
if ($foundDockingStation['name'] != $table->getHash()[$key]['name']) {
throw new \Exception('name does not match');
}
}
}

/**
* Sets Mink instance.
*
* @param \Behat\Mink\Mink $mink Mink session manager
*/
public function setMink(\Behat\Mink\Mink $mink)
{
$this->mink = $mink;
}

/**
* Sets parameters provided for Mink.
*
* @param array $parameters
*/
public function setMinkParameters(array $parameters)
{
$this->minkParameters = $parameters;
}
}
6 changes: 4 additions & 2 deletions features/bootstrap/PublicTransportUserContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
class PublicTransportUserContext implements Context, SnippetAcceptingContext
{
/** @var \Cocoders\CityBike\DockingStations */
private $dockingStations;
private $foundDockingStations;
protected $dockingStations;
protected $foundDockingStations;
/**
* @var FoundDockingStation[]
*/
Expand All @@ -39,6 +39,8 @@ public function __construct()
*/
public function thereAreSuchDockingStations(TableNode $table)
{
$this->dockingStations->removeAll();

foreach ($table->getHash() as $row) {
$dockingStation = new \Cocoders\CityBike\DockingStation(
$row['id'],
Expand Down
1 change: 1 addition & 0 deletions features/searchNearestDockingStation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Feature: Searching docking station
| 2 | Toruń Św Katarzyny | 53.0132672 | 18.613699 | 2 |
| 3 | Toruń Plac Rapackiego | 53.0099343 | 18.6010726 | 0 |

@api
Scenario: Searching next docking station
When I am searching nearest bike docking stations from my posisiton which is "53.03531,18.598338"
Then I should see such nearest docking stations:
Expand Down
Loading

0 comments on commit 8a4ac34

Please sign in to comment.