Skip to content

Instantly share code, notes, and snippets.

@faffyman
Last active April 19, 2017 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save faffyman/9810b64a9aed3a450e54258b5f9584ba to your computer and use it in GitHub Desktop.
Save faffyman/9810b64a9aed3a450e54258b5f9584ba to your computer and use it in GitHub Desktop.
PHP Unit testing with Codeception: Useful hints
<?php
namespace AppBundle;
use Codeception\Util\Debug;
use Doctrine\ORM\EntityManager;
class MySymfonyTest extends \Codeception\Test\Unit
{
protected $em;
protected $container;
protected function _before()
{
// create entity manager
$this->em = $this->getModule('Doctrine2')->em;
/** @var Symfony\Component\DependencyInjection\Container */
$this->container = $this->getModule('Symfony')->kernel->getContainer();
// Sample Usage
// $myServiceClass = $conatienr->get('MyService');
}
protected function _after()
{
}
public function testSomething()
{
// you can also grab services without grabbing the container first
$myServiceClass = $this->getModule('Symfony')->grabServiceFromContainer('app.myservice');
// test code here...
}
}// end MyTest Class
namespace: AppBundle
class_name: UnitTester
modules:
enabled:
- REST:
url: /v1
depends: Symfony
- Asserts
- Doctrine2:
depends: Symfony
- Symfony:
var_path: '../../var'
app_path: '../../app'
- AppBundle\Helper\Unit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment