forked from jon-acker/mink-legacy-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Process GET parameters and decouple requiring #1
Open
jon-acker
wants to merge
7
commits into
carlosV2:master
Choose a base branch
from
jon-acker:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d9aa80f
Process GET parameters and refactor LegacyApp
03127aa
Merge branch 'feature/process_get_parameters' of github.com:jon-acker…
69bb11c
Remove unused
e571fe5
Spec adding parameters from GET
76b8b5e
bin/phpspec
4713342
Fix type hinting
f083f7b
Downgrade phpspec and phpunit versions
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/vendor/ | ||
vendor/ | ||
composer.lock | ||
bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
Feature: Passing parameters | ||
In order to emulate ... | ||
As a developer | ||
I need to be able to pass GET and POST parameters to the application | ||
|
||
Background: | ||
Given the file "index.php" is configured as the unique frontend controller | ||
|
||
Scenario: Error is generated when trying to render input when no parameters passed | ||
Given the "index.php" file contains: | ||
""" | ||
<?php | ||
echo "My name is: {$_GET['name']}"; | ||
""" | ||
When I make a request to "/item" with no parameters | ||
Then the page content should include the error "Undefined index: name" | ||
|
||
Scenario: Error is generated when trying to render input with incorrect parameter passed | ||
Given the "index.php" file contains: | ||
""" | ||
<?php | ||
echo "My name is: {$_GET['name']}"; | ||
""" | ||
When I make a request to "/item?nae=jon" | ||
Then the page content should include the error "Undefined index: name" | ||
|
||
Scenario: Correctly rendering input when correct parameter passed | ||
Given the "index.php" file contains: | ||
""" | ||
<?php | ||
echo "My name is: {$_GET['name']}"; | ||
""" | ||
When I make a request to "/?name=jon" | ||
Then the page content should be "My name is: jon" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace spec\carlosV2\LegacyDriver\LegacyApp; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Symfony\Component\Routing\RouteCollection; | ||
|
||
class ControllersSpec extends ObjectBehavior | ||
{ | ||
function it_is_constructed_with_routes(RouteCollection $routeCollection) | ||
{ | ||
$this->beConstructedWith($routeCollection); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace spec\carlosV2\LegacyDriver\LegacyApp; | ||
|
||
use carlosV2\LegacyDriver\LegacyApp\Controllers; | ||
use carlosV2\LegacyDriver\LegacyApp\LegacyApp; | ||
use carlosV2\LegacyDriver\LegacyApp\Script; | ||
use PhpSpec\ObjectBehavior; | ||
use PHPUnit_Framework_Assert; | ||
use Symfony\Component\BrowserKit\Request; | ||
|
||
/** | ||
* @mixin LegacyApp | ||
*/ | ||
class LegacyAppSpec extends ObjectBehavior | ||
{ | ||
function let(Script $bootstrapScript, Controllers $controllers) | ||
{ | ||
$bootstrapScript->__toString()->willReturn('script.php'); | ||
$documentRoot = './'; | ||
$environmentVariables = []; | ||
$bootstrapScripts = [$bootstrapScript]; | ||
|
||
$bootstrapScript->load()->willReturn(); | ||
|
||
$this->beConstructedWith($documentRoot, $controllers, $environmentVariables, $bootstrapScripts); | ||
} | ||
|
||
function it_loads_all_bootstrap_scripts(Script $bootstrapScript, Controllers $controllers) | ||
{ | ||
$request = new Request('http://localhost/', 'GET'); | ||
$controllers->getFront($request)->willReturn($bootstrapScript); | ||
|
||
$bootstrapScript->load()->shouldBeCalledTimes(2); | ||
|
||
$this->handle($request); | ||
} | ||
|
||
function it_sets_up_request_parameters_from_query_string_on_GET(Script $bootstrapScript, Controllers $controllers) | ||
{ | ||
$request = new Request('http://localhost/?name=jon', 'GET'); | ||
$controllers->getFront($request)->willReturn($bootstrapScript); | ||
|
||
$this->handle($request); | ||
|
||
PHPUnit_Framework_Assert::assertEquals($_REQUEST['name'], 'jon'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace spec\carlosV2\LegacyDriver\LegacyApp; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
|
||
class ScriptSpec extends ObjectBehavior | ||
{ | ||
public function let() | ||
{ | ||
$this->beConstructedWith(['bootstrap.php']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace carlosV2\LegacyDriver\LegacyApp; | ||
|
||
use Symfony\Component\BrowserKit\Request; | ||
use Symfony\Component\Routing\Matcher\UrlMatcher; | ||
use Symfony\Component\Routing\RequestContext; | ||
use Symfony\Component\Routing\Route; | ||
use Symfony\Component\Routing\RouteCollection; | ||
|
||
class Controllers | ||
{ | ||
/** | ||
* @var RouteCollection | ||
*/ | ||
private $routeCollection; | ||
|
||
/** | ||
* @param RouteCollection $routeCollection | ||
*/ | ||
public function __construct(RouteCollection $routeCollection) | ||
{ | ||
$this->routeCollection = $routeCollection; | ||
} | ||
|
||
/** | ||
* @param Request $request | ||
* | ||
* @return Script | ||
*/ | ||
public function getFront(Request $request) | ||
{ | ||
$parts = parse_url($request->getUri()); | ||
|
||
$matcher = new UrlMatcher( | ||
$this->routeCollection, | ||
new RequestContext( | ||
'/', | ||
strtoupper($request->getMethod()) | ||
) | ||
); | ||
|
||
$parameters = $matcher->match($parts['path']); | ||
|
||
return new Script($parameters['file']); | ||
} | ||
|
||
public function add(Route $route) | ||
{ | ||
$this->routeCollection->add(md5(serialize($route)), $route); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this route should be "/", and same above