我有一个树枝模板{{ app.user }}.问题是,在phpunit测试(一个扩展的类WebTestCase)中,它被定义为NULL.使用令牌模拟身份验证(http://symfony.com/doc/current/cookbook/testing/simulating_authentication.html)或模拟HTTP身份验证(http://symfony.com/doc/current/cookbook/testing/http_authentication.html)没有帮助.那么如何从phpunit测试中设置一个twig全局变量呢?为什么模拟认证在这种情况下不起作用?
当我尝试在 Controller 操作中使用 @ParamConverter 注释时,出现错误
"Cannot resolve argument $company of \"App\\Controller\\ProfileController::top()\": Cannot autowire service \".service_locator.0CrkHeS\": it references class \"App\\Document\\Company\" but no such service exists."
Run Code Online (Sandbox Code Playgroud)
我知道这样的服务不存在,因为我已经排除Document了services.yaml. 我只需要从 Repostiroy 中找到一个 Company 文档对象。
这是我的控制器代码:
<?php
// src/Controller/ProfileController.php
namespace App\Controller;
use App\Document\Company;
use App\Service\DocumentManager\CompanyManager;
use FOS\RestBundle\Controller\FOSRestController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Swagger\Annotations as SWG;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/profile")
*/
class ProfileController extends FOSRestController
{
/**
* @Route("/top/{id}")
* @Method("GET")
* @SWG\Response(
* response=200,
* description="Returns top profiles", …Run Code Online (Sandbox Code Playgroud)