|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Arachne\Codeception\Module; |
| 4 | + |
| 5 | +use Arachne\Codeception\Connector\Nette as NetteConnector; |
| 6 | +use Codeception\TestCase; |
| 7 | +use Codeception\Lib\Framework; |
| 8 | +use Nette\DI\MissingServiceException; |
| 9 | + |
| 10 | +/** |
| 11 | + * @author Jáchym Toušek <enumag@gmail.com> |
| 12 | + */ |
| 13 | +class Nette extends Framework |
| 14 | +{ |
| 15 | + |
| 16 | + public static $containerClass; |
| 17 | + |
| 18 | + public function _before(TestCase $test) |
| 19 | + { |
| 20 | + if (!class_exists(self::$containerClass)) { |
| 21 | + throw new \Codeception\Exception\ModuleConfig(__CLASS__, 'Specify container class in bootstrap.'); |
| 22 | + } |
| 23 | + $this->container = new self::$containerClass(); |
| 24 | + $this->client = new NetteConnector(); |
| 25 | + $this->client->setContainer($this->container); |
| 26 | + // TODO: make this configurable |
| 27 | + $this->client->followRedirects(false); |
| 28 | + parent::_before($test); |
| 29 | + } |
| 30 | + |
| 31 | + public function _after(TestCase $test) |
| 32 | + { |
| 33 | + parent::_after($test); |
| 34 | + $_SESSION = []; |
| 35 | + $_GET = []; |
| 36 | + $_POST = []; |
| 37 | + $_COOKIE = []; |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * @param string $service |
| 42 | + * @return object |
| 43 | + */ |
| 44 | + public function grabService($service) |
| 45 | + { |
| 46 | + try { |
| 47 | + return $this->container->getByType($service); |
| 48 | + } catch (MissingServiceException $e) { |
| 49 | + $this->fail($e->getMessage()); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + public function seeRedirectTo($url) |
| 54 | + { |
| 55 | + $request = $this->container->getByType('Nette\Http\IRequest'); |
| 56 | + $response = $this->container->getByType('Nette\Http\IResponse'); |
| 57 | + if ($response->getHeader('Location') !== $request->getUrl()->getHostUrl() . $url && $response->getHeader('Location') !== $url) { |
| 58 | + $this->fail('Couldn\'t confirm redirect target to be "' . $url . '", Location header contains "' . $response->getHeader('Location') . '".'); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + public function debugContent() |
| 63 | + { |
| 64 | + $this->debugSection('Content', $this->client->getInternalResponse()->getContent()); |
| 65 | + } |
| 66 | + |
| 67 | +} |
0 commit comments