Skip to content

Commit

Permalink
Make the app testable
Browse files Browse the repository at this point in the history
  • Loading branch information
punkstar committed Nov 2, 2017
1 parent dd954c0 commit 7cc288d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 45 deletions.
46 changes: 1 addition & 45 deletions public/index.php
Original file line number Diff line number Diff line change
@@ -1,49 +1,5 @@
<?php

use Punkstar\RugbyFeed\DataManager;

require_once __DIR__ . '/../vendor/autoload.php';

$config = ['debug' => true];

$app = new Silex\Application($config);

$app->mount('/fixtures', new \Punkstar\RugbyFeedService\Controller\FixtureController());
$app->mount('/table', new \Punkstar\RugbyFeedService\Controller\TableController());

$app->get('/', function () {
$links = [];

$data = new DataManager();
$leagues = $data->getLeagues();

foreach ($leagues as $league) {
$fixtures_url = 'fixtures/' . $league->getUrlKey();
$table_url = 'table/' . $league->getUrlKey();

$links[] = sprintf(
'<li><a href="%s">%s</a></li>',
$fixtures_url,
$fixtures_url
);

foreach ($league->getTeams() as $team) {
$team_url = 'fixtures/' . $league->getUrlKey() . '/' . $team->getUrlKey();
$links[] = sprintf(
'<li><a href="%s">%s</a></li>',
$team_url,
$team_url
);
}

$links[] = sprintf(
'<li><a href="%s">%s</a></li>',
$table_url,
$table_url
);
}

return "<h1>Available Resources</h1> " . implode("\n", $links);
});

$app->run();
(new \Punkstar\RugbyFeedService\App())->getApp()->run();
70 changes: 70 additions & 0 deletions src/Punkstar/RugbyFeedService/App.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace Punkstar\RugbyFeedService;

use League\Fractal\Manager;
use League\Fractal\Resource\Collection;
use League\Fractal\Serializer\JsonApiSerializer;
use Punkstar\RugbyFeed\DataManager;
use Punkstar\RugbyFeed\FixtureSet;
use Punkstar\RugbyFeed\League\Aviva;
use Punkstar\RugbyFeed\League\Pro14;
use Punkstar\RugbyFeedService\Transformer\FixtureTransformer;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Response;

class App
{
protected $app;

public function __construct()
{
$config = ['debug' => true];

$this->app = new Application($config);

$this->app->mount('/fixtures', new Controller\FixtureController());
$this->app->mount('/table', new Controller\TableController());

$this->app->get('/', function () {
$links = [];

$data = new DataManager();
$leagues = $data->getLeagues();

foreach ($leagues as $league) {
$fixtures_url = 'fixtures/' . $league->getUrlKey();
$table_url = 'table/' . $league->getUrlKey();

$links[] = sprintf(
'<li><a href="%s">%s</a></li>',
$fixtures_url,
$fixtures_url
);

foreach ($league->getTeams() as $team) {
$team_url = 'fixtures/' . $league->getUrlKey() . '/' . $team->getUrlKey();
$links[] = sprintf(
'<li><a href="%s">%s</a></li>',
$team_url,
$team_url
);
}

$links[] = sprintf(
'<li><a href="%s">%s</a></li>',
$table_url,
$table_url
);
}

return "<h1>Available Resources</h1> " . implode("\n", $links);
});
}

public function getApp()
{
return $this->app;
}
}

0 comments on commit 7cc288d

Please sign in to comment.