PHP code example of yalesov / zf2-phpunit-testcase

1. Go to this page and download the library: Download yalesov/zf2-phpunit-testcase library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yalesov / zf2-phpunit-testcase example snippets


use Zend\Mvc\Application;
chdir(__DIR__); // chdir() to application root
 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);

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

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