2017 © Pedro Peláez
 

library zf2-phpunit-testcase

PHPUnit test case base classes for ZF2 applications.

image

heartsentwined/zf2-phpunit-testcase

PHPUnit test case base classes for ZF2 applications.

  • Wednesday, July 6, 2016
  • by heartsentwined
  • Repository
  • 2 Watchers
  • 6 Stars
  • 1,789 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

zf2-phpunit-testcase

PHPUnit test case base classes for ZF2 applications., (*1)

Installation

Composer:, (*2)

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

PHPUnit is not bundled with this package. You can install it through PEAR and use the CLI at phpunit:, (*3)

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

Usage

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

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:, (*5)

Zf

Bootstrap your Zf2 application with the bootstrap file foo/bootstrap.php:, (*6)

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

Bootstrap your Zf2 application with the bootstrap file foo/bootstrap.php, and with Doctrine ORM support. Your EntityManager is aliased with the ServiceManager at doctrine.entitymanager.orm_default., (*7)

(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()), (*8)

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'
  }
}

The Versions

06/07 2016

dev-master

9999999-dev https://github.com/yalesov/zf2-phpunit-testcase

PHPUnit test case base classes for ZF2 applications.

  Sources   Download

ISC

The Requires

 

by Yulij Andreevich Lesov

phpunit zf2 zendframework

06/07 2016

v2.1.3

2.1.3.0 https://github.com/yalesov/zf2-phpunit-testcase

PHPUnit test case base classes for ZF2 applications.

  Sources   Download

ISC

The Requires

 

by Yulij Andreevich Lesov

phpunit zf2 zendframework

06/07 2016

v2.1.2

2.1.2.0 https://github.com/yalesov/zf2-phpunit-testcase

PHPUnit test case base classes for ZF2 applications.

  Sources   Download

ISC

The Requires

 

by Yulij Andreevich Lesov

phpunit zf2 zendframework

06/07 2016

v2.1.1

2.1.1.0 https://github.com/yalesov/zf2-phpunit-testcase

PHPUnit test case base classes for ZF2 applications.

  Sources   Download

ISC

The Requires

 

by Yulij Andreevich Lesov

phpunit zf2 zendframework

05/07 2016

v2.1.0

2.1.0.0 https://github.com/yalesov/zf2-phpunit-testcase

PHPUnit test case base classes for ZF2 applications.

  Sources   Download

ISC

The Requires

 

by Yulij Andreevich Lesov

phpunit zf2 zendframework

05/07 2016

v2.0.0

2.0.0.0 https://github.com/yalesov/zf2-phpunit-testcase

PHPUnit test case base classes for ZF2 applications.

  Sources   Download

ISC

The Requires

 

by Yulij Andreevich Lesov

phpunit zf2 zendframework

28/09 2012

1.0.2

1.0.2.0 https://github.com/heartsentwined/zf2-phpunit-testcase

PHPUnit test case base classes for ZF2 applications.

  Sources   Download

GPL-3.0

The Requires

 

by Avatar heartsentwined

phpunit zf2 zendframework

20/09 2012

1.0.1

1.0.1.0 https://github.com/heartsentwined/zf2-phpunit-testcase

PHPUnit test case base classes for ZF2 applications.

  Sources   Download

GPL-3.0

The Requires

 

by Avatar heartsentwined

phpunit zf2 zendframework

19/09 2012

1.0.0

1.0.0.0 https://github.com/heartsentwined/zf2-phpunit-testcase

PHPUnit test case base classes for ZF2 applications.

  Sources   Download

GPL-3.0

The Requires

 

by Avatar heartsentwined

phpunit zf2 zendframework