小编rga*_*lot的帖子

Symfony 2中的实体管理器和phpunit问题

我的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)

php phpunit symfony doctrine-orm symfony-2.1

5
推荐指数
1
解决办法
2767
查看次数

PHP 错误的 DateTime::diff() 返回错误的 DateInterval

我遇到两个日期时间相差的问题。这是显示 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)

php datetime dateinterval

4
推荐指数
1
解决办法
3853
查看次数