PHPackages                             heartsentwined/zf2-phpunit-testcase - 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. heartsentwined/zf2-phpunit-testcase

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

heartsentwined/zf2-phpunit-testcase
===================================

PHPUnit test case base classes for ZF2 applications.

v2.1.3(9y ago)41.8kISCPHPPHP &gt;=5.3.3

Since Sep 19Pushed 9y ago2 watchersCompare

[ Source](https://github.com/heartsentwined/zf2-phpunit-testcase)[ Packagist](https://packagist.org/packages/heartsentwined/zf2-phpunit-testcase)[ Docs](https://github.com/yalesov/zf2-phpunit-testcase)[ RSS](/packages/heartsentwined-zf2-phpunit-testcase/feed)WikiDiscussions master Synced today

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

zf2-phpunit-testcase
====================

[](#zf2-phpunit-testcase)

[PHPUnit](http://phpunit.de/) test case base classes for ZF2 applications.

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

[](#installation)

[Composer](http://getcomposer.org/):

```
{
  "require": {
    "yalesov/zf2-phpunit-testcase": "2.*"
  }
}
```

[PHPUnit](http://phpunit.de/) is **not** bundled with this package. You can install it through PEAR and use the CLI at `phpunit`:

```
$ pear config-set auto_discover 1
$ pear install pear.phpunit.de/PHPUnit
```

Usage
=====

[](#usage)

First, you will need a bootstrap file which returns `Zend\Mvc\Application`. Here is an example:

```
use Zend\Mvc\Application;
chdir(__DIR__); // chdir() to application root
require 'vendor/autoload.php';
/*
 * why another set of config?
 * now that you're writing unit test
 * odds are that you would want to override some production settings here,
 * e.g. load only certain module; use a test database connection, etc
 */
$config = array(
  'modules'   => array(
    'Foo',
    'Bar',
  ),
  'module_listener_options' => array(
    'config_glob_paths' => array(
      __DIR__ . '/test/config/{,*.}php'
    ),
    'module_paths' => array(
      'Foo' => __DIR__,
      'vendor',
    ),
  ),
));
return Application::init($config);
```

Now, on to the test case base classes:

Zf
--

[](#zf)

Bootstrap your Zf2 application with the bootstrap file `foo/bootstrap.php`:

```
use Yalesov\Phpunit\Testcase\Zf as ZfTestcase;

class FooTest extends ZfTestcase
{
  public function setUp()
  {
    $this->setBootstrap('foo/bootstrap.php'); // watch out for relative dirs! - use __DIR__ if needed
    parent::setUp();
  }

  public function tearDown()
  {
    // your tearDown() operations
    parent::tearDown();
  }

  public function testFoo()
  {
    // $this->application instance of Zend\Mvc\Application
    // $this->sm instance of Zend\ServiceManager\ServiceManager
  }
}
```

Doctrine
--------

[](#doctrine)

Bootstrap your Zf2 application with the bootstrap file `foo/bootstrap.php`, and with [Doctrine ORM](http://www.doctrine-project.org/projects/orm.html) support. Your `EntityManager` is aliased with the ServiceManager at `doctrine.entitymanager.orm_default`.

(Optional) You have declared the directory `foo/tmp` as a temporary directory somewhere in your config files - possibly for storing Proxies, and you want this directory to be created before each test; and deleted after each test. (i.e. during setUp() and teardown())

```
use Yalesov\Phpunit\Testcase\Doctrine as DoctrineTestcase;

class FooTest extends DoctrineTestcase
{
  public function setUp()
  {
    // fluent interface available
    $this
      ->setBootstrap('foo/bootstrap.php')
      ->setEmAlias('doctrine.entitymanager.orm_default')
      ->setTmpDir('foo/tmp'); // optional: see use case above
    parent::setUp();
  }

  public function tearDown()
  {
    // your tearDown() operations
    parent::tearDown();
  }

  public function testFoo()
  {
    // $this->application instance of Zend\Mvc\Application
    // $this->sm instance of Zend\ServiceManager\ServiceManager
    // $this->em instance of Doctrine\ORM\EntityManager
    // $this->tmpDir = 'foo/tmp'
  }
}
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity63

Established project with proven stability

 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 ~198 days

Recently: every ~0 days

Total

8

Last Release

3596d ago

Major Versions

1.0.2 → v2.0.02016-07-05

### Community

Maintainers

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

---

Top Contributors

[![yalesov](https://avatars.githubusercontent.com/u/20264293?v=4)](https://github.com/yalesov "yalesov (5 commits)")

---

Tags

phpunitZendFrameworkzf2

### Embed Badge

![Health badge](/badges/heartsentwined-zf2-phpunit-testcase/health.svg)

```
[![Health](https://phpackages.com/badges/heartsentwined-zf2-phpunit-testcase/health.svg)](https://phpackages.com/packages/heartsentwined-zf2-phpunit-testcase)
```

###  Alternatives

[phpunit/phpunit

The PHP Unit Testing framework.

20.0k910.7M134.7k](/packages/phpunit-phpunit)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[johnkary/phpunit-speedtrap

Find and report on slow tests in your PHPUnit test suite

78137.2M122](/packages/johnkary-phpunit-speedtrap)[spatie/phpunit-snapshot-assertions

Snapshot testing with PHPUnit

69417.9M511](/packages/spatie-phpunit-snapshot-assertions)[dg/bypass-finals

Removes final keyword from source code on-the-fly and allows mocking of final methods and classes

56426.3M456](/packages/dg-bypass-finals)[phpspec/prophecy-phpunit

Integrating the Prophecy mocking library in PHPUnit test cases

19254.9M1.4k](/packages/phpspec-prophecy-phpunit)

PHPackages © 2026

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