PHPackages                             cosma/phest - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. cosma/phest

ActiveLibrary[Testing &amp; Quality](/categories/testing)

cosma/phest
===========

Phest = Phalcon + Test

0.0.3(9y ago)321MITPHPPHP ^5.6 || ^7.0

Since Sep 15Pushed 9y ago1 watchersCompare

[ Source](https://github.com/cosma/phest)[ Packagist](https://packagist.org/packages/cosma/phest)[ Docs](https://github.com/cosma/phest)[ RSS](/packages/cosma-phest/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (3)Versions (4)Used By (0)

Phest
=====

[](#phest)

[![Circle CI](https://camo.githubusercontent.com/6d9a6a8f61091e9b57698b57d53460df230b5516c5b79883d288b5f2507bfe33/68747470733a2f2f636972636c6563692e636f6d2f67682f636f736d612f70686573742e7376673f7374796c653d737667)](https://circleci.com/gh/cosma/phest)

Phalcon + Test = Phest. A test library for [Phalcon Framework](http://phalconphp.com).

Table of Contents
=================

[](#table-of-contents)

- [Installation](#installation)
- [Dependencies](#dependencies)
- [Test Cases](#test-cases)
- [Retry Tests](#retry-tests)
- [Run Tests](#run-tests)
- [License](#license)

Installation
============

[](#installation)

### 1. Add Phest to composer.json

[](#1-add-phest-to-composerjson)

```
    $   php composer.phar require cosma/phest '0.0.*'
```

Follow the 'dev-master' branch for latest dev version. I recommend to use more stable version tags if available.

### 2. Add a bootstrap.php file to Phalcon project tests directory

[](#2-add-a-bootstrapphp-file-to-phalcon-project-tests-directory)

```
# /path/to/phalcon/project/tests/bootstrap.php

 /**
 * Define TEST_PATH to point to path/to/phalcon/project/tests/
 */
define('TEST_PATH', __DIR__ );

/**
 * Require Phest environment.php file
 */
require_once '/path/to/vendor/cosma/phest/src/environment.php';

/**
 * Get your application from your phalcon project
 */
/** @var \Phalcon\Mvc\Micro|\Phalcon\Mvc\Application $app */
$app = require_once __DIR__ . '/../src/init.php';

 /**
 * Require Phest library bootstrap.php file
 */
require_once '/path/to/vendor/cosma/phest/src/bootstrap.php';
```

An example for [bootstrap.php](https://github.com/cosma/phest/blob/master/examples/bootstrap.php)

### 3. Add to phpunit configuration XML the bootstrap file

[](#3-add-to-phpunit-configuration-xml-the-bootstrap-file)

```

    ........

```

An example for [phpunit.xml](https://github.com/cosma/phest/blob/master/examples/phpunit.xml)

### Optionally, you can add a config.php that is merged with you Phalcon project configs

[](#optionally-you-can-add-a-configphp-that-is-merged-with-you-phalcon-project-configs)

```
# /path/to/phalcon/project/tests/config.php

return new \Phalcon\Config([
    'someConfigVariable' => 'some value',
]);
```

An example for [config.php](https://github.com/cosma/phest/blob/master/examples/config.php)

Dependencies
============

[](#dependencies)

This test library is intended for projects using Phalcon Framework version version 2.9. Therefore, PHP extension 2.0.13 must be installed. [Phalcon Extension](https://docs.phalconphp.com/uk/latest/reference/install.html)

Test Cases
==========

[](#test-cases)

Supports the following Test Cases:

- [Unit](#unit-test-case)
- [Web Test Case](#web-test-case)

Unit Test Case
--------------

[](#unit-test-case)

This case is used for unit testing is an extension of PHPUnit\_Framework\_TestCase:

```
use Cosma\Phest\TestCase\UnitTestCase;

class SomeVerySimpleUnitTest extends UnitTestCase
{
    public function testSomething()
    {
        $additionClass = new AdditionCLass();

        $this->assertEquals(3, $additionClass->calculate(1, 2));
    }
}
```

Web Test Case
-------------

[](#web-test-case)

This case is used for functional and controller tests and has the following methods:

- **mockService** ($serviceName, $mock)
- **sendRequest** ($url = '', $requestMethod = 'GET', $parameters = \[\], $headers = \[\])

```
use Cosma\Phest\TestCase\WebTestCase;

class SomeWebFunctionalTest extends WebTestCase
{
    public function setUp()
    {
        /**
        * Required call
        */
        parent::setUp();

        $db = $this->getMockBuilder('Phalcon\Db\Adapter\Pdo\Mysql')
            ->disableOriginalConstructor()
            ->setMethods(['query'])
            ->getMock();
        $this->mockService('db', $db);

    }

    public function testSomething()
    {
        /** @var \Phalcon\Http\Response $response */
        $response = $this->sendRequest(
            '/test_endpoint', 'POST', ['test_var' => 'value'], ['Header1' => 223456789, 'Header2' => 'value2']);

        $this->assertInstanceOf('Phalcon\Http\Response', $response);

        $this->assertEquals('200 OK', $response->getStatusCode());
        $this->assertEquals('value', $response->getContent());

    }

    public function testGetHealthCheck()
    {
        /** @var \Phalcon\Http\Response $response */
        $response = $this->sendRequest(
            '/healthCheck', 'GET', [], []);

        $this->assertInstanceOf('Phalcon\Http\Response', $response);

        $this->assertEquals('200 OK', $response->getStatusCode());
    }
}
```

Retry Tests
===========

[](#retry-tests)

Use the @retry annotation for a Class or Method to retry tests in case of failure. Method annotations are overwriting Class annotation.

```
use Cosma\Phest\TestCase\UnitTestCase;

/**
* Will retry 10 times all the Class tests that are failing
*
* @retry 10
*/
class SomeVerySimpleUnitTest extends UnitTestCase
{
    /**
    * Will retry 10 times this test if is failing because of the class annotation from above
    */
    public function testFirst()
    {
        // ...
    }

    /**
    * Will retry 4 times this test if is failing because of the method annotation from below
    *
    * @retry 4
    */
    public function testSecond()
    {
        // ...
    }
}
```

Mockery
-------

[](#mockery)

[Mockery](https://github.com/padraic/mockery) is a simple yet flexible PHP mock object framework for use in unit testing

```
use Cosma\Phest\TestCase\UnitTestCase;

class SomeUnitTest extends UnitTestCase
{
    public function testGetsAverageTemperatureFromThreeServiceReadings()
    {
        $service = \Mockery::mock('service');
        $service->shouldReceive('readTemp')->times(3)->andReturn(10, 12, 14);

        $temperature = new Temperature($service);

        $this->assertEquals(12, $temperature->average());
    }
}
```

Run Tests
=========

[](#run-tests)

vendor/bin/phpunit -c phpunit.xml --coverage-text --coverage-html=tests/coverage tests

License
=======

[](#license)

The bundle is licensed under MIT.

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

3575d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a1695d8d888c44c734f8a2d8151eadc456fa1605179acab2ba14d090d4b27e9a?d=identicon)[cosma](/maintainers/cosma)

---

Top Contributors

[![cosma](https://avatars.githubusercontent.com/u/1668991?v=4)](https://github.com/cosma "cosma (1 commits)")

---

Tags

phpunitunit testphalconfunctional test

### Embed Badge

![Health badge](/badges/cosma-phest/health.svg)

```
[![Health](https://phpackages.com/badges/cosma-phest/health.svg)](https://phpackages.com/packages/cosma-phest)
```

###  Alternatives

[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k41.3M39.1k](/packages/orchestra-testbench)[brianium/paratest

Parallel testing for PHP

2.5k129.9M920](/packages/brianium-paratest)[spatie/phpunit-snapshot-assertions

Snapshot testing with PHPUnit

69619.1M607](/packages/spatie-phpunit-snapshot-assertions)[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1499.3M94](/packages/ergebnis-phpunit-slow-test-detector)[yidas/codeigniter-phpunit

CodeIgniter 3 PHPUnit Test extension library

1697.2k2](/packages/yidas-codeigniter-phpunit)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
