Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
找不到Symfony 2和PhpUnit类_Php_Symfony_Phpunit_Classnotfound - Fatal编程技术网

找不到Symfony 2和PhpUnit类

找不到Symfony 2和PhpUnit类,php,symfony,phpunit,classnotfound,Php,Symfony,Phpunit,Classnotfound,我不知道如何为我的问题找到解决方案,我已经在互联网上搜索了很多(和stackoverflow),但对我来说没有什么是好的 问题 我有一个Symfony 2应用程序。我使用PHPUnit创建了一个测试,但当我执行该测试时,出现以下异常: 1) RepositoryBundle\Tests\DAO\UserDAOTest::testCreate 错误:找不到类“RepositoryBundle\Tests\DAO\User” 我不知道为什么 <?php namespace Repositor

我不知道如何为我的问题找到解决方案,我已经在互联网上搜索了很多(和stackoverflow),但对我来说没有什么是好的

问题 我有一个Symfony 2应用程序。我使用PHPUnit创建了一个测试,但当我执行该测试时,出现以下异常:

1) RepositoryBundle\Tests\DAO\UserDAOTest::testCreate 错误:找不到类“RepositoryBundle\Tests\DAO\User”

我不知道为什么

<?php

namespace RepositoryBundle\Tests\DAO;

use RepositoryBundle\Entity;
use RepositoryBundle\DAO;

class UserDAOTest extends \PHPUnit_Framework_TestCase
{
    public function testCreate()
    {
        $user1 = new User();
        $user1.setName("TestName");
        $user1.setEmail("TestEmail");
        $user1.setPassword("TestPassword");
        $user1.setMemberNumber(12345);
        $user1.setAdmin(true);
        $user1.setRole(1);

        $UserDAO = FactoryDAO::getInstance("UserDAO");
        $user1 = $UserDAO.save($user1);

        $this->assertTrue($user1.getId() > 0);
        $this->assertEquals("TestName", $user1.getName());
        $this->assertEquals("TestEmail", $user1.getEmail());
        $this->assertEquals("TestPassword", $user1.getPassword());
        $this->assertEquals(12345, $user1.getMemberNumber());
        $this->assertEquals(true, $user1.isAdmin());
        $this->assertEquals(1, $user1.getRole());
    }
}
在AppKernele.php中

    $bundles = array(
        // The Base Symfony Bundle
        new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
        new Symfony\Bundle\SecurityBundle\SecurityBundle(),
        new Symfony\Bundle\TwigBundle\TwigBundle(),
        new Symfony\Bundle\MonologBundle\MonologBundle(),
        new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
        new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
        new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),

        // Sonata Admin Bundle
        new Sonata\CoreBundle\SonataCoreBundle(),
        new Sonata\BlockBundle\SonataBlockBundle(),
        new Knp\Bundle\MenuBundle\KnpMenuBundle(),
        new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
        new Sonata\AdminBundle\SonataAdminBundle(),

        // Our Bundle
        new RepositoryBundle\RepositoryBundle(),
        new AdminBundle\AdminBundle(),
    );
因此,在所有这些情况下,boostrap.php.cache应该是正常的,为什么不是呢


如果你需要更多的信息,问我。我真的需要你的帮助。

问题出在这里
$user1=new User()
如果您的用户类位于
RepositoryBundle\Entity
,则有两种解决方案

  • 使用RepositoryBundle\Entity\User
    而不是
    使用RepositoryBundle\Entity
  • $user1=new Entity\User()
    而不是
    $user1=new User()
  • 选择其中一个解决方案,而不是两个都选。阅读php名称空间以进一步了解

    "autoload": {
        "psr-4": { "": "src/" },
        "classmap": [ "app/AppKernel.php", "app/AppCache.php" ]
    },
    
        $bundles = array(
            // The Base Symfony Bundle
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
    
            // Sonata Admin Bundle
            new Sonata\CoreBundle\SonataCoreBundle(),
            new Sonata\BlockBundle\SonataBlockBundle(),
            new Knp\Bundle\MenuBundle\KnpMenuBundle(),
            new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
            new Sonata\AdminBundle\SonataAdminBundle(),
    
            // Our Bundle
            new RepositoryBundle\RepositoryBundle(),
            new AdminBundle\AdminBundle(),
        );