我的phpunit中的实体管理器有问题.
这是我的测试:
public function testValidChangeEmail()
{
$client = self::createAuthClient('user','password');
$crawler = $client->request('GET', '/user/edit/30');
$crawler = $client->submit($crawler->selectButton('submit')->form(array(
'form[email]' => 'new@email.com',
)));
/*
* With this em, this work perfectly
* $em = $client->getContainer()->get('doctrine.orm.entity_manager');
*/
$user = self::$em->getRepository('MyBundle:User')->findUser('new@email.com');
die(var_dump($user->getEmail()));
}
Run Code Online (Sandbox Code Playgroud)
这是我的WebTestCase,它扩展了原始的WebTestCase:
class WebTestCase extends BaseWebTestCase
{
static protected $container;
static protected $em;
static protected function createClient(array $options = array(), array $server = array())
{
$client = parent::createClient($options, $server);
self::$em = $client->getContainer()->get('doctrine.orm.entity_manager');
self::$container = $client->getContainer();
return $client;
}
protected function createAuthClient($user, $pass)
{ …Run Code Online (Sandbox Code Playgroud) 我遇到两个日期时间相差的问题。这是显示 DateInterval 对象的命令行:
php -r "\$a = new Datetime('first day of 4 months ago midnight'); \$b = new Datetime('first day of 1 month ago midnight'); var_dump(\$a->diff(\$b));"
Run Code Online (Sandbox Code Playgroud)
这里是DateInterval输出:
class DateInterval#3 (15) {
public $y => int(0)
public $m => int(3)
public $d => int(3)
public $h => int(0)
public $i => int(0)
public $s => int(0)
public $weekday => int(0)
public $weekday_behavior => int(0)
public $first_last_day_of => int(0)
public $invert => int(0)
public $days => int(92)
public $special_type => …Run Code Online (Sandbox Code Playgroud)