Skip to content

Commit

Permalink
Merge pull request #4 from cocoders/search-api
Browse files Browse the repository at this point in the history
nearest-stations api
  • Loading branch information
l3l0 committed Nov 19, 2015
2 parents 525b799 + 43d1844 commit 2bb83f1
Show file tree
Hide file tree
Showing 10 changed files with 371 additions and 11 deletions.
6 changes: 5 additions & 1 deletion app/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ services:
class: AppBundle\Command\UpdateAvailableBikesFromProviderCommand
tags:
- { name: console.command }
arguments: [@cocoders.trm24.parser, @cocoders.use_case.update_available_bikes]
arguments: [@cocoders.trm24.parser, @cocoders.use_case.update_available_bikes]

cocoders.found_docking_stations:
class: Cocoders\InMemory\CityBike\FoundDockingStations
arguments: ["@cocoders.repository.docking_station"]
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;
}
}
Loading

0 comments on commit 2bb83f1

Please sign in to comment.