Skip to content

Commit

Permalink
Updated to codeception 2.1, enabled followRedirects
Browse files Browse the repository at this point in the history
  • Loading branch information
enumag committed Jul 9, 2015
1 parent 696af84 commit 895e7e1
Show file tree
Hide file tree
Showing 16 changed files with 235 additions and 220 deletions.
20 changes: 13 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,33 @@
"require": {
"php": ">=5.5.0",
"arachne/bootstrap": "~0.1",
"codeception/codeception": "~2.0",
"codeception/codeception": "~2.1",
"nette/bootstrap": "~2.2",
"nette/di": "~2.2",
"nette/http": "~2.2"
},
"require-dev": {
"arachne/coding-style": "~0.2",
"arachne/coding-style": "~0.3",
"enumag/application": "~0.2",
"nette/nette": "~2.2",
"squizlabs/php_codesniffer": "~2.0"
"latte/latte": "~2.2",
"squizlabs/php_codesniffer": "~2.0",
"tracy/tracy": "~2.2"
},
"autoload": {
"psr-4": {
"Arachne\\Codeception\\": "src",
"Codeception\\Module\\": "src/CodeceptionModule"
"Arachne\\Codeception\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\Unit\\": "tests/unit/src",
"Tests\\Integration\\": "tests/integration/src"
}
}
},
"repositories": [
{
"type": "composer",
"url": "http://packages.m33.cz"
}
]
}
164 changes: 0 additions & 164 deletions src/CodeceptionModule/Nette.php

This file was deleted.

26 changes: 19 additions & 7 deletions src/Connector/Nette.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace Arachne\Codeception\Connector;

use Arachne\Codeception\Http\Request as HttpRequest;
use Arachne\Codeception\Http\Response as HttpResponse;
use Nette\Application\Application;
use Nette\DI\Container;
use Nette\Http\IRequest;
use Nette\Http\IResponse;
use Symfony\Component\BrowserKit\Client;
use Symfony\Component\BrowserKit\Request;
Expand Down Expand Up @@ -32,25 +36,33 @@ public function doRequest($request)
$_SERVER = $request->getServer();
$_FILES = $request->getFiles();

$uri = str_replace('http://localhost', '', $request->getUri());
$_SERVER['REQUEST_METHOD'] = $method = strtoupper($request->getMethod());
$_SERVER['REQUEST_URI'] = $uri = str_replace('http://localhost', '', $request->getUri());

$_SERVER['REQUEST_METHOD'] = strtoupper($request->getMethod());
$_SERVER['REQUEST_URI'] = $uri;
if ($method === 'HEAD' || $method === 'GET') {
$_GET = $request->getParameters();
} else {
$_POST = $request->getParameters();
}

// Container initialization can't be called earlier because Nette\Http\IRequest service might be initialized too soon and amOnPage method would not work anymore.
$this->container->initialize();
$httpRequest = $this->container->getByType(IRequest::class);
$httpResponse = $this->container->getByType(IResponse::class);
if (!$httpRequest instanceof HttpRequest || !$httpResponse instanceof HttpResponse) {
throw new \Exception('Arachne\Codeception\DI\CodeceptionExtension is not used or conflicts with another extension.');
}
$httpRequest->reset();
$httpResponse->reset();

try {
ob_start();
$this->container->getByType('Nette\Application\Application')->run();
$this->container->getByType(Application::class)->run();
$content = ob_get_clean();

} catch (\Exception $e) {
ob_end_clean();
throw $e;
}

$httpResponse = $this->container->getByType('Nette\Http\IResponse');
$code = $httpResponse->getCode();
$headers = $httpResponse->getHeaders();

Expand Down
2 changes: 1 addition & 1 deletion src/Console/RunTestInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class RunTestInput extends ArgvInput
{

public function __construct(InputDefinition $definition = NULL)
public function __construct(InputDefinition $definition = null)
{
$parameters = [ $_SERVER['argv'][0], 'run' ];

Expand Down
8 changes: 3 additions & 5 deletions src/DI/CodeceptionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@ public function beforeCompile()
$request = $builder->getByType('Nette\Http\IRequest') ?: 'httpRequest';
if ($builder->hasDefinition($request)) {
$builder->getDefinition($request)
// RequestFactory leaves port NULL in CLI mode but the urls created by amOnPage have port 80 which breaks canonicalization.
->addSetup('$url = ?->getUrl(); if (!$url->getPort()) { $url->setPort(80); }', [ '@self' ]);
->setClass('Nette\Http\Request')
->setFactory('Arachne\Codeception\Http\Request');
}

$response = $builder->getByType('Nette\Http\IResponse') ?: 'httpResponse';
if ($builder->hasDefinition($response)) {
$builder->getDefinition($response)
->setClass('Nette\Http\IResponse')
->setFactory('Arachne\Codeception\Http\Response')
// The HTTP code from previous test sometimes survives in http_response_code() so it's necessary to reset it manually.
->addSetup('setCode', [ IResponse::S200_OK ]);
->setFactory('Arachne\Codeception\Http\Response');
}
}

Expand Down
Loading

0 comments on commit 895e7e1

Please sign in to comment.