小编Pha*_*tom的帖子

Symfony2从phpunit测试中的twig模板访问全局变量

我有一个树枝模板{{ 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全局变量呢?为什么模拟认证在这种情况下不起作用?

php phpunit symfony twig

6
推荐指数
1
解决办法
950
查看次数

Symfony 4。ParamConverter 注释冲突通过自动装配注入服务

当我尝试在 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)

我知道这样的服务不存在,因为我已经排除Documentservices.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)

php autowired doctrine-orm doctrine-odm symfony4

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

标签 统计

php ×2

autowired ×1

doctrine-odm ×1

doctrine-orm ×1

phpunit ×1

symfony ×1

symfony4 ×1

twig ×1