diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 3e53396..c563b02 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
- php: [7.3, 7.4, 8.0]
+ php: [7.4, 8.0]
steps:
- name: Checkout code
diff --git a/composer.json b/composer.json
index 0e20ed2..70eb7b9 100644
--- a/composer.json
+++ b/composer.json
@@ -1,41 +1,43 @@
{
- "name": "codeception/module-phpbrowser",
- "description": "Codeception module for testing web application over HTTP",
- "keywords": [ "codeception", "http", "functional-testing" ],
- "homepage": "https://codeception.com/",
- "type": "library",
- "license": "MIT",
- "authors": [
- {
- "name": "Michael Bodnarchuk"
- },
- {
- "name": "Gintautas Miselis"
- }
- ],
- "minimum-stability": "RC",
- "require": {
- "php": "^7.3 || ^8.0",
- "ext-json": "*",
- "guzzlehttp/guzzle": "^7.3",
- "codeception/lib-innerbrowser": "^1.5 || *@dev",
- "codeception/codeception": "^5.0 || *@dev"
- },
- "require-dev": {
- "codeception/module-rest": "^1.3 || *@dev"
- },
- "conflict": {
- "codeception/codeception": "<5.0"
- },
- "suggest": {
- "codeception/phpbuiltinserver": "Start and stop PHP built-in web server for your tests"
- },
- "autoload": {
- "classmap": [
- "src/"
- ]
- },
- "config": {
- "classmap-authoritative": true
- }
+ "name": "codeception/module-phpbrowser",
+ "description": "Codeception module for testing web application over HTTP",
+ "keywords": [ "codeception", "http", "functional-testing" ],
+ "homepage": "https://codeception.com/",
+ "type": "library",
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "Michael Bodnarchuk"
+ },
+ {
+ "name": "Gintautas Miselis"
+ }
+ ],
+ "minimum-stability": "RC",
+ "require": {
+ "php": "^7.4 | ^8.0",
+ "ext-json": "*",
+ "guzzlehttp/guzzle": "^7.3",
+ "codeception/lib-innerbrowser": "^1.5 | *@dev",
+ "codeception/codeception": "^4.0 | *@dev"
+ },
+ "require-dev": {
+ "ext-curl": "*",
+ "aws/aws-sdk-php": "^3.199",
+ "codeception/module-rest": "^1.3 | *@dev"
+ },
+ "conflict": {
+ "codeception/codeception": "<4.0"
+ },
+ "suggest": {
+ "codeception/phpbuiltinserver": "Start and stop PHP built-in web server for your tests"
+ },
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "config": {
+ "classmap-authoritative": true
+ }
}
diff --git a/readme.md b/readme.md
index caa153a..144cbb8 100644
--- a/readme.md
+++ b/readme.md
@@ -9,7 +9,7 @@ A Codeception module for testing web application over HTTP.
## Requirements
-* `PHP 7.3` or higher.
+* `PHP 7.4` or higher.
## Installation
diff --git a/src/Codeception/Lib/Connector/Guzzle.php b/src/Codeception/Lib/Connector/Guzzle.php
index 86cc662..302f819 100644
--- a/src/Codeception/Lib/Connector/Guzzle.php
+++ b/src/Codeception/Lib/Connector/Guzzle.php
@@ -4,16 +4,16 @@
namespace Codeception\Lib\Connector;
-use Aws\Credentials\Credentials;
-use Aws\Signature\SignatureV4;
+use Aws\Credentials\Credentials as AwsCredentials;
+use Aws\Signature\SignatureV4 as AwsSignatureV4;
use Codeception\Util\Uri;
use GuzzleHttp\Client as GuzzleClient;
-use GuzzleHttp\Cookie\CookieJar;
+use GuzzleHttp\Cookie\CookieJar as GuzzleCookieJar;
use GuzzleHttp\Cookie\SetCookie;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Handler\CurlHandler;
use GuzzleHttp\Handler\StreamHandler;
-use GuzzleHttp\HandlerStack;
+use GuzzleHttp\HandlerStack as GuzzleHandlerStack;
use GuzzleHttp\Psr7\Request as Psr7Request;
use GuzzleHttp\Psr7\Response as Psr7Response;
use GuzzleHttp\Psr7\Uri as Psr7Uri;
@@ -23,33 +23,18 @@
class Guzzle extends AbstractBrowser
{
- /**
- * @var array
- */
- protected $requestOptions = [
+ protected array $requestOptions = [
'allow_redirects' => false,
'headers' => [],
];
- /**
- * @var int
- */
- protected $refreshMaxInterval = 0;
+ protected int $refreshMaxInterval = 0;
- /**
- * @var \Aws\Credentials\Credentials|null
- */
- protected $awsCredentials;
+ protected ?AwsCredentials $awsCredentials = null;
- /**
- * @var \Aws\Signature\SignatureV4|null
- */
- protected $awsSignature;
+ protected ?AwsSignatureV4 $awsSignature = null;
- /**
- * @var GuzzleClient
- */
- protected $client;
+ protected ?GuzzleClient $client = null;
/**
* Sets the maximum allowable timeout interval for a meta tag refresh to
@@ -108,13 +93,12 @@ public function setAuth(string $username, string $password, string $type = 'basi
unset($this->requestOptions['auth']);
return;
}
+
$this->requestOptions['auth'] = [$username, $password, $type];
}
/**
* Taken from Mink\BrowserKitDriver
- *
- * @return BrowserKitResponse
*/
protected function createResponse(Psr7Response $psr7Response): BrowserKitResponse
{
@@ -126,6 +110,7 @@ protected function createResponse(Psr7Response $psr7Response): BrowserKitRespons
if (isset($headers['Content-Type'])) {
$contentType = reset($headers['Content-Type']);
}
+
if (!$contentType) {
$contentType = 'text/html';
}
@@ -134,6 +119,7 @@ protected function createResponse(Psr7Response $psr7Response): BrowserKitRespons
if (preg_match('#]+charset *= *["\']?([a-zA-Z\-0-9]+)#i', $body, $matches)) {
$contentType .= ';charset=' . $matches[1];
}
+
$headers['Content-Type'] = [$contentType];
}
@@ -182,17 +168,19 @@ protected function getAbsoluteUri($uri)
return Uri::appendPath((string)$baseUri, $uri);
}
+
// relative url
if (!$this->getHistory()->isEmpty()) {
return Uri::mergeUrls((string)$this->getHistory()->current()->getUri(), $uri);
}
}
+
return Uri::mergeUrls((string)$baseUri, $uri);
}
protected function doRequest($request)
{
- /** @var $request BrowserKitRequest **/
+ /** @var $request BrowserKitRequest **/
$guzzleRequest = new Psr7Request(
$request->getMethod(),
$request->getUri(),
@@ -217,15 +205,20 @@ protected function doRequest($request)
} else {
$response = $this->client->send($guzzleRequest, $options);
}
- } catch (RequestException $e) {
- if (!$e->hasResponse()) {
- throw $e;
+ } catch (RequestException $exception) {
+ if (!$exception->hasResponse()) {
+ throw $exception;
}
- $response = $e->getResponse();
+
+ $response = $exception->getResponse();
}
+
return $this->createResponse($response);
}
+ /**
+ * @return array
+ */
protected function extractHeaders(BrowserKitRequest $request): array
{
$headers = [];
@@ -240,6 +233,7 @@ protected function extractHeaders(BrowserKitRequest $request): array
$headers[$header] = $val;
}
}
+
return $headers;
}
@@ -255,9 +249,11 @@ protected function extractFormData(BrowserKitRequest $browserKitRequest): ?array
if (isset($headers['HTTP_CONTENT_TYPE']) && $headers['HTTP_CONTENT_TYPE'] !== 'application/x-www-form-urlencoded') {
return null;
}
+
if ($browserKitRequest->getContent() !== null) {
return null;
}
+
return $browserKitRequest->getParameters();
}
@@ -275,6 +271,7 @@ protected function extractMultipartFormData(BrowserKitRequest $browserKitRequest
foreach ($browserKitRequest->getParameters() as $k => $parameter) {
$parts = $this->formatMultipart($parts, $k, $parameter);
}
+
return $parts;
}
@@ -284,8 +281,10 @@ protected function formatMultipart($parts, $key, $value)
foreach ($value as $subKey => $subValue) {
$parts = array_merge($this->formatMultipart([], $key.sprintf('[%s]', $subKey), $subValue), $parts);
}
+
return $parts;
}
+
$parts[] = ['name' => $key, 'contents' => (string) $value];
return $parts;
}
@@ -313,6 +312,7 @@ protected function mapFiles($requestFiles, $arrayName = ''): array
'content-type' => $info['type']
];
}
+
$files[] = $file;
}
} else {
@@ -329,7 +329,7 @@ protected function mapFiles($requestFiles, $arrayName = ''): array
return $files;
}
- protected function extractCookies($host): \GuzzleHttp\Cookie\CookieJar
+ protected function extractCookies($host): GuzzleCookieJar
{
$jar = [];
$cookies = $this->getCookieJar()->all();
@@ -338,34 +338,41 @@ protected function extractCookies($host): \GuzzleHttp\Cookie\CookieJar
if (!$setCookie->getDomain()) {
$setCookie->setDomain($host);
}
+
$jar[] = $setCookie;
}
- return new CookieJar(false, $jar);
+
+ return new GuzzleCookieJar(false, $jar);
}
- public static function createHandler($handler): \GuzzleHttp\HandlerStack
+ public static function createHandler($handler): GuzzleHandlerStack
{
- if ($handler instanceof HandlerStack) {
+ if ($handler instanceof GuzzleHandlerStack) {
return $handler;
}
+
if ($handler === 'curl') {
- return HandlerStack::create(new CurlHandler());
+ return GuzzleHandlerStack::create(new CurlHandler());
}
+
if ($handler === 'stream') {
- return HandlerStack::create(new StreamHandler());
+ return GuzzleHandlerStack::create(new StreamHandler());
}
+
if (is_string($handler) && class_exists($handler)) {
- return HandlerStack::create(new $handler);
+ return GuzzleHandlerStack::create(new $handler);
}
+
if (is_callable($handler)) {
- return HandlerStack::create($handler);
+ return GuzzleHandlerStack::create($handler);
}
- return HandlerStack::create();
+
+ return GuzzleHandlerStack::create();
}
public function setAwsAuth($config): void
{
- $this->awsCredentials = new Credentials($config['key'], $config['secret']);
- $this->awsSignature = new SignatureV4($config['service'], $config['region']);
+ $this->awsCredentials = new AwsCredentials($config['key'], $config['secret']);
+ $this->awsSignature = new AwsSignatureV4($config['service'], $config['region']);
}
}
diff --git a/src/Codeception/Module/PhpBrowser.php b/src/Codeception/Module/PhpBrowser.php
index 4755dce..580e1df 100644
--- a/src/Codeception/Module/PhpBrowser.php
+++ b/src/Codeception/Module/PhpBrowser.php
@@ -14,7 +14,7 @@
use GuzzleHttp\Client as GuzzleClient;
/**
- * Uses [Guzzle](http://guzzlephp.org/) to interact with your application over CURL.
+ * Uses [Guzzle](https://docs.guzzlephp.org/en/stable/) to interact with your application over CURL.
* Module works over CURL and requires **PHP CURL extension** to be enabled.
*
* Use to perform web acceptance tests with non-javascript browser.
@@ -106,7 +106,7 @@ class PhpBrowser extends InnerBrowser implements Remote, MultiSession
/**
* @var string[]
*/
- protected $guzzleConfigFields = [
+ protected array $guzzleConfigFields = [
'auth',
'proxy',
'verify',
@@ -125,10 +125,7 @@ class PhpBrowser extends InnerBrowser implements Remote, MultiSession
*/
public $client;
- /**
- * @var GuzzleClient
- */
- public $guzzle;
+ public ?GuzzleClient $guzzle = null;
public function _initialize()
{
@@ -140,6 +137,7 @@ public function _before(TestInterface $test)
if (!$this->client) {
$this->client = new Guzzle();
}
+
$this->_prepareSession();
}
@@ -171,6 +169,7 @@ public function amOnUrl($url): void
if ($page === '') {
$page = '/';
}
+
$this->debugSection('Host', $host);
$this->amOnPage($page);
}
@@ -214,19 +213,22 @@ public function executeInGuzzle(Closure $function)
return $function($this->guzzle);
}
+ /**
+ * @return int|string
+ */
public function _getResponseCode()
{
return $this->getResponseStatusCode();
}
- public function _initializeSession(): void
+ public function _initializeSession()
{
// independent sessions need independent cookies
$this->client = new Guzzle();
$this->_prepareSession();
}
- public function _prepareSession()
+ public function _prepareSession(): void
{
$defaults = array_intersect_key($this->config, array_flip($this->guzzleConfigFields));
$curlOptions = [];
@@ -248,6 +250,7 @@ public function _prepareSession()
$handler->push($middleware);
}
}
+
$defaults['handler'] = $handler;
$this->guzzle = new GuzzleClient($defaults);
@@ -255,7 +258,7 @@ public function _prepareSession()
$this->client->setClient($this->guzzle);
}
- public function _backupSession(): array
+ public function _backupSession()
{
return [
'client' => $this->client,
@@ -265,14 +268,14 @@ public function _backupSession(): array
];
}
- public function _loadSession($session): void
+ public function _loadSession($session)
{
foreach ($session as $key => $val) {
$this->$key = $val;
}
}
- public function _closeSession($session = null): void
+ public function _closeSession($session = null)
{
unset($session);
}
diff --git a/tests/unit/Codeception/Module/PhpBrowserRestTest.php b/tests/unit/Codeception/Module/PhpBrowserRestTest.php
index 49f037a..e618375 100644
--- a/tests/unit/Codeception/Module/PhpBrowserRestTest.php
+++ b/tests/unit/Codeception/Module/PhpBrowserRestTest.php
@@ -2,42 +2,44 @@
declare(strict_types=1);
+use Codeception\Lib\ModuleContainer;
+use Codeception\Module\PhpBrowser;
+use Codeception\Module\REST;
+use Codeception\Test\Cest;
use Codeception\Test\Unit;
use Codeception\Stub;
+use PHPUnit\Framework\AssertionFailedError;
+use PHPUnit\Framework\ExpectationFailedException;
+use Symfony\Component\BrowserKit\Request as SymfonyRequest;
final class PhpBrowserRestTest extends Unit
{
- /**
- * @var \Codeception\Module\REST
- */
- protected $module;
+ protected REST $module;
- /**
- * @var \Codeception\Module\PhpBrowser
- */
- protected $phpBrowser;
+ protected ?PhpBrowser $phpBrowser = null;
- public function _setUp()
+ protected function _setUp()
{
- $container = Stub::make('Codeception\Lib\ModuleContainer');
- $this->phpBrowser = new \Codeception\Module\PhpBrowser($container);
+ $container = Stub::make(ModuleContainer::class);
+ $this->phpBrowser = new PhpBrowser($container);
$url = 'http://localhost:8010';
$this->phpBrowser->_setConfig(['url' => $url]);
$this->phpBrowser->_initialize();
- $this->module = Stub::make('\Codeception\Module\REST');
+ $this->module = Stub::make(REST::class);
$this->module->_inject($this->phpBrowser);
$this->module->_initialize();
- $this->module->_before(Stub::makeEmpty('\Codeception\Test\Cest'));
- $this->phpBrowser->_before(Stub::makeEmpty('\Codeception\Test\Cest'));
+ $this->module->_before(Stub::makeEmpty(Cest::class));
+
+ $this->phpBrowser->_before(Stub::makeEmpty(Cest::class));
}
private function setStubResponse($response)
{
- $this->phpBrowser = Stub::make('\Codeception\Module\PhpBrowser', ['_getResponseContent' => $response]);
+ $this->phpBrowser = Stub::make(PhpBrowser::class, ['_getResponseContent' => $response]);
$this->module->_inject($this->phpBrowser);
$this->module->_initialize();
- $this->module->_before(Stub::makeEmpty('\Codeception\Test\Cest'));
+ $this->module->_before(Stub::makeEmpty(Cest::class));
}
public function testGet()
@@ -74,7 +76,7 @@ public function testValidJson()
public function testInvalidJson()
{
- $this->expectException('PHPUnit\Framework\ExpectationFailedException');
+ $this->expectException(ExpectationFailedException::class);
$this->setStubResponse('{xxx = yyy}');
$this->module->seeResponseIsJson();
}
@@ -90,7 +92,7 @@ public function testValidXml()
public function testInvalidXml()
{
- $this->expectException('PHPUnit\Framework\ExpectationFailedException');
+ $this->expectException(ExpectationFailedException::class);
$this->setStubResponse('John');
$this->module->seeResponseIsXml();
}
@@ -105,7 +107,7 @@ public function testSeeInJson()
$this->module->seeResponseContainsJson(['user' => ['name' => 'Davert']]);
$this->module->seeResponseContainsJson(['ticket' => ['title' => 'Bug should be fixed']]);
$this->module->seeResponseContainsJson(['ticket' => ['user' => ['name' => 'Davert']]]);
- $this->module->seeResponseContainsJson(array('ticket' => array('labels' => null)));
+ $this->module->seeResponseContainsJson(['ticket' => ['labels' => null]]);
}
public function testSeeInJsonCollection()
@@ -115,8 +117,8 @@ public function testSeeInJsonCollection()
. '{"user":"John Doe","age":27,"tags":["web-dev","java"]}]'
);
$this->module->seeResponseIsJson();
- $this->module->seeResponseContainsJson(array('tags' => array('web-dev', 'java')));
- $this->module->seeResponseContainsJson(array('user' => 'John Doe', 'age' => 27));
+ $this->module->seeResponseContainsJson(['tags' => ['web-dev', 'java']]);
+ $this->module->seeResponseContainsJson(['user' => 'John Doe', 'age' => 27]);
}
public function testArrayJson()
@@ -124,7 +126,7 @@ public function testArrayJson()
$this->setStubResponse(
'[{"id":1,"title": "Bug should be fixed"},{"title": "Feature should be implemented","id":2}]'
);
- $this->module->seeResponseContainsJson(array('id' => 1));
+ $this->module->seeResponseContainsJson(['id' => 1]);
}
/**
@@ -134,7 +136,7 @@ public function testSeeResponseContainsJsonFailsGracefullyWhenJsonResultIsNotArr
{
$this->shouldFail();
$this->setStubResponse(json_encode('no_status', JSON_THROW_ON_ERROR));
- $this->module->seeResponseContainsJson(array('id' => 1));
+ $this->module->seeResponseContainsJson(['id' => 1]);
}
public function testDontSeeResponseJsonMatchesJsonPathPassesWhenJsonResultIsNotArray()
@@ -147,16 +149,16 @@ public function testDontSeeInJson()
{
$this->setStubResponse('{"ticket": {"title": "Bug should be fixed", "user": {"name": "Davert"}}}');
$this->module->seeResponseIsJson();
- $this->module->dontSeeResponseContainsJson(array('name' => 'Davet'));
- $this->module->dontSeeResponseContainsJson(array('user' => array('name' => 'Davet')));
- $this->module->dontSeeResponseContainsJson(array('user' => array('title' => 'Bug should be fixed')));
+ $this->module->dontSeeResponseContainsJson(['name' => 'Davet']);
+ $this->module->dontSeeResponseContainsJson(['user' => ['name' => 'Davet']]);
+ $this->module->dontSeeResponseContainsJson(['user' => ['title' => 'Bug should be fixed']]);
}
public function testApplicationJsonIncludesJsonAsContent()
{
$this->module->haveHttpHeader('Content-Type', 'application/json');
- $this->module->sendPOST('/', array('name' => 'john'));
- /** @var $request \Symfony\Component\BrowserKit\Request **/
+ $this->module->sendPOST('/', ['name' => 'john']);
+ /** @var $request SymfonyRequest **/
$request = $this->module->client->getRequest();
$this->assertContains('application/json', $request->getServer());
$server = $request->getServer();
@@ -171,8 +173,8 @@ public function testApplicationJsonIncludesJsonAsContent()
public function testApplicationJsonHeaderCheckIsCaseInsensitive()
{
$this->module->haveHttpHeader('content-type', 'application/json');
- $this->module->sendPOST('/', array('name' => 'john'));
- /** @var $request \Symfony\Component\BrowserKit\Request **/
+ $this->module->sendPOST('/', ['name' => 'john']);
+ /** @var $request SymfonyRequest **/
$request = $this->module->client->getRequest();
$server = $request->getServer();
$this->assertEquals('application/json', $server['HTTP_CONTENT_TYPE']);
@@ -183,8 +185,8 @@ public function testApplicationJsonHeaderCheckIsCaseInsensitive()
public function testGetApplicationJsonNotIncludesJsonAsContent()
{
$this->module->haveHttpHeader('Content-Type', 'application/json');
- $this->module->sendGET('/', array('name' => 'john'));
- /** @var $request \Symfony\Component\BrowserKit\Request **/
+ $this->module->sendGET('/', ['name' => 'john']);
+ /** @var $request SymfonyRequest **/
$request = $this->module->client->getRequest();
$this->assertNull($request->getContent());
$this->assertContains('john', $request->getParameters());
@@ -196,25 +198,26 @@ public function testGetApplicationJsonNotIncludesJsonAsContent()
*/
public function testTwoTests()
{
- $cest1 = Stub::makeEmpty('\Codeception\Test\Cest');
- $cest2 = Stub::makeEmpty('\Codeception\Test\Cest');
+ $cest1 = Stub::makeEmpty(Cest::class);
+ $cest2 = Stub::makeEmpty(Cest::class);
$this->module->sendGET('/rest/user/');
$this->module->seeResponseIsJson();
$this->module->seeResponseContains('davert');
- $this->module->seeResponseContainsJson(array('name' => 'davert'));
+ $this->module->seeResponseContainsJson(['name' => 'davert']);
$this->module->seeResponseCodeIs(200);
$this->module->dontSeeResponseCodeIs(404);
-
+
$this->phpBrowser->_after($cest1);
$this->module->_after($cest1);
$this->module->_before($cest2);
+
$this->phpBrowser->_before($cest2);
-
+
$this->module->sendGET('/rest/user/');
$this->module->seeResponseIsJson();
$this->module->seeResponseContains('davert');
- $this->module->seeResponseContainsJson(array('name' => 'davert'));
+ $this->module->seeResponseContainsJson(['name' => 'davert']);
$this->module->seeResponseCodeIs(200);
$this->module->dontSeeResponseCodeIs(404);
}
@@ -297,7 +300,7 @@ public function testSessionHeaderBackup()
protected function shouldFail()
{
- $this->expectException('PHPUnit\Framework\AssertionFailedError');
+ $this->expectException(AssertionFailedError::class);
}
public function testGrabFromCurrentUrl()
diff --git a/tests/unit/Codeception/Module/PhpBrowserTest.php b/tests/unit/Codeception/Module/PhpBrowserTest.php
index 8e81325..c9127c7 100644
--- a/tests/unit/Codeception/Module/PhpBrowserTest.php
+++ b/tests/unit/Codeception/Module/PhpBrowserTest.php
@@ -2,34 +2,41 @@
declare(strict_types=1);
+use Codeception\Configuration as CodeceptConfig;
+use Codeception\Exception\ElementNotFound;
+use Codeception\Exception\ModuleException;
use Codeception\Exception\TestRuntimeException;
+use Codeception\Lib\Connector\Guzzle;
+use Codeception\Lib\ModuleContainer;
+use Codeception\Module\PhpBrowser;
use Codeception\Stub;
require_once 'tests/data/app/data.php';
require_once __DIR__ . '/TestsForBrowsers.php';
+use Codeception\Test\Cept;
+use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Handler\MockHandler;
+use GuzzleHttp\HandlerStack as GuzzleHandlerStack;
+use GuzzleHttp\Middleware as GuzzleMiddleware;
use GuzzleHttp\Psr7\Response;
-use PHPUnit\Framework\AssertionFailedError;
+use Symfony\Component\BrowserKit\Cookie;
final class PhpBrowserTest extends TestsForBrowsers
{
- /**
- * @var \Codeception\Module\PhpBrowser
- */
- protected $module;
+ protected PhpBrowser $module;
- protected $history = [];
+ protected array $history = [];
protected function _setUp()
{
- $container = Stub::make('Codeception\Lib\ModuleContainer');
- $this->module = new \Codeception\Module\PhpBrowser($container);
+ $container = Stub::make(ModuleContainer::class);
+ $this->module = new PhpBrowser($container);
$url = 'http://localhost:8000';
$this->module->_setConfig(['url' => $url]);
$this->module->_initialize();
$this->module->_before($this->makeTest());
- $this->module->guzzle->getConfig('handler')->push(\GuzzleHttp\Middleware::history($this->history));
+ $this->module->guzzle->getConfig('handler')->push(GuzzleMiddleware::history($this->history));
}
@@ -47,12 +54,16 @@ protected function _tearDown()
if ($this->module) {
$this->module->_after($this->makeTest());
}
+
data::clean();
}
+ /**
+ * @return \\Codeception\Test\Cept&\PHPUnit\Framework\MockObject\MockObject
+ */
protected function makeTest()
{
- return Stub::makeEmpty('\Codeception\Test\Cept');
+ return Stub::makeEmpty(Cept::class);
}
public function testAjax()
@@ -61,7 +72,7 @@ public function testAjax()
$this->module->sendAjaxGetRequest('/info');
$this->assertNotNull(data::get('ajax'));
- $this->module->sendAjaxPostRequest('/form/complex', array('show' => 'author'));
+ $this->module->sendAjaxPostRequest('/form/complex', ['show' => 'author']);
$this->assertNotNull(data::get('ajax'));
$post = data::get('form');
$this->assertEquals('author', $post['show']);
@@ -79,8 +90,8 @@ public function testHtmlSnapshot()
$this->module->amOnPage('/');
$testName="debugPhpBrowser";
$this->module->makeHtmlSnapshot($testName);
- $this->assertFileExists(\Codeception\Configuration::outputDir().'debug/'.$testName.'.html');
- @unlink(\Codeception\Configuration::outputDir().'debug/'.$testName.'.html');
+ $this->assertFileExists(CodeceptConfig::outputDir().'debug/'.$testName.'.html');
+ @unlink(CodeceptConfig::outputDir().'debug/'.$testName.'.html');
}
/**
@@ -146,7 +157,7 @@ public function testSubmitFormGet()
{
$I = $this->module;
$I->amOnPage('/search');
- $I->submitForm('form', array('searchQuery' => 'test'));
+ $I->submitForm('form', ['searchQuery' => 'test']);
$I->see('Success');
}
@@ -200,6 +211,7 @@ public function testRedirectWithGetParams()
{
$this->module->amOnPage('/redirect4');
$this->module->seeInCurrentUrl('/search?ln=test@gmail.com&sn=testnumber');
+
$params = data::get('params');
$this->assertContains('test@gmail.com', $params);
}
@@ -265,11 +277,11 @@ public function testRedirectLimitReached()
$this->module->client->setMaxRedirects(1);
try {
$this->module->amOnPage('/redirect_twice');
- $this->assertTrue(false, 'redirect limit is not respected');
- } catch (\LogicException $e) {
+ $this->fail('redirect limit is not respected');
+ } catch (LogicException $exception) {
$this->assertEquals(
'The maximum number (1) of redirections was reached.',
- $e->getMessage(),
+ $exception->getMessage(),
'redirect limit is respected'
);
}
@@ -299,8 +311,9 @@ public function testRedirectToAnotherDomainUsingSchemalessUrl()
new Response(200, [], 'Cool stuff')
])
]);
- /** @var \GuzzleHttp\HandlerStack $handlerStack */
+ /** @var GuzzleHandlerStack $handlerStack */
$this->module->amOnUrl('http://fictional.redirector/redirect-to?url=//example.org/');
+
$currentUrl = $this->module->client->getHistory()->current()->getUri();
$this->assertSame('http://example.org/', $currentUrl);
}
@@ -335,9 +348,9 @@ public function testSubmitFormWithQueries()
{
$this->module->amOnPage('/form/example3');
$this->module->seeElement('form');
- $this->module->submitForm('form', array(
+ $this->module->submitForm('form', [
'name' => 'jon',
- ));
+ ]);
$form = data::get('form');
$this->assertEquals('jon', $form['name']);
$this->module->seeCurrentUrlEquals('/form/example3?validate=yes');
@@ -368,13 +381,14 @@ public function testDeleteHeadersByEmptyValue()
public function testCurlOptions()
{
- $this->module->_setConfig(array('url' => 'http://google.com', 'curl' => array('CURLOPT_NOBODY' => true)));
+ $this->module->_setConfig(['url' => 'http://google.com', 'curl' => ['CURLOPT_NOBODY' => true]]);
$this->module->_initialize();
if (method_exists($this->module->guzzle, 'getConfig')) {
$config = $this->module->guzzle->getConfig();
} else {
$config = $this->module->guzzle->getDefaultOption('config');
}
+
$this->assertArrayHasKey('curl', $config);
$this->assertArrayHasKey(CURLOPT_NOBODY, $config['curl']);
}
@@ -382,13 +396,14 @@ public function testCurlOptions()
public function testCurlSslOptions()
{
- $this->module->_setConfig(array(
+ $this->module->_setConfig([
'url' => 'https://github.com',
- 'curl' => array(
+ 'curl' => [
'CURLOPT_NOBODY' => true,
'CURLOPT_SSL_CIPHER_LIST' => 'TLSv1',
- )));
+ ]]);
$this->module->_initialize();
+
$config = $this->module->guzzle->getConfig();
$this->assertArrayHasKey('curl', $config);
@@ -417,7 +432,7 @@ public function testHttpAuth()
public function testRawGuzzle()
{
- $code = $this->module->executeInGuzzle(function (\GuzzleHttp\Client $client) {
+ $code = $this->module->executeInGuzzle(function (GuzzleClient $client): int {
$res = $client->get('/info');
return $res->getStatusCode();
});
@@ -457,7 +472,8 @@ public function testDoubleSlash()
{
$I = $this->module;
$I->amOnPage('/register');
- $I->submitForm('form', array('test' => 'test'));
+ $I->submitForm('form', ['test' => 'test']);
+
$formUrl = $this->module->client->getHistory()->current()->getUri();
$formPath = parse_url($formUrl)['path'];
$this->assertEquals($formPath, '/register');
@@ -465,7 +481,7 @@ public function testDoubleSlash()
public function testFillFieldWithoutPage()
{
- $this->expectException("\\Codeception\\Exception\\ModuleException");
+ $this->expectException(ModuleException::class);
$this->module->fillField('#name', 'Nothing special');
}
@@ -493,12 +509,13 @@ public function testCookiesForDomain()
$mock = new MockHandler([
new Response(200, ['X-Foo' => 'Bar']),
]);
- $handler = \GuzzleHttp\HandlerStack::create($mock);
- $handler->push(\GuzzleHttp\Middleware::history($this->history));
- $client = new \GuzzleHttp\Client(['handler' => $handler, 'base_uri' => 'http://codeception.com']);
- $guzzleConnector = new \Codeception\Lib\Connector\Guzzle();
+ $handler = GuzzleHandlerStack::create($mock);
+ $handler->push(GuzzleMiddleware::history($this->history));
+
+ $client = new GuzzleClient(['handler' => $handler, 'base_uri' => 'http://codeception.com']);
+ $guzzleConnector = new Guzzle();
$guzzleConnector->setClient($client);
- $guzzleConnector->getCookieJar()->set(new \Symfony\Component\BrowserKit\Cookie('hello', 'world'));
+ $guzzleConnector->getCookieJar()->set(new Cookie('hello', 'world'));
$guzzleConnector->request('GET', 'http://codeception.com/');
$this->assertArrayHasKey('cookies', $this->history[0]['options']);
/** @var $cookie GuzzleHttp\Cookie\SetCookie **/
@@ -528,6 +545,7 @@ public function testSetCookiesByOptions()
$this->module->amOnPage('/cookies');
$this->module->seeCurrentUrlEquals('/info');
}
+
/**
* @issue https://github.com/Codeception/Codeception/issues/2234
*/
@@ -543,7 +561,7 @@ public function testEmptyValueOfCookie()
public function testRequestApi()
{
- $this->expectException('Codeception\Exception\ModuleException');
+ $this->expectException(ModuleException::class);
$response = $this->module->_request('POST', '/form/try', ['user' => 'davert']);
$data = data::get('form');
$this->assertEquals('davert', $data['user']);
@@ -568,7 +586,7 @@ public function testLoadPageApi()
public function testClickFailure()
{
$this->module->amOnPage('/info');
- $this->expectException('Codeception\Exception\ElementNotFound');
+ $this->expectException(ElementNotFound::class);
$this->expectExceptionMessage("'Sign In!' is invalid CSS and XPath selector and Link or Button element with 'name=Sign In!' was not found");
$this->module->click('Sign In!');
}
@@ -630,6 +648,7 @@ public function testFillFieldInGetFormWithoutId()
$this->module->selectOption('select_name', 'two');
$this->module->fillField('search_name', 'searchterm');
$this->module->click('Submit');
+
$params = data::get('query');
$this->assertEquals('two', $params['select_name']);
$this->assertEquals('searchterm', $params['search_name']);
@@ -637,7 +656,7 @@ public function testFillFieldInGetFormWithoutId()
public function testGrabPageSourceWhenNotOnPage()
{
- $this->expectException('\Codeception\Exception\ModuleException');
+ $this->expectException(ModuleException::class);
$this->expectExceptionMessage('Page not loaded. Use `$I->amOnPage` (or hidden API methods `_request` and `_loadPage`) to open it');
$this->module->grabPageSource();
}
@@ -684,6 +703,7 @@ public function testSetUserAgentUsingConfig()
$this->module->_initialize();
$this->module->amOnPage('/user-agent');
+
$response = $this->module->grabPageSource();
$this->assertEquals('Codeception User Agent Test 1.0', $response, 'Incorrect user agent');
}
@@ -732,6 +752,7 @@ public function testSelectOptionByTextWhenItHasNoValue()
$this->module->amOnPage('/form/bug5547');
$this->module->selectOption('#_payment_type', 'qwerty');
$this->module->click('Submit');
+
$form = data::get('form');
$this->assertEquals('qwerty', $form['payment_type']);
}
diff --git a/tests/unit/Codeception/Module/TestsForBrowsers.php b/tests/unit/Codeception/Module/TestsForBrowsers.php
index d0df175..ddf2c28 100644
--- a/tests/unit/Codeception/Module/TestsForBrowsers.php
+++ b/tests/unit/Codeception/Module/TestsForBrowsers.php
@@ -2,26 +2,26 @@
declare(strict_types=1);
+use Codeception\Exception\ModuleException;
+
require_once 'TestsForWeb.php';
+
/**
* Author: davert
* Date: 13.01.12
*
- * Class TestsForMink
- * Description:
- *
+ * Class TestsForBrowsers
*/
-
abstract class TestsForBrowsers extends TestsForWeb
{
public function testAmOnSubdomain()
{
- $this->module->_reconfigure(array('url' => 'http://google.com'));
+ $this->module->_reconfigure(['url' => 'http://google.com']);
$this->module->amOnSubdomain('user');
$this->assertEquals('http://user.google.com', $this->module->_getUrl());
- $this->module->_reconfigure(array('url' => 'http://www.google.com'));
+ $this->module->_reconfigure(['url' => 'http://www.google.com']);
$this->module->amOnSubdomain('user');
$this->assertEquals('http://user.google.com', $this->module->_getUrl());
}
@@ -48,12 +48,12 @@ public function testHeadersRedirect()
*/
public function testSiteRootRelativePathsForBasePathWithSubdir()
{
- $this->module->_reconfigure(array('url' => 'http://localhost:8000/form'));
+ $this->module->_reconfigure(['url' => 'http://localhost:8000/form']);
$this->module->amOnPage('/relative_siteroot');
$this->module->seeInCurrentUrl('/form/relative_siteroot');
- $this->module->submitForm('form', array(
+ $this->module->submitForm('form', [
'test' => 'value'
- ));
+ ]);
$this->module->dontSeeInCurrentUrl('form/form/');
$this->module->amOnPage('relative_siteroot');
$this->module->click('Click me');
@@ -62,7 +62,7 @@ public function testSiteRootRelativePathsForBasePathWithSubdir()
public function testOpenPageException()
{
- $this->expectException('Codeception\Exception\ModuleException');
+ $this->expectException(ModuleException::class);
$this->module->see('Hello');
}
}
diff --git a/tests/unit/Codeception/Module/TestsForWeb.php b/tests/unit/Codeception/Module/TestsForWeb.php
index 057d135..9d571b5 100644
--- a/tests/unit/Codeception/Module/TestsForWeb.php
+++ b/tests/unit/Codeception/Module/TestsForWeb.php
@@ -2,21 +2,22 @@
declare(strict_types=1);
+use Codeception\Exception\ElementNotFound;
+use Codeception\Exception\MalformedLocatorException;
+use Codeception\Module\PhpBrowser;
+use Codeception\Step\Argument\PasswordArgument;
+use Codeception\Test\Unit;
+use PHPUnit\Framework\AssertionFailedError;
+
/**
* Author: davert
* Date: 13.01.12
*
- * Class TestsForMink
- * Description:
- *
+ * Class TestsForWeb
*/
-
-abstract class TestsForWeb extends \Codeception\Test\Unit
+abstract class TestsForWeb extends Unit
{
- /**
- * @var \Codeception\Module\PhpBrowser
- */
- protected $module;
+ protected PhpBrowser $module;
public function testAmOnPage()
{
@@ -95,7 +96,7 @@ public function testSeeIsCaseInsensitiveForUnicodeText()
public function testDontSeeIsCaseInsensitiveForUnicodeText()
{
- $this->expectException("PHPUnit\Framework\AssertionFailedError");
+ $this->expectException(AssertionFailedError::class);
$this->module->amOnPage('/info');
$this->module->dontSee('ссылочка');
}
@@ -132,7 +133,7 @@ public function testDontSeeLink()
public function testSeeLinkFailsIfTextDoesNotMatch()
{
- $this->expectException('PHPUnit\Framework\AssertionFailedError');
+ $this->expectException(AssertionFailedError::class);
$this->expectExceptionMessage("No links containing text 'Codeception' were found in page /external_url");
$this->module->amOnPage('/external_url');
$this->module->seeLink('Codeception');
@@ -140,7 +141,7 @@ public function testSeeLinkFailsIfTextDoesNotMatch()
public function testSeeLinkFailsIfHrefDoesNotMatch()
{
- $this->expectException('PHPUnit\Framework\AssertionFailedError');
+ $this->expectException(AssertionFailedError::class);
$this->expectExceptionMessage("No links containing text 'Next' and URL '/fsdfsdf/' were found in page /external_url");
$this->module->amOnPage('/external_url');
$this->module->seeLink('Next', '/fsdfsdf/');
@@ -148,7 +149,7 @@ public function testSeeLinkFailsIfHrefDoesNotMatch()
public function testSeeLinkFailsIfHrefDoesNotMatchExactly()
{
- $this->expectException('PHPUnit\Framework\AssertionFailedError');
+ $this->expectException(AssertionFailedError::class);
$this->expectExceptionMessage("No links containing text 'Next' and URL 'http://codeception' were found in page /external_url");
$this->module->amOnPage('/external_url');
$this->module->seeLink('Next', 'http://codeception');
@@ -156,7 +157,7 @@ public function testSeeLinkFailsIfHrefDoesNotMatchExactly()
public function testDontSeeLinkFailsIfTextMatches()
{
- $this->expectException('PHPUnit\Framework\AssertionFailedError');
+ $this->expectException(AssertionFailedError::class);
$this->expectExceptionMessage("Link containing text 'Next' was found in page /external_url");
$this->module->amOnPage('/external_url');
$this->module->dontSeeLink('Next');
@@ -164,7 +165,7 @@ public function testDontSeeLinkFailsIfTextMatches()
public function testDontSeeLinkFailsIfTextAndUrlMatches()
{
- $this->expectException('PHPUnit\Framework\AssertionFailedError');
+ $this->expectException(AssertionFailedError::class);
$this->expectExceptionMessage("Link containing text 'Next' and URL 'http://codeception.com/' was found in page /external_url");
$this->module->amOnPage('/external_url');
$this->module->dontSeeLink('Next', 'http://codeception.com/');
@@ -179,7 +180,7 @@ public function testSeeLinkMatchesRelativeLink()
public function testDontSeeLinkMatchesRelativeLink()
{
- $this->expectException('PHPUnit\Framework\AssertionFailedError');
+ $this->expectException(AssertionFailedError::class);
$this->expectExceptionMessage("Link containing text 'Sign in!' and URL '/login' was found in page /info");
$this->module->amOnPage('/info');
$this->module->dontSeeLink('Sign in!', '/login');
@@ -204,6 +205,7 @@ public function testClickByName()
{
$this->module->amOnPage('/form/button');
$this->module->click("btn0");
+
$form = data::get('form');
$this->assertEquals('val', $form['text']);
}
@@ -231,6 +233,7 @@ public function testCheckboxByCss()
$this->module->amOnPage('/form/checkbox');
$this->module->checkOption('#checkin');
$this->module->click('Submit');
+
$form = data::get('form');
$this->assertEquals('agree', $form['terms']);
}
@@ -240,6 +243,7 @@ public function testCheckboxByName()
$this->module->amOnPage('/form/checkbox');
$this->module->checkOption('terms');
$this->module->click('Submit');
+
$form = data::get('form');
$this->assertEquals('agree', $form['terms']);
}
@@ -249,6 +253,7 @@ public function testCheckboxByLabel()
$this->module->amOnPage('/form/checkbox');
$this->module->checkOption('I Agree');
$this->module->click('Submit');
+
$form = data::get('form');
$this->assertEquals('agree', $form['terms']);
}
@@ -262,6 +267,7 @@ public function testCheckboxArray()
$this->module->amOnPage('/form/checkbox_array');
$this->module->checkOption('#id2');
$this->module->click('Submit');
+
$form = data::get('form');
$this->assertEquals('second', reset($form['field']));
}
@@ -271,6 +277,7 @@ public function testSelectByCss()
$this->module->amOnPage('/form/select');
$this->module->selectOption('form select[name=age]', 'adult');
$this->module->click('Submit');
+
$form = data::get('form');
$this->assertEquals('adult', $form['age']);
}
@@ -280,6 +287,7 @@ public function testSelectByName()
$this->module->amOnPage('/form/select');
$this->module->selectOption('age', 'adult');
$this->module->click('Submit');
+
$form = data::get('form');
$this->assertEquals('adult', $form['age']);
}
@@ -289,6 +297,7 @@ public function testSelectByLabel()
$this->module->amOnPage('/form/select');
$this->module->selectOption('Select your age', 'dead');
$this->module->click('Submit');
+
$form = data::get('form');
$this->assertEquals('dead', $form['age']);
}
@@ -298,6 +307,7 @@ public function testSelectByLabelAndOptionText()
$this->module->amOnPage('/form/select');
$this->module->selectOption('Select your age', '21-60');
$this->module->click('Submit');
+
$form = data::get('form');
$this->assertEquals('adult', $form['age']);
}
@@ -324,6 +334,7 @@ public function testSeeSelectedOptionReturnsFirstOptionIfNotSelected()
$this->module->amOnPage('/form/complex');
$this->module->seeOptionIsSelected('#age', 'below 13');
$this->module->click('Submit');
+
$form = data::get('form');
$this->assertEquals('child', $form['age'], 'first option was not submitted');
}
@@ -336,6 +347,7 @@ public function testSubmitSeveralSubmitsForm()
{
$this->module->amOnPage('/form/example8');
$this->module->click('form button[value="second"]');
+
$form = data::get('form');
$this->assertEquals('second', $form['submit']);
}
@@ -350,6 +362,7 @@ public function testSubmitLotsOfSubmitsForm()
{
$this->module->amOnPage('/form/example11');
$this->module->click('form button[value="fifth"]');
+
$form = data::get('form');
$this->assertEquals('fifth', $form['submit']);
}
@@ -357,25 +370,28 @@ public function testSubmitLotsOfSubmitsForm()
public function testSelectMultipleOptionsByText()
{
$this->module->amOnPage('/form/select_multiple');
- $this->module->selectOption('What do you like the most?', array('Play Video Games', 'Have Sex'));
+ $this->module->selectOption('What do you like the most?', ['Play Video Games', 'Have Sex']);
$this->module->click('Submit');
+
$form = data::get('form');
- $this->assertEquals(array('play', 'adult'), $form['like']);
+ $this->assertEquals(['play', 'adult'], $form['like']);
}
public function testSelectMultipleOptionsByValue()
{
$this->module->amOnPage('/form/select_multiple');
- $this->module->selectOption('What do you like the most?', array('eat', 'adult'));
+ $this->module->selectOption('What do you like the most?', ['eat', 'adult']);
$this->module->click('Submit');
+
$form = data::get('form');
- $this->assertEquals(array('eat', 'adult'), $form['like']);
+ $this->assertEquals(['eat', 'adult'], $form['like']);
}
public function testHidden()
{
$this->module->amOnPage('/form/hidden');
$this->module->click('Submit');
+
$form = data::get('form');
$this->assertEquals('kill_people', $form['action']);
}
@@ -385,6 +401,7 @@ public function testTextareaByCss()
$this->module->amOnPage('/form/textarea');
$this->module->fillField('textarea', 'Nothing special');
$this->module->click('Submit');
+
$form = data::get('form');
$this->assertEquals('Nothing special', $form['description']);
}
@@ -394,6 +411,7 @@ public function testTextareaByLabel()
$this->module->amOnPage('/form/textarea');
$this->module->fillField('Description', 'Nothing special');
$this->module->click('Submit');
+
$form = data::get('form');
$this->assertEquals('Nothing special', $form['description']);
}
@@ -403,6 +421,7 @@ public function testTextFieldByCss()
$this->module->amOnPage('/form/field');
$this->module->fillField('#name', 'Nothing special');
$this->module->click('Submit');
+
$form = data::get('form');
$this->assertEquals('Nothing special', $form['name']);
}
@@ -413,6 +432,7 @@ public function testTextFieldByName()
$this->module->fillField('LoginForm[username]', 'davert');
$this->module->fillField('LoginForm[password]', '123456');
$this->module->click('Login');
+
$login = data::get('form');
$this->assertEquals('davert', $login['LoginForm']['username']);
$this->assertEquals('123456', $login['LoginForm']['password']);
@@ -423,6 +443,7 @@ public function testTextFieldByLabel()
$this->module->amOnPage('/form/field');
$this->module->fillField('Name', 'Nothing special');
$this->module->click('Submit');
+
$form = data::get('form');
$this->assertEquals('Nothing special', $form['name']);
}
@@ -432,6 +453,7 @@ public function testTextFieldByLabelWithoutFor()
$this->module->amOnPage('/form/field');
$this->module->fillField('Other label', 'Nothing special');
$this->module->click('Submit');
+
$form = data::get('form');
$this->assertEquals('Nothing special', $form['othername']);
}
@@ -572,7 +594,7 @@ public function testSeeInFieldOnSelectMultiple()
public function testSeeInFieldWithExactMatch()
{
$this->module->amOnPage('/form/field_values');
- $this->module->seeInField(array('name' => 'select2'), 'see test one');
+ $this->module->seeInField(['name' => 'select2'], 'see test one');
}
public function testDontSeeInFieldOnInput()
@@ -615,7 +637,7 @@ public function testSeeInFormFields()
public function testSeeInFormFieldsFails()
{
$this->module->amOnPage('/form/field_values');
- $this->expectException("PHPUnit\Framework\AssertionFailedError");
+ $this->expectException(AssertionFailedError::class);
$params = [
'radio1' => 'something I should not see',
'checkbox1' => true,
@@ -653,7 +675,7 @@ public function testDontSeeInFormFields()
public function testDontSeeInFormFieldsFails()
{
$this->module->amOnPage('/form/field_values');
- $this->expectException("PHPUnit\Framework\AssertionFailedError");
+ $this->expectException(AssertionFailedError::class);
$params = [
'checkbox[]' => [
'wont see this anyway',
@@ -730,6 +752,7 @@ public function testGrabValueFromWithFillField()
{
$this->module->amOnPage('/form/bug3866');
$this->module->fillField('empty', 'new value');
+
$result = $this->module->grabValueFrom('#empty');
$this->assertEquals('new value', $result);
$this->module->fillField('empty_textarea', 'new value');
@@ -781,7 +804,7 @@ public function testSeeElementOnPage()
// regression test. https://github.com/Codeception/Codeception/issues/587
public function testSeeElementOnPageFails()
{
- $this->expectException("PHPUnit\Framework\AssertionFailedError");
+ $this->expectException(AssertionFailedError::class);
$this->module->amOnPage('/form/field');
$this->module->dontSeeElement('input[name=name]');
}
@@ -795,7 +818,6 @@ public function testCookies()
$this->module->setCookie($cookie_name, $cookie_value);
$this->module->setCookie('notthatcookie', '22222');
-
$this->module->seeCookie($cookie_name);
$this->module->dontSeeCookie('evil_cookie');
@@ -946,6 +968,7 @@ public function testExample1()
$this->module->fillField('#LoginForm_password', '123456');
$this->module->checkOption('#LoginForm_rememberMe');
$this->module->click('Login');
+
$login = data::get('form');
$this->assertEquals('davert', $login['LoginForm']['username']);
$this->assertEquals('123456', $login['LoginForm']['password']);
@@ -958,6 +981,7 @@ public function testExample2()
$this->module->fillField('input[name=username]', 'davert');
$this->module->fillField('input[name=password]', '123456');
$this->module->click('Log on');
+
$login = data::get('form');
$this->assertEquals('davert', $login['username']);
$this->assertEquals('123456', $login['password']);
@@ -1039,10 +1063,10 @@ public function testExample9()
public function testSubmitForm()
{
$this->module->amOnPage('/form/complex');
- $this->module->submitForm('form', array(
+ $this->module->submitForm('form', [
'name' => 'Davert',
'description' => 'Is Codeception maintainer'
- ));
+ ]);
$form = data::get('form');
$this->assertEquals('Davert', $form['name']);
$this->assertEquals('Is Codeception maintainer', $form['description']);
@@ -1069,9 +1093,9 @@ public function testSubmitFormWithFillField()
public function testSubmitFormWithoutButton()
{
$this->module->amOnPage('/form/empty');
- $this->module->submitForm('form', array(
+ $this->module->submitForm('form', [
'text' => 'Hello!'
- ));
+ ]);
$form = data::get('form');
$this->assertEquals('Hello!', $form['text']);
}
@@ -1080,6 +1104,7 @@ public function testSubmitFormWithAmpersand()
{
$this->module->amOnPage('/form/submitform_ampersands');
$this->module->submitForm('form', []);
+
$form = data::get('form');
$this->assertEquals('this & that', $form['test']);
}
@@ -1088,6 +1113,7 @@ public function testSubmitFormWithArrayField()
{
$this->module->amOnPage('/form/example17');
$this->module->submitForm('form', []);
+
$data = data::get('form');
$this->assertSame('baz', $data['FooBar']['bar']);
$this->assertArrayNotHasKey('FooBar[bar]', $data);
@@ -1112,6 +1138,7 @@ public function testSubmitFormWithMultiSelect()
{
$this->module->amOnPage('/form/submitform_multiple');
$this->module->submitForm('form', []);
+
$form = data::get('form');
$this->assertCount(2, $form['select']);
$this->assertEquals('see test one', $form['select'][0]);
@@ -1164,6 +1191,7 @@ public function testSubmitFormWithDefaultTextareaValue()
{
$this->module->amOnPage('/form/textarea');
$this->module->submitForm('form', []);
+
$form = data::get('form');
$this->assertEquals('sunrise', $form['description']);
}
@@ -1186,6 +1214,7 @@ public function testSelectTwoSubmitsByText()
$this->module->amOnPage('/form/select_two_submits');
$this->module->selectOption('What kind of sandwich would you like?', 2);
$this->module->click('Save');
+
$form = data::get('form');
$this->assertEquals(2, $form['sandwich_select']);
}
@@ -1195,13 +1224,14 @@ public function testSelectTwoSubmitsByCSS()
$this->module->amOnPage('/form/select_two_submits');
$this->module->selectOption("form select[name='sandwich_select']", '2');
$this->module->click('Save');
+
$form = data::get('form');
$this->assertEquals(2, $form['sandwich_select']);
}
protected function shouldFail()
{
- $this->expectException('PHPUnit\Framework\AssertionFailedError');
+ $this->expectException(AssertionFailedError::class);
}
/**
@@ -1212,6 +1242,7 @@ public function testSubmitFormWithTwoSubmitButtonsSubmitsCorrectValue()
$this->module->amOnPage('/form/example10');
$this->module->seeElement("#button2");
$this->module->click("#button2");
+
$form = data::get('form');
$this->assertArrayHasKey('button2', $form);
$this->assertArrayHasKey('username', $form);
@@ -1227,6 +1258,7 @@ public function testSubmitFormWithTwoSubmitButtonsSubmitsCorrectValueAfterFillFi
$this->module->amOnPage('/form/example10');
$this->module->fillField("username", "bob");
$this->module->click("#button2");
+
$form = data::get('form');
$this->assertArrayHasKey('button2', $form);
$this->assertArrayHasKey('username', $form);
@@ -1240,18 +1272,18 @@ public function testSubmitFormWithTwoSubmitButtonsSubmitsCorrectValueAfterFillFi
public function testSubmitFormWithDocRelativePathForAction()
{
$this->module->amOnPage('/form/example12');
- $this->module->submitForm('form', array(
+ $this->module->submitForm('form', [
'test' => 'value'
- ));
+ ]);
$this->module->seeCurrentUrlEquals('/form/example11');
}
public function testSubmitFormWithDocRelativePathForActionFromDefaultPage()
{
$this->module->amOnPage('/form/');
- $this->module->submitForm('form', array(
+ $this->module->submitForm('form', [
'test' => 'value'
- ));
+ ]);
$this->module->seeCurrentUrlEquals('/form/example11');
}
@@ -1268,9 +1300,9 @@ public function testLinkWithDocRelativeURLFromDefaultPage()
public function testSubmitFormWithDefaultRadioAndCheckboxValues()
{
$this->module->amOnPage('/form/example16');
- $this->module->submitForm('form', array(
+ $this->module->submitForm('form', [
'test' => 'value'
- ));
+ ]);
$form = data::get('form');
$this->assertArrayHasKey('checkbox1', $form, 'Checkbox value not sent');
$this->assertArrayHasKey('radio1', $form, 'Radio button value not sent');
@@ -1281,17 +1313,17 @@ public function testSubmitFormWithDefaultRadioAndCheckboxValues()
public function testSubmitFormCheckboxWithBoolean()
{
$this->module->amOnPage('/form/example16');
- $this->module->submitForm('form', array(
+ $this->module->submitForm('form', [
'checkbox1' => true
- ));
+ ]);
$form = data::get('form');
$this->assertArrayHasKey('checkbox1', $form, 'Checkbox value not sent');
$this->assertEquals('testing', $form['checkbox1']);
$this->module->amOnPage('/form/example16');
- $this->module->submitForm('form', array(
+ $this->module->submitForm('form', [
'checkbox1' => false
- ));
+ ]);
$form = data::get('form');
$this->assertArrayNotHasKey('checkbox1', $form, 'Checkbox value sent');
}
@@ -1306,9 +1338,9 @@ public function testSubmitFormWithCheckboxesWithoutValue()
public function testSubmitFormWithButtons()
{
$this->module->amOnPage('/form/form_with_buttons');
- $this->module->submitForm('form', array(
+ $this->module->submitForm('form', [
'test' => 'value',
- ));
+ ]);
$form = data::get('form');
$this->assertFalse(
isset($form['button1']) || isset($form['button2']) || isset($form['button3']) || isset($form['button4']),
@@ -1316,9 +1348,9 @@ public function testSubmitFormWithButtons()
);
$this->module->amOnPage('/form/form_with_buttons');
- $this->module->submitForm('form', array(
+ $this->module->submitForm('form', [
'test' => 'value',
- ), 'button3');
+ ], 'button3');
$form = data::get('form');
$this->assertFalse(
isset($form['button1']) || isset($form['button2']) || isset($form['button4']),
@@ -1328,9 +1360,9 @@ public function testSubmitFormWithButtons()
$this->assertEquals($form['button3'], 'third', 'Button value for button3 should equal third');
$this->module->amOnPage('/form/form_with_buttons');
- $this->module->submitForm('form', array(
+ $this->module->submitForm('form', [
'test' => 'value',
- ), 'button4');
+ ], 'button4');
$form = data::get('form');
$this->assertFalse(
isset($form['button1']) || isset($form['button2']) || isset($form['button3']),
@@ -1345,28 +1377,28 @@ public function testSubmitFormWithButtons()
*/
public function testWrongXpath()
{
- $this->expectException('Codeception\Exception\MalformedLocatorException');
+ $this->expectException(MalformedLocatorException::class);
$this->module->amOnPage('/');
$this->module->seeElement('//aas[asd}[sd]a[/[');
}
public function testWrongCSS()
{
- $this->expectException('Codeception\Exception\MalformedLocatorException');
+ $this->expectException(MalformedLocatorException::class);
$this->module->amOnPage('/');
$this->module->seeElement('.user#iasosexpectException('Codeception\Exception\MalformedLocatorException');
+ $this->expectException(MalformedLocatorException::class);
$this->module->amOnPage('/');
$this->module->seeElement(['css' => 'hel!1$expectException('Codeception\Exception\MalformedLocatorException');
+ $this->expectException(MalformedLocatorException::class);
$this->module->amOnPage('/');
$this->module->seeElement(['xpath' => 'hellorld']);
}
@@ -1406,6 +1438,7 @@ public function testTextFieldByNameFirstNotCss()
$this->module->fillField('description', 'description');
$this->module->fillField('price', '19.99');
$this->module->click('Create');
+
$data = data::get('form');
$this->assertEquals('Special Widget', $data['title']);
}
@@ -1418,6 +1451,7 @@ public function testCheckingOptionsWithComplexNames()
$this->module->amOnPage('/form/bug1535');
$this->module->checkOption('#bmessage-topicslinks input[value="4"]');
$this->module->click('Submit');
+
$data = data::get('form');
$this->assertContains('4', $data['BMessage']['topicsLinks']);
}
@@ -1434,6 +1468,7 @@ public function testUnreachableField()
$this->module->fillField('input[name="users[]"]', 'davert');
$this->module->attachFile('input[name="files[]"]', 'app/avatar.jpg');
$this->module->click('Submit');
+
$data = data::get('form');
$this->assertContains('test3', $data['items'][1]);
$this->assertContains('test2', $data['captions']);
@@ -1444,6 +1479,7 @@ public function testSubmitAdjacentForms()
{
$this->module->amOnPage('/form/submit_adjacentforms');
$this->module->submitForm('#form-2', []);
+
$data = data::get('form');
$this->assertArrayHasKey('second-field', $data);
$this->assertArrayNotHasKey('first-field', $data);
@@ -1456,6 +1492,7 @@ public function testSubmitAdjacentFormsByButton()
$this->module->fillField('first-field', 'First');
$this->module->fillField('second-field', 'Second');
$this->module->click('#submit1');
+
$data = data::get('form');
$this->assertArrayHasKey('first-field', $data);
$this->assertArrayNotHasKey('second-field', $data);
@@ -1465,6 +1502,7 @@ public function testSubmitAdjacentFormsByButton()
$this->module->fillField('first-field', 'First');
$this->module->fillField('second-field', 'Second');
$this->module->click('#submit2');
+
$data = data::get('form');
$this->assertArrayNotHasKey('first-field', $data);
$this->assertArrayHasKey('second-field', $data);
@@ -1499,12 +1537,12 @@ public function testSelectAndCheckOptionSquareBracketNames()
$this->module->selectOption('//input[@name="input_radio_name"]', '1');
$this->module->selectOption('//input[@name="input_radio_name"]', '2');
- $this->module->checkOption('//input[@name="input_checkbox_name"]', '1');
- $this->module->checkOption('//input[@name="input_checkbox_name"]', '2');
+ $this->module->checkOption('//input[@name="input_checkbox_name"]');
+ $this->module->checkOption('//input[@name="input_checkbox_name"]');
- $this->module->checkOption('//input[@name="input[checkbox][name][]"]', '1');
- $this->module->checkOption('//input[@name="input[checkbox][name][]"]', '2');
- $this->module->checkOption('//input[@name="input[checkbox][name][]"]', '1');
+ $this->module->checkOption('//input[@name="input[checkbox][name][]"]');
+ $this->module->checkOption('//input[@name="input[checkbox][name][]"]');
+ $this->module->checkOption('//input[@name="input[checkbox][name][]"]');
$this->module->selectOption('//select[@name="select_name"]', '1');
@@ -1520,6 +1558,7 @@ public function testFillFieldWithAmpersand()
$this->module->amOnPage('/form/field');
$this->module->fillField('Name', 'this & that');
$this->module->click('Submit');
+
$form = data::get('form');
$this->assertEquals('this & that', $form['name']);
}
@@ -1576,7 +1615,7 @@ public function testClickMultiByteLink()
*/
public function testClickThrowsElementNotFoundExceptionWhenTextContainsNumber()
{
- $this->expectException('Codeception\Exception\ElementNotFound');
+ $this->expectException(ElementNotFound::class);
$this->expectExceptionMessage("'Link 2' is invalid CSS and XPath selector and Link or Button element with 'name=Link 2' was not found.");
$this->module->amOnPage('/info');
$this->module->click('Link 2');
@@ -1594,6 +1633,7 @@ public function testSelectOptionValueSelector()
$this->module->amOnPage('/form/select_selectors');
$this->module->selectOption('age', ['value' => '20']);
$this->module->click('Submit');
+
$data = data::get('form');
$this->assertEquals('20', $data['age']);
}
@@ -1698,7 +1738,7 @@ public function testAttachFileThrowsCorrectMessageWhenFileDoesNotExist()
{
$filename = 'does-not-exist.jpg';
$expectedMessage = 'File does not exist: ' . codecept_data_dir($filename);
- $this->expectException('InvalidArgumentException');
+ $this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage($expectedMessage);
$this->module->amOnPage('/form/file');
@@ -1708,8 +1748,9 @@ public function testAttachFileThrowsCorrectMessageWhenFileDoesNotExist()
public function testPasswordArgument()
{
$this->module->amOnPage('/form/password_argument');
- $this->module->fillField('password', new \Codeception\Step\Argument\PasswordArgument('thisissecret'));
+ $this->module->fillField('password', new PasswordArgument('thisissecret'));
$this->module->click('Submit');
+
$data = data::get('form');
$this->assertEquals('thisissecret', $data['password']);
}