Search

Phalcon4

Installation

If you use Codeception installed using composer, install this module with the following command:

composer require --dev codeception/module-phalcon4

Alternatively, you can enable Phalcon4 module in suite configuration file and run

codecept init upgrade4

This module was bundled with Codeception 2 and 3, but since version 4 it is necessary to install it separately.
Some modules are bundled with PHAR files.
Warning. Using PHAR file and composer in the same project can cause unexpected errors.

Description

This module provides integration with Phalcon framework (4.x). Please try it and leave your feedback.

Status

Config

The following configurations are required for this module:

  • bootstrap: string, default app/config/bootstrap.php - relative path to app.php config file
  • cleanup: boolean, default true - all database queries will be run in a transaction, which will be rolled back at the end of each test
  • savepoints: boolean, default true - use savepoints to emulate nested transactions

The application bootstrap file must return Application object but not call its handle() method.

API

  • di - Phalcon\Di\Injectable instance
  • client - BrowserKit client

Parts

By default all available methods are loaded, but you can specify parts to select only needed actions and avoid conflicts.

  • orm - include only haveRecord/grabRecord/seeRecord/dontSeeRecord actions.
  • services - allows to use grabServiceFromContainer and addServiceToContainer.

See WebDriver module for general information on how to load parts of a framework module.

Usage example:

Sample bootstrap (app/config/bootstrap.php):

<?php
$di = new \Phalcon\DI\FactoryDefault();
return new \Phalcon\Mvc\Application($di);
?>
actor: AcceptanceTester
modules:
    enabled:
        - Phalcon4:
            part: services
            bootstrap: 'app/config/bootstrap.php'
            cleanup: true
            savepoints: true
        - WebDriver:
            url: http://your-url.com
            browser: phantomjs

Actions

_findElements

hidden API method, expected to be used from Helper classes

Locates element using available Codeception locator types:

  • XPath
  • CSS
  • Strict Locator

Use it in Helpers or GroupObject or Extension classes:

<?php
$els = $this->getModule('Phalcon4')->_findElements('.items');
$els = $this->getModule('Phalcon4')->_findElements(['name' => 'username']);

$editLinks = $this->getModule('Phalcon4')->_findElements(['link' => 'Edit']);
// now you can iterate over $editLinks and check that all them have valid hrefs

WebDriver module returns Facebook\WebDriver\Remote\RemoteWebElement instances PhpBrowser and Framework modules return Symfony\Component\DomCrawler\Crawler instances

  • param $locator
  • return array of interactive elements

_getResponseContent

hidden API method, expected to be used from Helper classes

Returns content of the last response Use it in Helpers when you want to retrieve response of request performed by another module.

<?php
// in Helper class
public function seeResponseContains($text)
{
   $this->assertStringContainsString($text, $this->getModule('Phalcon4')->_getResponseContent(), "response contains");
}
  • return string @throws ModuleException

_loadPage

hidden API method, expected to be used from Helper classes

Opens a page with arbitrary request parameters. Useful for testing multi-step forms on a specific step.

<?php
// in Helper class
public function openCheckoutFormStep2($orderId) {
    $this->getModule('Phalcon4')->_loadPage('POST', '/checkout/step2', ['order' => $orderId]);
}
  • param string $method
  • param string $uri
  • param string $content

_request

hidden API method, expected to be used from Helper classes

Send custom request to a backend using method, uri, parameters, etc. Use it in Helpers to create special request actions, like accessing API Returns a string with response body.

<?php
// in Helper class
public function createUserByApi($name) {
    $userData = $this->getModule('Phalcon4')->_request('POST', '/api/v1/users', ['name' => $name]);
    $user = json_decode($userData);
    return $user->id;
}

Does not load the response into the module so you can’t interact with response page (click, fill forms). To load arbitrary page for interaction, use _loadPage method.

  • param string $method
  • param string $uri
  • param string $content
  • return string @throws ExternalUrlException @see _loadPage

_savePageSource

hidden API method, expected to be used from Helper classes

Saves page source of to a file

$this->getModule('Phalcon4')->_savePageSource(codecept_output_dir().'page.html');
  • param $filename

addServiceToContainer

Registers a service in the services container and resolve it. This record will be erased after the test. Recommended to use for unit testing.

<?php
$filter = $I->addServiceToContainer('filter', ['className' => '\Phalcon\Filter']);
$filter = $I->addServiceToContainer('answer', function () {
     return rand(0, 1) ? 'Yes' : 'No';
}, true);
  • param string $name
  • param mixed $definition
  • param boolean $shared
  • return mixed|null
  • [Part] services

amHttpAuthenticated

Authenticates user for HTTP_AUTH

  • param string $username
  • param string $password

amOnPage

Opens the page for the given relative URI.

<?php
// opens front page
$I->amOnPage('/');
// opens /register page
$I->amOnPage('/register');
  • param string $page

amOnRoute

Opens web page using route name and parameters.

<?php
$I->amOnRoute('posts.create');
  • param string $routeName
  • param array $params

attachFile

Attaches a file relative to the Codeception _data directory to the given file upload field.

<?php
// file is stored in 'tests/_data/prices.xls'