Last active
April 19, 2017 10:23
-
-
Save faffyman/9810b64a9aed3a450e54258b5f9584ba to your computer and use it in GitHub Desktop.
PHP Unit testing with Codeception: Useful hints
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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